feathers-utils 7.0.0 → 7.0.1
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/README.md +3 -4
- package/dist/index.cjs +28 -42
- package/dist/index.d.cts +27 -28
- package/dist/index.d.mts +27 -28
- package/dist/index.d.ts +27 -28
- package/dist/index.mjs +28 -42
- package/package.json +19 -22
- package/src/filters/array.ts +11 -13
- package/src/filters/index.ts +2 -2
- package/src/filters/object.ts +11 -11
- package/src/hooks/checkMulti.ts +98 -82
- package/src/hooks/createRelated.ts +22 -23
- package/src/hooks/forEach.ts +32 -32
- package/src/hooks/from-client-for-server/common.ts +1 -1
- package/src/hooks/from-client-for-server/index.ts +2 -2
- package/src/hooks/from-client-for-server/paramsForServer.ts +32 -32
- package/src/hooks/from-client-for-server/paramsFromClient.ts +25 -25
- package/src/hooks/index.ts +9 -9
- package/src/hooks/onDelete.ts +32 -32
- package/src/hooks/parseFields.ts +13 -13
- package/src/hooks/removeRelated.ts +20 -20
- package/src/hooks/runPerItem.ts +17 -18
- package/src/hooks/setData.ts +295 -264
- package/src/index.ts +6 -6
- package/src/mixins/debounce-mixin/DebouncedStore.ts +29 -29
- package/src/mixins/debounce-mixin/debounceMixin.ts +17 -17
- package/src/mixins/debounce-mixin/index.ts +3 -3
- package/src/mixins/debounce-mixin/types.ts +9 -9
- package/src/mixins/debounce-mixin/utils.ts +3 -3
- package/src/mixins/index.ts +1 -1
- package/src/types.ts +3 -5
- package/src/typesInternal.ts +14 -14
- package/src/utility-types/index.ts +48 -48
- package/src/utils/_utils.internal.ts +5 -5
- package/src/utils/defineHooks.ts +8 -8
- package/src/utils/deflattenQuery.ts +31 -31
- package/src/utils/filterQuery.ts +58 -58
- package/src/utils/flattenQuery.ts +54 -54
- package/src/utils/getItemsIsArray.ts +148 -149
- package/src/utils/getPaginate.ts +31 -31
- package/src/utils/index.ts +17 -17
- package/src/utils/isMulti.ts +48 -40
- package/src/utils/isPaginated.ts +30 -30
- package/src/utils/markHookForSkip.ts +177 -178
- package/src/utils/mergeQuery/index.ts +3 -3
- package/src/utils/mergeQuery/mergeArrays.ts +67 -67
- package/src/utils/mergeQuery/mergeQuery.ts +211 -211
- package/src/utils/mergeQuery/types.ts +12 -12
- package/src/utils/mergeQuery/utils.ts +224 -224
- package/src/utils/optimizeBatchPatch.ts +42 -42
- package/src/utils/pushSet.ts +57 -57
- package/src/utils/setQueryKeySafely.ts +68 -68
- package/src/utils/setResultEmpty.ts +125 -123
- package/src/utils/shouldSkip.ts +72 -72
- package/src/utils/toJSON.ts +4 -4
- package/src/utils/validateQueryProperty.ts +10 -10
- package/src/hooks/makeSequelizeQuery.ts_ +0 -90
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# feathers-utils
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/feathers-utils)
|
|
4
|
-
[](https://github.com/fratzinger/feathers-utils/actions/workflows/node.js.yaml?query=branch%3Amain)
|
|
5
5
|
[](https://codeclimate.com/github/fratzinger/feathers-utils)
|
|
6
6
|
[](https://codeclimate.com/github/fratzinger/feathers-utils)
|
|
7
7
|
[](https://www.npmjs.com/package/feathers-utils)
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
|
|
10
10
|
> NOTE: This is the version for Feathers v5. For Feathers v4 use [feathers-utils v1](https://github.com/fratzinger/feathers-utils/tree/crow)
|
|
11
11
|
|
|
12
|
-
|
|
13
12
|
## Installation
|
|
14
13
|
|
|
15
14
|
```shell
|
|
@@ -48,7 +47,7 @@ npm i feathers-utils
|
|
|
48
47
|
- `markHookForSkip`: add hookName to `context.params.skipHooks` - also see `shouldSkip`
|
|
49
48
|
- `mergeQuery`: deeply merges queries
|
|
50
49
|
- `mergeArrays`: merges arrays with intersection options
|
|
51
|
-
- `pushSet`: if existing array:
|
|
50
|
+
- `pushSet`: if existing array: _push_, else _set_
|
|
52
51
|
- `setQueryKeySafely`
|
|
53
52
|
- `setResultEmpty`
|
|
54
|
-
- `shouldSkip`: checks `context.params.skipHooks` for `'all' | '${hookName}' | '${type}:${hookName}'` - also see `markHookForSkip`
|
|
53
|
+
- `shouldSkip`: checks `context.params.skipHooks` for `'all' | '${hookName}' | '${type}:${hookName}'` - also see `markHookForSkip`
|
package/dist/index.cjs
CHANGED
|
@@ -24,7 +24,7 @@ function defineHooks(hooks) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
function filterQuery(providedQuery) {
|
|
27
|
-
providedQuery
|
|
27
|
+
providedQuery ??= {};
|
|
28
28
|
const { $select, $limit, $skip, $sort, ...query } = providedQuery;
|
|
29
29
|
const result = { query };
|
|
30
30
|
if ("$select" in providedQuery) {
|
|
@@ -392,12 +392,12 @@ function handleCircular(target, source, prependKey, options) {
|
|
|
392
392
|
}
|
|
393
393
|
}
|
|
394
394
|
function makeDefaultOptions$1(options) {
|
|
395
|
-
options
|
|
396
|
-
options.defaultHandle
|
|
397
|
-
options.useLogicalConjunction
|
|
398
|
-
options.actionOnEmptyIntersect
|
|
395
|
+
options ??= {};
|
|
396
|
+
options.defaultHandle ??= "combine";
|
|
397
|
+
options.useLogicalConjunction ??= false;
|
|
398
|
+
options.actionOnEmptyIntersect ??= () => {
|
|
399
399
|
throw new errors.Forbidden("You're not allowed to make this request");
|
|
400
|
-
}
|
|
400
|
+
};
|
|
401
401
|
options.handle = options.handle || {};
|
|
402
402
|
if (options.defaultHandle === "intersect") {
|
|
403
403
|
options.handle.$select = options.handle.$select || "intersectOrFull";
|
|
@@ -517,7 +517,6 @@ function mergeQuery(target, source, _options) {
|
|
|
517
517
|
}
|
|
518
518
|
|
|
519
519
|
const setQueryKeySafely = (params, key, value, operator = "$eq", options) => {
|
|
520
|
-
var _a;
|
|
521
520
|
const { mutate = false } = options || {};
|
|
522
521
|
if (!mutate) {
|
|
523
522
|
params = structuredClone(params);
|
|
@@ -538,7 +537,7 @@ const setQueryKeySafely = (params, key, value, operator = "$eq", options) => {
|
|
|
538
537
|
if (isPlainObject(params.query[key]) && !(operator in params.query[key])) {
|
|
539
538
|
params.query[key][operator] = value;
|
|
540
539
|
} else {
|
|
541
|
-
|
|
540
|
+
params.query.$and ??= [];
|
|
542
541
|
params.query.$and.push(
|
|
543
542
|
operator === "$eq" ? { [key]: value } : {
|
|
544
543
|
[key]: {
|
|
@@ -826,7 +825,7 @@ function onDelete(options) {
|
|
|
826
825
|
const data = { [keyThere]: null };
|
|
827
826
|
promise = context.app.service(service).patch(null, data, params);
|
|
828
827
|
}
|
|
829
|
-
if (blocking) {
|
|
828
|
+
if (blocking && promise) {
|
|
830
829
|
promises.push(promise);
|
|
831
830
|
}
|
|
832
831
|
}
|
|
@@ -966,19 +965,18 @@ function defineParamsForServer(keyToHide) {
|
|
|
966
965
|
return;
|
|
967
966
|
}
|
|
968
967
|
if (whitelist.includes(key)) {
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
query
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
if (!clonedParams.query[keyToHide]) {
|
|
978
|
-
clonedParams.query[keyToHide] = {};
|
|
968
|
+
const currentParams = clonedParams ?? {
|
|
969
|
+
...context.params,
|
|
970
|
+
query: {
|
|
971
|
+
...context.params.query
|
|
972
|
+
}
|
|
973
|
+
};
|
|
974
|
+
if (!currentParams.query[keyToHide]) {
|
|
975
|
+
currentParams.query[keyToHide] = {};
|
|
979
976
|
}
|
|
980
|
-
|
|
981
|
-
delete
|
|
977
|
+
currentParams.query[keyToHide][key] = currentParams[key];
|
|
978
|
+
delete currentParams[key];
|
|
979
|
+
clonedParams = currentParams;
|
|
982
980
|
}
|
|
983
981
|
});
|
|
984
982
|
if (clonedParams) {
|
|
@@ -1035,20 +1033,14 @@ const makeDefaultOptions = () => {
|
|
|
1035
1033
|
};
|
|
1036
1034
|
};
|
|
1037
1035
|
|
|
1038
|
-
var __defProp = Object.defineProperty;
|
|
1039
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1040
|
-
var __publicField = (obj, key, value) => {
|
|
1041
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1042
|
-
return value;
|
|
1043
|
-
};
|
|
1044
1036
|
class DebouncedStore {
|
|
1037
|
+
_app;
|
|
1038
|
+
_options;
|
|
1039
|
+
_isRunningById;
|
|
1040
|
+
_queueById;
|
|
1041
|
+
//_waitingById: Record<string, WaitingObject>;
|
|
1042
|
+
add;
|
|
1045
1043
|
constructor(app, options) {
|
|
1046
|
-
__publicField(this, "_app");
|
|
1047
|
-
__publicField(this, "_options");
|
|
1048
|
-
__publicField(this, "_isRunningById");
|
|
1049
|
-
__publicField(this, "_queueById");
|
|
1050
|
-
//_waitingById: Record<string, WaitingObject>;
|
|
1051
|
-
__publicField(this, "add");
|
|
1052
1044
|
this._app = app;
|
|
1053
1045
|
this._options = Object.assign(makeDefaultOptions(), options);
|
|
1054
1046
|
this._queueById = {};
|
|
@@ -1091,13 +1083,9 @@ class DebouncedStore {
|
|
|
1091
1083
|
function debounceMixin(options) {
|
|
1092
1084
|
return (app) => {
|
|
1093
1085
|
options = options || {};
|
|
1094
|
-
const defaultOptions = Object.assign(
|
|
1095
|
-
makeDefaultOptions(),
|
|
1096
|
-
options?.default
|
|
1097
|
-
);
|
|
1086
|
+
const defaultOptions = Object.assign(makeDefaultOptions(), options?.default);
|
|
1098
1087
|
app.mixins.push((service, path) => {
|
|
1099
|
-
if (options?.blacklist && options.blacklist.includes(path))
|
|
1100
|
-
return;
|
|
1088
|
+
if (options?.blacklist && options.blacklist.includes(path)) return;
|
|
1101
1089
|
if (service.debouncedStore) {
|
|
1102
1090
|
console.warn(
|
|
1103
1091
|
`[feathers-utils] service: '${path}' already has a property 'debouncedStore'. Mixin will skip creating a new debouncedStore`
|
|
@@ -1115,9 +1103,7 @@ function debounceMixin(options) {
|
|
|
1115
1103
|
|
|
1116
1104
|
const filterQueryArray = (key) => (arr, { operators }) => {
|
|
1117
1105
|
if (arr && !Array.isArray(arr)) {
|
|
1118
|
-
throw new Error(
|
|
1119
|
-
`Invalid query parameter '${key}'. It has to be an array`
|
|
1120
|
-
);
|
|
1106
|
+
throw new Error(`Invalid query parameter '${key}'. It has to be an array`);
|
|
1121
1107
|
}
|
|
1122
1108
|
if (Array.isArray(arr)) {
|
|
1123
1109
|
return arr.map((current) => validateQueryProperty(current, operators));
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as _feathersjs_feathers from '@feathersjs/feathers';
|
|
2
2
|
import { HookContext, Application, Id, HookOptions, Query, Params } from '@feathersjs/feathers';
|
|
3
|
-
import { HookContext as HookContext$1, Application as Application$1 } from '@feathersjs/feathers/lib';
|
|
4
3
|
import { PropertyPath, DebouncedFunc } from 'lodash';
|
|
5
4
|
import { PaginationOptions, FilterQueryOptions } from '@feathersjs/adapter-commons';
|
|
6
5
|
import { HookType } from 'feathers-hooks-common';
|
|
@@ -13,7 +12,7 @@ declare function checkMulti<H extends HookContext = HookContext>(): (context: H)
|
|
|
13
12
|
type MaybeArray<T> = T | T[];
|
|
14
13
|
type Promisable<T> = T | Promise<T>;
|
|
15
14
|
type Path = Array<string | number>;
|
|
16
|
-
type ReturnAsyncHook<H extends HookContext
|
|
15
|
+
type ReturnAsyncHook<H extends HookContext = HookContext> = (context: H) => Promise<H>;
|
|
17
16
|
type KeyOf<T> = Extract<keyof T, string>;
|
|
18
17
|
|
|
19
18
|
interface CreateRelatedOptions<S = Record<string, any>> {
|
|
@@ -27,7 +26,7 @@ interface CreateRelatedOptions<S = Record<string, any>> {
|
|
|
27
26
|
*/
|
|
28
27
|
declare function createRelated<S = Record<string, any>, H extends HookContext = HookContext>(options: MaybeArray<CreateRelatedOptions<S>>): (context: H) => Promise<H>;
|
|
29
28
|
|
|
30
|
-
type GetItemsIsArrayFrom =
|
|
29
|
+
type GetItemsIsArrayFrom = 'data' | 'result' | 'automatic';
|
|
31
30
|
type GetItemsIsArrayOptions = {
|
|
32
31
|
from?: GetItemsIsArrayFrom;
|
|
33
32
|
};
|
|
@@ -35,11 +34,11 @@ interface GetItemsIsArrayResult<T = any> {
|
|
|
35
34
|
items: T[];
|
|
36
35
|
isArray: boolean;
|
|
37
36
|
}
|
|
38
|
-
declare const getItemsIsArray: <T = any, H extends HookContext = HookContext
|
|
37
|
+
declare const getItemsIsArray: <T = any, H extends HookContext = HookContext>(context: H, options?: GetItemsIsArrayOptions) => GetItemsIsArrayResult<T>;
|
|
39
38
|
|
|
40
39
|
type HookForEachOptions<T = any, H = HookContext, R = any> = {
|
|
41
|
-
wait?:
|
|
42
|
-
items?: GetItemsIsArrayOptions[
|
|
40
|
+
wait?: 'sequential' | 'parallel' | false;
|
|
41
|
+
items?: GetItemsIsArrayOptions['from'];
|
|
43
42
|
forAll?: (items: T[], context: H) => Promisable<R>;
|
|
44
43
|
skip?: (context: H) => Promisable<boolean>;
|
|
45
44
|
};
|
|
@@ -49,9 +48,9 @@ type ActionPerItem<T, H, R> = (item: T, options: {
|
|
|
49
48
|
} & (undefined extends R ? {} : {
|
|
50
49
|
fromAll: R;
|
|
51
50
|
})) => Promisable<any>;
|
|
52
|
-
declare const forEach: <H extends HookContext = HookContext
|
|
51
|
+
declare const forEach: <H extends HookContext = HookContext, T = any, R = any>(actionPerItem: ActionPerItem<T, H, R>, options?: HookForEachOptions<T, H, R>) => ReturnAsyncHook<H>;
|
|
53
52
|
|
|
54
|
-
type OnDeleteAction =
|
|
53
|
+
type OnDeleteAction = 'cascade' | 'set null';
|
|
55
54
|
interface OnDeleteOptions<Path extends string = string> {
|
|
56
55
|
service: Path;
|
|
57
56
|
keyThere: string;
|
|
@@ -92,7 +91,7 @@ interface HookRunPerItemOptions {
|
|
|
92
91
|
* hook to run a hook for each item in the context
|
|
93
92
|
* uses `context.result` if it is existent. otherwise uses context.data
|
|
94
93
|
*/
|
|
95
|
-
declare const runPerItem: <H extends HookContext = HookContext
|
|
94
|
+
declare const runPerItem: <H extends HookContext = HookContext, T = any>(actionPerItem: (item: T, context: H) => Promisable<any>, _options?: HookRunPerItemOptions) => (context: H) => Promise<H>;
|
|
96
95
|
|
|
97
96
|
type Predicate<T = any> = (item: T) => boolean;
|
|
98
97
|
type PredicateWithContext<T = any> = (item: T, context: HookContext) => boolean;
|
|
@@ -139,14 +138,14 @@ declare class DebouncedStore {
|
|
|
139
138
|
private _options;
|
|
140
139
|
private _isRunningById;
|
|
141
140
|
_queueById: Record<string, DebouncedFunc<(id: Id, action: DebouncedFunctionApp) => void | Promise<void>>>;
|
|
142
|
-
add:
|
|
141
|
+
add: (id: Id, action: (app?: Application) => void | Promise<void>) => void | Promise<void> | undefined;
|
|
143
142
|
constructor(app: Application, options?: Partial<DebouncedStoreOptions>);
|
|
144
143
|
private unbounced;
|
|
145
144
|
private debounceById;
|
|
146
145
|
cancel(id: Id): void;
|
|
147
146
|
}
|
|
148
147
|
|
|
149
|
-
declare function debounceMixin(options?: Partial<InitDebounceMixinOptions>): (app: Application
|
|
148
|
+
declare function debounceMixin(options?: Partial<InitDebounceMixinOptions>): (app: Application) => void;
|
|
150
149
|
|
|
151
150
|
declare function defineHooks<A extends Application = Application, S = {
|
|
152
151
|
find: any;
|
|
@@ -158,11 +157,11 @@ declare function defineHooks<A extends Application = Application, S = {
|
|
|
158
157
|
}, Options = HookOptions<A, S>>(hooks: Options): Options;
|
|
159
158
|
|
|
160
159
|
type FilterQueryResult<Q extends Query = Query> = {
|
|
161
|
-
$select: Q[
|
|
162
|
-
$limit: Q[
|
|
163
|
-
$skip: Q[
|
|
164
|
-
$sort: Q[
|
|
165
|
-
query: Omit<Q,
|
|
160
|
+
$select: Q['$select'] extends any ? Q['$select'] : never;
|
|
161
|
+
$limit: Q['$limit'] extends any ? Q['$limit'] : never;
|
|
162
|
+
$skip: Q['$skip'] extends any ? Q['$skip'] : never;
|
|
163
|
+
$sort: Q['$sort'] extends any ? Q['$sort'] : never;
|
|
164
|
+
query: Omit<Q, '$select' | '$limit' | '$skip' | '$sort'>;
|
|
166
165
|
};
|
|
167
166
|
/**
|
|
168
167
|
* Extracts $select, $limit, $skip, $sort from a query and returns the rest as a query object.
|
|
@@ -179,7 +178,7 @@ declare function reassembleQuery(query: FilterQueryResult): Query;
|
|
|
179
178
|
* 2. it uses `service.options.paginate` if it exists
|
|
180
179
|
* 3. it uses `context.params.adapter` if it exists
|
|
181
180
|
*/
|
|
182
|
-
declare const getPaginate: <H extends HookContext = HookContext
|
|
181
|
+
declare const getPaginate: <H extends HookContext = HookContext>(context: H) => PaginationOptions | undefined;
|
|
183
182
|
|
|
184
183
|
/**
|
|
185
184
|
* util to check if a hook is a multi hook:
|
|
@@ -190,19 +189,19 @@ declare const getPaginate: <H extends HookContext = HookContext<_feathersjs_feat
|
|
|
190
189
|
* - patch: `context.id == null`
|
|
191
190
|
* - remove: `context.id == null`
|
|
192
191
|
*/
|
|
193
|
-
declare const isMulti: <H extends HookContext = HookContext
|
|
192
|
+
declare const isMulti: <H extends HookContext = HookContext>(context: H) => boolean;
|
|
194
193
|
|
|
195
194
|
/**
|
|
196
195
|
* util to check if a hook is a paginated hook using `getPaginate`
|
|
197
196
|
*/
|
|
198
|
-
declare const isPaginated: <H extends HookContext = HookContext
|
|
197
|
+
declare const isPaginated: <H extends HookContext = HookContext>(context: H) => boolean;
|
|
199
198
|
|
|
200
199
|
/**
|
|
201
200
|
* util to mark a hook for skip, has to be used with `shouldSkip`
|
|
202
201
|
*/
|
|
203
|
-
declare function markHookForSkip<H extends HookContext = HookContext>(hookName: string, type:
|
|
202
|
+
declare function markHookForSkip<H extends HookContext = HookContext>(hookName: string, type: 'all' | MaybeArray<HookType>, context?: H): H | undefined;
|
|
204
203
|
|
|
205
|
-
type Handle =
|
|
204
|
+
type Handle = 'target' | 'source' | 'combine' | 'intersect' | 'intersectOrFull';
|
|
206
205
|
type ActionOnEmptyIntersect = (target: unknown, source: unknown, prependKey: Path) => void;
|
|
207
206
|
interface MergeQueryOptions {
|
|
208
207
|
defaultHandle: Handle;
|
|
@@ -240,7 +239,7 @@ declare const setQueryKeySafely: (params: Params, key: string, value: any, opera
|
|
|
240
239
|
/**
|
|
241
240
|
* util to set `context.result` to an empty array or object, depending on the hook type
|
|
242
241
|
*/
|
|
243
|
-
declare const setResultEmpty: <H extends HookContext = HookContext
|
|
242
|
+
declare const setResultEmpty: <H extends HookContext = HookContext>(context: H) => H;
|
|
244
243
|
|
|
245
244
|
type ShouldSkipOptions = {
|
|
246
245
|
notSkippable?: boolean;
|
|
@@ -248,7 +247,7 @@ type ShouldSkipOptions = {
|
|
|
248
247
|
/**
|
|
249
248
|
* util to detect if a hook should be skipped
|
|
250
249
|
*/
|
|
251
|
-
declare const shouldSkip: <H extends HookContext = HookContext
|
|
250
|
+
declare const shouldSkip: <H extends HookContext = HookContext>(hookName: string, context: H, options?: ShouldSkipOptions) => boolean;
|
|
252
251
|
|
|
253
252
|
declare const toJSON: (context: HookContext) => HookContext<_feathersjs_feathers.Application<any, any>, any>;
|
|
254
253
|
|
|
@@ -261,10 +260,10 @@ type OptimizeBatchPatchOptions<IdKey extends string> = {
|
|
|
261
260
|
/** the key of the id property */
|
|
262
261
|
id?: IdKey;
|
|
263
262
|
};
|
|
264
|
-
type OptimizeBatchPatchResultItem<T = Record<string, unknown>, P = Params> = [Id, T, P | undefined];
|
|
263
|
+
type OptimizeBatchPatchResultItem<T = Record<string, unknown>, P = Params> = [Id | null, T, P | undefined];
|
|
265
264
|
declare function optimizeBatchPatch<T extends Record<string, any>, IdKey extends KeyOf<T>, P extends Params, R extends Omit<T, IdKey> = Omit<T, IdKey>>(items: T[], options?: OptimizeBatchPatchOptions<IdKey>): OptimizeBatchPatchResultItem<R, P>[];
|
|
266
265
|
|
|
267
|
-
declare function flattenQuery(q: Query):
|
|
266
|
+
declare function flattenQuery(q: Query): Query;
|
|
268
267
|
|
|
269
268
|
declare function deflattenQuery(query: Query): Query;
|
|
270
269
|
|
|
@@ -303,7 +302,7 @@ type InferPatchResult<S, IdOrNullable = any> = S extends {
|
|
|
303
302
|
type InferRemoveResult<S, IdOrNullable = any> = S extends {
|
|
304
303
|
remove: (id: IdOrNullable, params: any) => infer R;
|
|
305
304
|
} ? IdOrNullable extends Id ? Single<Awaited<R>> : IdOrNullable extends null ? AsArray<Awaited<R>> : Awaited<R> : never;
|
|
306
|
-
type GetService<App extends Application, Path extends string> = App[
|
|
305
|
+
type GetService<App extends Application, Path extends string> = App['services'][Path];
|
|
307
306
|
type InferGetResultFromPath<App extends Application, Path extends string> = InferGetResult<GetService<App, Path>>;
|
|
308
307
|
type InferFindResultFromPath<App extends Application, Path extends string> = InferFindResult<GetService<App, Path>>;
|
|
309
308
|
type InferCreateDataFromPath<App extends Application, Path extends string> = InferCreateData<GetService<App, Path>>;
|
|
@@ -315,7 +314,7 @@ type InferPatchDataFromPath<App extends Application, Path extends string> = Infe
|
|
|
315
314
|
type InferUpdateResultFromPath<App extends Application, Path extends string> = InferUpdateResult<GetService<App, Path>>;
|
|
316
315
|
type InferPatchResultFromPath<App extends Application, Path extends string, IdOrNullable = any> = InferPatchResult<GetService<App, Path>, IdOrNullable>;
|
|
317
316
|
type InferRemoveResultFromPath<App extends Application, Path extends string, IdOrNullable = any> = InferRemoveResult<GetService<App, Path>, IdOrNullable>;
|
|
318
|
-
type InferDataFromPath<App extends Application, Path extends string, Method extends
|
|
319
|
-
type InferResultFromPath<App extends Application, Path extends string, Method extends
|
|
317
|
+
type InferDataFromPath<App extends Application, Path extends string, Method extends 'create' | 'update' | 'patch'> = Method extends 'create' ? InferCreateDataFromPath<App, Path> : Method extends 'update' ? InferUpdateDataFromPath<App, Path> : Method extends 'patch' ? InferPatchDataFromPath<App, Path> : never;
|
|
318
|
+
type InferResultFromPath<App extends Application, Path extends string, Method extends 'get' | 'find' | 'create' | 'update' | 'patch' | 'remove'> = Method extends 'get' ? InferGetResultFromPath<App, Path> : Method extends 'find' ? InferFindResultFromPath<App, Path> : Method extends 'create' ? InferCreateResultFromPath<App, Path> : Method extends 'update' ? InferUpdateResultFromPath<App, Path> : Method extends 'patch' ? InferPatchResultFromPath<App, Path> : Method extends 'remove' ? InferRemoveResultFromPath<App, Path> : never;
|
|
320
319
|
|
|
321
320
|
export { type ActionOnEmptyIntersect, type CreateRelatedOptions, type DebouncedFunctionApp, type DebouncedService, DebouncedStore, type DebouncedStoreOptions, type GetItemsIsArrayFrom, type GetItemsIsArrayOptions, type GetItemsIsArrayResult, type GetService, type Handle, type HookForEachOptions, type HookRunPerItemOptions, type HookSetDataOptions, type InferCreateData, type InferCreateDataFromPath, type InferCreateDataSingle, type InferCreateDataSingleFromPath, type InferCreateResult, type InferCreateResultFromPath, type InferCreateResultSingle, type InferCreateResultSingleFromPath, type InferDataFromPath, type InferFindResult, type InferFindResultFromPath, type InferGetResult, type InferGetResultFromPath, type InferPatchData, type InferPatchDataFromPath, type InferPatchResult, type InferPatchResultFromPath, type InferRemoveResult, type InferRemoveResultFromPath, type InferResultFromPath, type InferUpdateData, type InferUpdateDataFromPath, type InferUpdateResult, type InferUpdateResultFromPath, type InitDebounceMixinOptions, type MergeQueryOptions, type OnDeleteAction, type OnDeleteOptions, type OptimizeBatchPatchOptions, type OptimizeBatchPatchResultItem, type Predicate, type PredicateWithContext, type PushSetOptions, type RemoveRelatedOptions, type SetQueryKeySafelyOptions, type ShouldSkipOptions, checkMulti, createRelated, debounceMixin, defineHooks, defineParamsForServer, defineParamsFromClient, deflattenQuery, filterArray, filterObject, filterQuery, flattenQuery, forEach, getItemsIsArray, getPaginate, isMulti, isPaginated, markHookForSkip, mergeArrays, mergeQuery, onDelete, optimizeBatchPatch, paramsForServer, paramsFromClient, parseFields, pushSet, reassembleQuery, removeRelated, runPerItem, setData, setQueryKeySafely, setResultEmpty, shouldSkip, toJSON, validateQueryProperty };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as _feathersjs_feathers from '@feathersjs/feathers';
|
|
2
2
|
import { HookContext, Application, Id, HookOptions, Query, Params } from '@feathersjs/feathers';
|
|
3
|
-
import { HookContext as HookContext$1, Application as Application$1 } from '@feathersjs/feathers/lib';
|
|
4
3
|
import { PropertyPath, DebouncedFunc } from 'lodash';
|
|
5
4
|
import { PaginationOptions, FilterQueryOptions } from '@feathersjs/adapter-commons';
|
|
6
5
|
import { HookType } from 'feathers-hooks-common';
|
|
@@ -13,7 +12,7 @@ declare function checkMulti<H extends HookContext = HookContext>(): (context: H)
|
|
|
13
12
|
type MaybeArray<T> = T | T[];
|
|
14
13
|
type Promisable<T> = T | Promise<T>;
|
|
15
14
|
type Path = Array<string | number>;
|
|
16
|
-
type ReturnAsyncHook<H extends HookContext
|
|
15
|
+
type ReturnAsyncHook<H extends HookContext = HookContext> = (context: H) => Promise<H>;
|
|
17
16
|
type KeyOf<T> = Extract<keyof T, string>;
|
|
18
17
|
|
|
19
18
|
interface CreateRelatedOptions<S = Record<string, any>> {
|
|
@@ -27,7 +26,7 @@ interface CreateRelatedOptions<S = Record<string, any>> {
|
|
|
27
26
|
*/
|
|
28
27
|
declare function createRelated<S = Record<string, any>, H extends HookContext = HookContext>(options: MaybeArray<CreateRelatedOptions<S>>): (context: H) => Promise<H>;
|
|
29
28
|
|
|
30
|
-
type GetItemsIsArrayFrom =
|
|
29
|
+
type GetItemsIsArrayFrom = 'data' | 'result' | 'automatic';
|
|
31
30
|
type GetItemsIsArrayOptions = {
|
|
32
31
|
from?: GetItemsIsArrayFrom;
|
|
33
32
|
};
|
|
@@ -35,11 +34,11 @@ interface GetItemsIsArrayResult<T = any> {
|
|
|
35
34
|
items: T[];
|
|
36
35
|
isArray: boolean;
|
|
37
36
|
}
|
|
38
|
-
declare const getItemsIsArray: <T = any, H extends HookContext = HookContext
|
|
37
|
+
declare const getItemsIsArray: <T = any, H extends HookContext = HookContext>(context: H, options?: GetItemsIsArrayOptions) => GetItemsIsArrayResult<T>;
|
|
39
38
|
|
|
40
39
|
type HookForEachOptions<T = any, H = HookContext, R = any> = {
|
|
41
|
-
wait?:
|
|
42
|
-
items?: GetItemsIsArrayOptions[
|
|
40
|
+
wait?: 'sequential' | 'parallel' | false;
|
|
41
|
+
items?: GetItemsIsArrayOptions['from'];
|
|
43
42
|
forAll?: (items: T[], context: H) => Promisable<R>;
|
|
44
43
|
skip?: (context: H) => Promisable<boolean>;
|
|
45
44
|
};
|
|
@@ -49,9 +48,9 @@ type ActionPerItem<T, H, R> = (item: T, options: {
|
|
|
49
48
|
} & (undefined extends R ? {} : {
|
|
50
49
|
fromAll: R;
|
|
51
50
|
})) => Promisable<any>;
|
|
52
|
-
declare const forEach: <H extends HookContext = HookContext
|
|
51
|
+
declare const forEach: <H extends HookContext = HookContext, T = any, R = any>(actionPerItem: ActionPerItem<T, H, R>, options?: HookForEachOptions<T, H, R>) => ReturnAsyncHook<H>;
|
|
53
52
|
|
|
54
|
-
type OnDeleteAction =
|
|
53
|
+
type OnDeleteAction = 'cascade' | 'set null';
|
|
55
54
|
interface OnDeleteOptions<Path extends string = string> {
|
|
56
55
|
service: Path;
|
|
57
56
|
keyThere: string;
|
|
@@ -92,7 +91,7 @@ interface HookRunPerItemOptions {
|
|
|
92
91
|
* hook to run a hook for each item in the context
|
|
93
92
|
* uses `context.result` if it is existent. otherwise uses context.data
|
|
94
93
|
*/
|
|
95
|
-
declare const runPerItem: <H extends HookContext = HookContext
|
|
94
|
+
declare const runPerItem: <H extends HookContext = HookContext, T = any>(actionPerItem: (item: T, context: H) => Promisable<any>, _options?: HookRunPerItemOptions) => (context: H) => Promise<H>;
|
|
96
95
|
|
|
97
96
|
type Predicate<T = any> = (item: T) => boolean;
|
|
98
97
|
type PredicateWithContext<T = any> = (item: T, context: HookContext) => boolean;
|
|
@@ -139,14 +138,14 @@ declare class DebouncedStore {
|
|
|
139
138
|
private _options;
|
|
140
139
|
private _isRunningById;
|
|
141
140
|
_queueById: Record<string, DebouncedFunc<(id: Id, action: DebouncedFunctionApp) => void | Promise<void>>>;
|
|
142
|
-
add:
|
|
141
|
+
add: (id: Id, action: (app?: Application) => void | Promise<void>) => void | Promise<void> | undefined;
|
|
143
142
|
constructor(app: Application, options?: Partial<DebouncedStoreOptions>);
|
|
144
143
|
private unbounced;
|
|
145
144
|
private debounceById;
|
|
146
145
|
cancel(id: Id): void;
|
|
147
146
|
}
|
|
148
147
|
|
|
149
|
-
declare function debounceMixin(options?: Partial<InitDebounceMixinOptions>): (app: Application
|
|
148
|
+
declare function debounceMixin(options?: Partial<InitDebounceMixinOptions>): (app: Application) => void;
|
|
150
149
|
|
|
151
150
|
declare function defineHooks<A extends Application = Application, S = {
|
|
152
151
|
find: any;
|
|
@@ -158,11 +157,11 @@ declare function defineHooks<A extends Application = Application, S = {
|
|
|
158
157
|
}, Options = HookOptions<A, S>>(hooks: Options): Options;
|
|
159
158
|
|
|
160
159
|
type FilterQueryResult<Q extends Query = Query> = {
|
|
161
|
-
$select: Q[
|
|
162
|
-
$limit: Q[
|
|
163
|
-
$skip: Q[
|
|
164
|
-
$sort: Q[
|
|
165
|
-
query: Omit<Q,
|
|
160
|
+
$select: Q['$select'] extends any ? Q['$select'] : never;
|
|
161
|
+
$limit: Q['$limit'] extends any ? Q['$limit'] : never;
|
|
162
|
+
$skip: Q['$skip'] extends any ? Q['$skip'] : never;
|
|
163
|
+
$sort: Q['$sort'] extends any ? Q['$sort'] : never;
|
|
164
|
+
query: Omit<Q, '$select' | '$limit' | '$skip' | '$sort'>;
|
|
166
165
|
};
|
|
167
166
|
/**
|
|
168
167
|
* Extracts $select, $limit, $skip, $sort from a query and returns the rest as a query object.
|
|
@@ -179,7 +178,7 @@ declare function reassembleQuery(query: FilterQueryResult): Query;
|
|
|
179
178
|
* 2. it uses `service.options.paginate` if it exists
|
|
180
179
|
* 3. it uses `context.params.adapter` if it exists
|
|
181
180
|
*/
|
|
182
|
-
declare const getPaginate: <H extends HookContext = HookContext
|
|
181
|
+
declare const getPaginate: <H extends HookContext = HookContext>(context: H) => PaginationOptions | undefined;
|
|
183
182
|
|
|
184
183
|
/**
|
|
185
184
|
* util to check if a hook is a multi hook:
|
|
@@ -190,19 +189,19 @@ declare const getPaginate: <H extends HookContext = HookContext<_feathersjs_feat
|
|
|
190
189
|
* - patch: `context.id == null`
|
|
191
190
|
* - remove: `context.id == null`
|
|
192
191
|
*/
|
|
193
|
-
declare const isMulti: <H extends HookContext = HookContext
|
|
192
|
+
declare const isMulti: <H extends HookContext = HookContext>(context: H) => boolean;
|
|
194
193
|
|
|
195
194
|
/**
|
|
196
195
|
* util to check if a hook is a paginated hook using `getPaginate`
|
|
197
196
|
*/
|
|
198
|
-
declare const isPaginated: <H extends HookContext = HookContext
|
|
197
|
+
declare const isPaginated: <H extends HookContext = HookContext>(context: H) => boolean;
|
|
199
198
|
|
|
200
199
|
/**
|
|
201
200
|
* util to mark a hook for skip, has to be used with `shouldSkip`
|
|
202
201
|
*/
|
|
203
|
-
declare function markHookForSkip<H extends HookContext = HookContext>(hookName: string, type:
|
|
202
|
+
declare function markHookForSkip<H extends HookContext = HookContext>(hookName: string, type: 'all' | MaybeArray<HookType>, context?: H): H | undefined;
|
|
204
203
|
|
|
205
|
-
type Handle =
|
|
204
|
+
type Handle = 'target' | 'source' | 'combine' | 'intersect' | 'intersectOrFull';
|
|
206
205
|
type ActionOnEmptyIntersect = (target: unknown, source: unknown, prependKey: Path) => void;
|
|
207
206
|
interface MergeQueryOptions {
|
|
208
207
|
defaultHandle: Handle;
|
|
@@ -240,7 +239,7 @@ declare const setQueryKeySafely: (params: Params, key: string, value: any, opera
|
|
|
240
239
|
/**
|
|
241
240
|
* util to set `context.result` to an empty array or object, depending on the hook type
|
|
242
241
|
*/
|
|
243
|
-
declare const setResultEmpty: <H extends HookContext = HookContext
|
|
242
|
+
declare const setResultEmpty: <H extends HookContext = HookContext>(context: H) => H;
|
|
244
243
|
|
|
245
244
|
type ShouldSkipOptions = {
|
|
246
245
|
notSkippable?: boolean;
|
|
@@ -248,7 +247,7 @@ type ShouldSkipOptions = {
|
|
|
248
247
|
/**
|
|
249
248
|
* util to detect if a hook should be skipped
|
|
250
249
|
*/
|
|
251
|
-
declare const shouldSkip: <H extends HookContext = HookContext
|
|
250
|
+
declare const shouldSkip: <H extends HookContext = HookContext>(hookName: string, context: H, options?: ShouldSkipOptions) => boolean;
|
|
252
251
|
|
|
253
252
|
declare const toJSON: (context: HookContext) => HookContext<_feathersjs_feathers.Application<any, any>, any>;
|
|
254
253
|
|
|
@@ -261,10 +260,10 @@ type OptimizeBatchPatchOptions<IdKey extends string> = {
|
|
|
261
260
|
/** the key of the id property */
|
|
262
261
|
id?: IdKey;
|
|
263
262
|
};
|
|
264
|
-
type OptimizeBatchPatchResultItem<T = Record<string, unknown>, P = Params> = [Id, T, P | undefined];
|
|
263
|
+
type OptimizeBatchPatchResultItem<T = Record<string, unknown>, P = Params> = [Id | null, T, P | undefined];
|
|
265
264
|
declare function optimizeBatchPatch<T extends Record<string, any>, IdKey extends KeyOf<T>, P extends Params, R extends Omit<T, IdKey> = Omit<T, IdKey>>(items: T[], options?: OptimizeBatchPatchOptions<IdKey>): OptimizeBatchPatchResultItem<R, P>[];
|
|
266
265
|
|
|
267
|
-
declare function flattenQuery(q: Query):
|
|
266
|
+
declare function flattenQuery(q: Query): Query;
|
|
268
267
|
|
|
269
268
|
declare function deflattenQuery(query: Query): Query;
|
|
270
269
|
|
|
@@ -303,7 +302,7 @@ type InferPatchResult<S, IdOrNullable = any> = S extends {
|
|
|
303
302
|
type InferRemoveResult<S, IdOrNullable = any> = S extends {
|
|
304
303
|
remove: (id: IdOrNullable, params: any) => infer R;
|
|
305
304
|
} ? IdOrNullable extends Id ? Single<Awaited<R>> : IdOrNullable extends null ? AsArray<Awaited<R>> : Awaited<R> : never;
|
|
306
|
-
type GetService<App extends Application, Path extends string> = App[
|
|
305
|
+
type GetService<App extends Application, Path extends string> = App['services'][Path];
|
|
307
306
|
type InferGetResultFromPath<App extends Application, Path extends string> = InferGetResult<GetService<App, Path>>;
|
|
308
307
|
type InferFindResultFromPath<App extends Application, Path extends string> = InferFindResult<GetService<App, Path>>;
|
|
309
308
|
type InferCreateDataFromPath<App extends Application, Path extends string> = InferCreateData<GetService<App, Path>>;
|
|
@@ -315,7 +314,7 @@ type InferPatchDataFromPath<App extends Application, Path extends string> = Infe
|
|
|
315
314
|
type InferUpdateResultFromPath<App extends Application, Path extends string> = InferUpdateResult<GetService<App, Path>>;
|
|
316
315
|
type InferPatchResultFromPath<App extends Application, Path extends string, IdOrNullable = any> = InferPatchResult<GetService<App, Path>, IdOrNullable>;
|
|
317
316
|
type InferRemoveResultFromPath<App extends Application, Path extends string, IdOrNullable = any> = InferRemoveResult<GetService<App, Path>, IdOrNullable>;
|
|
318
|
-
type InferDataFromPath<App extends Application, Path extends string, Method extends
|
|
319
|
-
type InferResultFromPath<App extends Application, Path extends string, Method extends
|
|
317
|
+
type InferDataFromPath<App extends Application, Path extends string, Method extends 'create' | 'update' | 'patch'> = Method extends 'create' ? InferCreateDataFromPath<App, Path> : Method extends 'update' ? InferUpdateDataFromPath<App, Path> : Method extends 'patch' ? InferPatchDataFromPath<App, Path> : never;
|
|
318
|
+
type InferResultFromPath<App extends Application, Path extends string, Method extends 'get' | 'find' | 'create' | 'update' | 'patch' | 'remove'> = Method extends 'get' ? InferGetResultFromPath<App, Path> : Method extends 'find' ? InferFindResultFromPath<App, Path> : Method extends 'create' ? InferCreateResultFromPath<App, Path> : Method extends 'update' ? InferUpdateResultFromPath<App, Path> : Method extends 'patch' ? InferPatchResultFromPath<App, Path> : Method extends 'remove' ? InferRemoveResultFromPath<App, Path> : never;
|
|
320
319
|
|
|
321
320
|
export { type ActionOnEmptyIntersect, type CreateRelatedOptions, type DebouncedFunctionApp, type DebouncedService, DebouncedStore, type DebouncedStoreOptions, type GetItemsIsArrayFrom, type GetItemsIsArrayOptions, type GetItemsIsArrayResult, type GetService, type Handle, type HookForEachOptions, type HookRunPerItemOptions, type HookSetDataOptions, type InferCreateData, type InferCreateDataFromPath, type InferCreateDataSingle, type InferCreateDataSingleFromPath, type InferCreateResult, type InferCreateResultFromPath, type InferCreateResultSingle, type InferCreateResultSingleFromPath, type InferDataFromPath, type InferFindResult, type InferFindResultFromPath, type InferGetResult, type InferGetResultFromPath, type InferPatchData, type InferPatchDataFromPath, type InferPatchResult, type InferPatchResultFromPath, type InferRemoveResult, type InferRemoveResultFromPath, type InferResultFromPath, type InferUpdateData, type InferUpdateDataFromPath, type InferUpdateResult, type InferUpdateResultFromPath, type InitDebounceMixinOptions, type MergeQueryOptions, type OnDeleteAction, type OnDeleteOptions, type OptimizeBatchPatchOptions, type OptimizeBatchPatchResultItem, type Predicate, type PredicateWithContext, type PushSetOptions, type RemoveRelatedOptions, type SetQueryKeySafelyOptions, type ShouldSkipOptions, checkMulti, createRelated, debounceMixin, defineHooks, defineParamsForServer, defineParamsFromClient, deflattenQuery, filterArray, filterObject, filterQuery, flattenQuery, forEach, getItemsIsArray, getPaginate, isMulti, isPaginated, markHookForSkip, mergeArrays, mergeQuery, onDelete, optimizeBatchPatch, paramsForServer, paramsFromClient, parseFields, pushSet, reassembleQuery, removeRelated, runPerItem, setData, setQueryKeySafely, setResultEmpty, shouldSkip, toJSON, validateQueryProperty };
|