feathers-utils 6.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 +81 -99
- package/dist/index.d.cts +35 -33
- package/dist/index.d.mts +35 -33
- package/dist/index.d.ts +35 -33
- package/dist/index.mjs +81 -99
- package/package.json +29 -32
- package/src/.DS_Store +0 -0
- package/src/filters/array.ts +11 -13
- package/src/filters/index.ts +2 -2
- package/src/filters/object.ts +11 -11
- package/src/hooks/.DS_Store +0 -0
- package/src/hooks/checkMulti.ts +98 -82
- package/src/hooks/createRelated.ts +41 -41
- 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 +54 -55
- package/src/hooks/parseFields.ts +13 -13
- package/src/hooks/removeRelated.ts +22 -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/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>> {
|
|
@@ -25,9 +24,9 @@ interface CreateRelatedOptions<S = Record<string, any>> {
|
|
|
25
24
|
/**
|
|
26
25
|
* hook to create related items
|
|
27
26
|
*/
|
|
28
|
-
declare function createRelated<S = Record<string, any>, H extends HookContext = HookContext>(
|
|
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
|
|
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,10 +48,11 @@ 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
|
|
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 =
|
|
55
|
-
interface OnDeleteOptions {
|
|
53
|
+
type OnDeleteAction = 'cascade' | 'set null';
|
|
54
|
+
interface OnDeleteOptions<Path extends string = string> {
|
|
55
|
+
service: Path;
|
|
56
56
|
keyThere: string;
|
|
57
57
|
keyHere: string;
|
|
58
58
|
onDelete: OnDeleteAction;
|
|
@@ -61,7 +61,7 @@ interface OnDeleteOptions {
|
|
|
61
61
|
/**
|
|
62
62
|
* hook to manipulate related items on delete
|
|
63
63
|
*/
|
|
64
|
-
declare function onDelete<S = Record<string, any>, H extends HookContext = HookContext>(
|
|
64
|
+
declare function onDelete<S = Record<string, any>, H extends HookContext = HookContext>(options: MaybeArray<OnDeleteOptions<KeyOf<S>>>): (context: H) => Promise<H>;
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* Parse fields to date or number
|
|
@@ -79,6 +79,8 @@ interface RemoveRelatedOptions<S = Record<string, any>> {
|
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* hook to remove related items
|
|
82
|
+
*
|
|
83
|
+
* @deprecated use 'onDelete' instead
|
|
82
84
|
*/
|
|
83
85
|
declare function removeRelated<S = Record<string, any>, H extends HookContext = HookContext>({ service, keyThere, keyHere, blocking, }: RemoveRelatedOptions<S>): (context: H) => Promise<H>;
|
|
84
86
|
|
|
@@ -89,7 +91,7 @@ interface HookRunPerItemOptions {
|
|
|
89
91
|
* hook to run a hook for each item in the context
|
|
90
92
|
* uses `context.result` if it is existent. otherwise uses context.data
|
|
91
93
|
*/
|
|
92
|
-
declare const runPerItem: <H extends HookContext
|
|
94
|
+
declare const runPerItem: <H extends HookContext = HookContext, T = any>(actionPerItem: (item: T, context: H) => Promisable<any>, _options?: HookRunPerItemOptions) => (context: H) => Promise<H>;
|
|
93
95
|
|
|
94
96
|
type Predicate<T = any> = (item: T) => boolean;
|
|
95
97
|
type PredicateWithContext<T = any> = (item: T, context: HookContext) => boolean;
|
|
@@ -103,14 +105,14 @@ interface HookSetDataOptions {
|
|
|
103
105
|
*/
|
|
104
106
|
declare function setData<H extends HookContext = HookContext>(from: PropertyPath, to: PropertyPath, _options?: HookSetDataOptions): (context: H) => H;
|
|
105
107
|
|
|
106
|
-
declare function defineParamsForServer(keyToHide: string): (...whitelist: string[]) => <H extends HookContext
|
|
108
|
+
declare function defineParamsForServer(keyToHide: string): (...whitelist: string[]) => <H extends HookContext>(context: H) => H;
|
|
107
109
|
/**
|
|
108
110
|
* a hook to move params to query._$client
|
|
109
111
|
* the server only receives 'query' from params. All other params are ignored.
|
|
110
112
|
* So, to use `$populateParams` on the server, we need to move the params to query._$client
|
|
111
113
|
* the server will move them back to params
|
|
112
114
|
*/
|
|
113
|
-
declare const paramsForServer: (...whitelist: string[]) => <H extends HookContext
|
|
115
|
+
declare const paramsForServer: (...whitelist: string[]) => <H extends HookContext>(context: H) => H;
|
|
114
116
|
|
|
115
117
|
declare function defineParamsFromClient(keyToHide: string): (...whitelist: string[]) => (context: HookContext) => HookContext;
|
|
116
118
|
declare const paramsFromClient: (...whitelist: string[]) => (context: HookContext) => HookContext;
|
|
@@ -136,14 +138,14 @@ declare class DebouncedStore {
|
|
|
136
138
|
private _options;
|
|
137
139
|
private _isRunningById;
|
|
138
140
|
_queueById: Record<string, DebouncedFunc<(id: Id, action: DebouncedFunctionApp) => void | Promise<void>>>;
|
|
139
|
-
add:
|
|
141
|
+
add: (id: Id, action: (app?: Application) => void | Promise<void>) => void | Promise<void> | undefined;
|
|
140
142
|
constructor(app: Application, options?: Partial<DebouncedStoreOptions>);
|
|
141
143
|
private unbounced;
|
|
142
144
|
private debounceById;
|
|
143
145
|
cancel(id: Id): void;
|
|
144
146
|
}
|
|
145
147
|
|
|
146
|
-
declare function debounceMixin(options?: Partial<InitDebounceMixinOptions>): (app: Application
|
|
148
|
+
declare function debounceMixin(options?: Partial<InitDebounceMixinOptions>): (app: Application) => void;
|
|
147
149
|
|
|
148
150
|
declare function defineHooks<A extends Application = Application, S = {
|
|
149
151
|
find: any;
|
|
@@ -155,11 +157,11 @@ declare function defineHooks<A extends Application = Application, S = {
|
|
|
155
157
|
}, Options = HookOptions<A, S>>(hooks: Options): Options;
|
|
156
158
|
|
|
157
159
|
type FilterQueryResult<Q extends Query = Query> = {
|
|
158
|
-
$select: Q[
|
|
159
|
-
$limit: Q[
|
|
160
|
-
$skip: Q[
|
|
161
|
-
$sort: Q[
|
|
162
|
-
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'>;
|
|
163
165
|
};
|
|
164
166
|
/**
|
|
165
167
|
* Extracts $select, $limit, $skip, $sort from a query and returns the rest as a query object.
|
|
@@ -176,7 +178,7 @@ declare function reassembleQuery(query: FilterQueryResult): Query;
|
|
|
176
178
|
* 2. it uses `service.options.paginate` if it exists
|
|
177
179
|
* 3. it uses `context.params.adapter` if it exists
|
|
178
180
|
*/
|
|
179
|
-
declare const getPaginate: <H extends HookContext
|
|
181
|
+
declare const getPaginate: <H extends HookContext = HookContext>(context: H) => PaginationOptions | undefined;
|
|
180
182
|
|
|
181
183
|
/**
|
|
182
184
|
* util to check if a hook is a multi hook:
|
|
@@ -187,19 +189,19 @@ declare const getPaginate: <H extends HookContext<_feathersjs_feathers.Applicati
|
|
|
187
189
|
* - patch: `context.id == null`
|
|
188
190
|
* - remove: `context.id == null`
|
|
189
191
|
*/
|
|
190
|
-
declare const isMulti: <H extends HookContext
|
|
192
|
+
declare const isMulti: <H extends HookContext = HookContext>(context: H) => boolean;
|
|
191
193
|
|
|
192
194
|
/**
|
|
193
195
|
* util to check if a hook is a paginated hook using `getPaginate`
|
|
194
196
|
*/
|
|
195
|
-
declare const isPaginated: <H extends HookContext
|
|
197
|
+
declare const isPaginated: <H extends HookContext = HookContext>(context: H) => boolean;
|
|
196
198
|
|
|
197
199
|
/**
|
|
198
200
|
* util to mark a hook for skip, has to be used with `shouldSkip`
|
|
199
201
|
*/
|
|
200
|
-
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;
|
|
201
203
|
|
|
202
|
-
type Handle =
|
|
204
|
+
type Handle = 'target' | 'source' | 'combine' | 'intersect' | 'intersectOrFull';
|
|
203
205
|
type ActionOnEmptyIntersect = (target: unknown, source: unknown, prependKey: Path) => void;
|
|
204
206
|
interface MergeQueryOptions {
|
|
205
207
|
defaultHandle: Handle;
|
|
@@ -237,7 +239,7 @@ declare const setQueryKeySafely: (params: Params, key: string, value: any, opera
|
|
|
237
239
|
/**
|
|
238
240
|
* util to set `context.result` to an empty array or object, depending on the hook type
|
|
239
241
|
*/
|
|
240
|
-
declare const setResultEmpty: <H extends HookContext
|
|
242
|
+
declare const setResultEmpty: <H extends HookContext = HookContext>(context: H) => H;
|
|
241
243
|
|
|
242
244
|
type ShouldSkipOptions = {
|
|
243
245
|
notSkippable?: boolean;
|
|
@@ -245,7 +247,7 @@ type ShouldSkipOptions = {
|
|
|
245
247
|
/**
|
|
246
248
|
* util to detect if a hook should be skipped
|
|
247
249
|
*/
|
|
248
|
-
declare const shouldSkip: <H extends HookContext
|
|
250
|
+
declare const shouldSkip: <H extends HookContext = HookContext>(hookName: string, context: H, options?: ShouldSkipOptions) => boolean;
|
|
249
251
|
|
|
250
252
|
declare const toJSON: (context: HookContext) => HookContext<_feathersjs_feathers.Application<any, any>, any>;
|
|
251
253
|
|
|
@@ -258,10 +260,10 @@ type OptimizeBatchPatchOptions<IdKey extends string> = {
|
|
|
258
260
|
/** the key of the id property */
|
|
259
261
|
id?: IdKey;
|
|
260
262
|
};
|
|
261
|
-
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];
|
|
262
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>[];
|
|
263
265
|
|
|
264
|
-
declare function flattenQuery(q: Query):
|
|
266
|
+
declare function flattenQuery(q: Query): Query;
|
|
265
267
|
|
|
266
268
|
declare function deflattenQuery(query: Query): Query;
|
|
267
269
|
|
|
@@ -300,7 +302,7 @@ type InferPatchResult<S, IdOrNullable = any> = S extends {
|
|
|
300
302
|
type InferRemoveResult<S, IdOrNullable = any> = S extends {
|
|
301
303
|
remove: (id: IdOrNullable, params: any) => infer R;
|
|
302
304
|
} ? IdOrNullable extends Id ? Single<Awaited<R>> : IdOrNullable extends null ? AsArray<Awaited<R>> : Awaited<R> : never;
|
|
303
|
-
type GetService<App extends Application, Path extends string> = App[
|
|
305
|
+
type GetService<App extends Application, Path extends string> = App['services'][Path];
|
|
304
306
|
type InferGetResultFromPath<App extends Application, Path extends string> = InferGetResult<GetService<App, Path>>;
|
|
305
307
|
type InferFindResultFromPath<App extends Application, Path extends string> = InferFindResult<GetService<App, Path>>;
|
|
306
308
|
type InferCreateDataFromPath<App extends Application, Path extends string> = InferCreateData<GetService<App, Path>>;
|
|
@@ -312,7 +314,7 @@ type InferPatchDataFromPath<App extends Application, Path extends string> = Infe
|
|
|
312
314
|
type InferUpdateResultFromPath<App extends Application, Path extends string> = InferUpdateResult<GetService<App, Path>>;
|
|
313
315
|
type InferPatchResultFromPath<App extends Application, Path extends string, IdOrNullable = any> = InferPatchResult<GetService<App, Path>, IdOrNullable>;
|
|
314
316
|
type InferRemoveResultFromPath<App extends Application, Path extends string, IdOrNullable = any> = InferRemoveResult<GetService<App, Path>, IdOrNullable>;
|
|
315
|
-
type InferDataFromPath<App extends Application, Path extends string, Method extends
|
|
316
|
-
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;
|
|
317
319
|
|
|
318
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.ts
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>> {
|
|
@@ -25,9 +24,9 @@ interface CreateRelatedOptions<S = Record<string, any>> {
|
|
|
25
24
|
/**
|
|
26
25
|
* hook to create related items
|
|
27
26
|
*/
|
|
28
|
-
declare function createRelated<S = Record<string, any>, H extends HookContext = HookContext>(
|
|
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
|
|
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,10 +48,11 @@ 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
|
|
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 =
|
|
55
|
-
interface OnDeleteOptions {
|
|
53
|
+
type OnDeleteAction = 'cascade' | 'set null';
|
|
54
|
+
interface OnDeleteOptions<Path extends string = string> {
|
|
55
|
+
service: Path;
|
|
56
56
|
keyThere: string;
|
|
57
57
|
keyHere: string;
|
|
58
58
|
onDelete: OnDeleteAction;
|
|
@@ -61,7 +61,7 @@ interface OnDeleteOptions {
|
|
|
61
61
|
/**
|
|
62
62
|
* hook to manipulate related items on delete
|
|
63
63
|
*/
|
|
64
|
-
declare function onDelete<S = Record<string, any>, H extends HookContext = HookContext>(
|
|
64
|
+
declare function onDelete<S = Record<string, any>, H extends HookContext = HookContext>(options: MaybeArray<OnDeleteOptions<KeyOf<S>>>): (context: H) => Promise<H>;
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* Parse fields to date or number
|
|
@@ -79,6 +79,8 @@ interface RemoveRelatedOptions<S = Record<string, any>> {
|
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* hook to remove related items
|
|
82
|
+
*
|
|
83
|
+
* @deprecated use 'onDelete' instead
|
|
82
84
|
*/
|
|
83
85
|
declare function removeRelated<S = Record<string, any>, H extends HookContext = HookContext>({ service, keyThere, keyHere, blocking, }: RemoveRelatedOptions<S>): (context: H) => Promise<H>;
|
|
84
86
|
|
|
@@ -89,7 +91,7 @@ interface HookRunPerItemOptions {
|
|
|
89
91
|
* hook to run a hook for each item in the context
|
|
90
92
|
* uses `context.result` if it is existent. otherwise uses context.data
|
|
91
93
|
*/
|
|
92
|
-
declare const runPerItem: <H extends HookContext
|
|
94
|
+
declare const runPerItem: <H extends HookContext = HookContext, T = any>(actionPerItem: (item: T, context: H) => Promisable<any>, _options?: HookRunPerItemOptions) => (context: H) => Promise<H>;
|
|
93
95
|
|
|
94
96
|
type Predicate<T = any> = (item: T) => boolean;
|
|
95
97
|
type PredicateWithContext<T = any> = (item: T, context: HookContext) => boolean;
|
|
@@ -103,14 +105,14 @@ interface HookSetDataOptions {
|
|
|
103
105
|
*/
|
|
104
106
|
declare function setData<H extends HookContext = HookContext>(from: PropertyPath, to: PropertyPath, _options?: HookSetDataOptions): (context: H) => H;
|
|
105
107
|
|
|
106
|
-
declare function defineParamsForServer(keyToHide: string): (...whitelist: string[]) => <H extends HookContext
|
|
108
|
+
declare function defineParamsForServer(keyToHide: string): (...whitelist: string[]) => <H extends HookContext>(context: H) => H;
|
|
107
109
|
/**
|
|
108
110
|
* a hook to move params to query._$client
|
|
109
111
|
* the server only receives 'query' from params. All other params are ignored.
|
|
110
112
|
* So, to use `$populateParams` on the server, we need to move the params to query._$client
|
|
111
113
|
* the server will move them back to params
|
|
112
114
|
*/
|
|
113
|
-
declare const paramsForServer: (...whitelist: string[]) => <H extends HookContext
|
|
115
|
+
declare const paramsForServer: (...whitelist: string[]) => <H extends HookContext>(context: H) => H;
|
|
114
116
|
|
|
115
117
|
declare function defineParamsFromClient(keyToHide: string): (...whitelist: string[]) => (context: HookContext) => HookContext;
|
|
116
118
|
declare const paramsFromClient: (...whitelist: string[]) => (context: HookContext) => HookContext;
|
|
@@ -136,14 +138,14 @@ declare class DebouncedStore {
|
|
|
136
138
|
private _options;
|
|
137
139
|
private _isRunningById;
|
|
138
140
|
_queueById: Record<string, DebouncedFunc<(id: Id, action: DebouncedFunctionApp) => void | Promise<void>>>;
|
|
139
|
-
add:
|
|
141
|
+
add: (id: Id, action: (app?: Application) => void | Promise<void>) => void | Promise<void> | undefined;
|
|
140
142
|
constructor(app: Application, options?: Partial<DebouncedStoreOptions>);
|
|
141
143
|
private unbounced;
|
|
142
144
|
private debounceById;
|
|
143
145
|
cancel(id: Id): void;
|
|
144
146
|
}
|
|
145
147
|
|
|
146
|
-
declare function debounceMixin(options?: Partial<InitDebounceMixinOptions>): (app: Application
|
|
148
|
+
declare function debounceMixin(options?: Partial<InitDebounceMixinOptions>): (app: Application) => void;
|
|
147
149
|
|
|
148
150
|
declare function defineHooks<A extends Application = Application, S = {
|
|
149
151
|
find: any;
|
|
@@ -155,11 +157,11 @@ declare function defineHooks<A extends Application = Application, S = {
|
|
|
155
157
|
}, Options = HookOptions<A, S>>(hooks: Options): Options;
|
|
156
158
|
|
|
157
159
|
type FilterQueryResult<Q extends Query = Query> = {
|
|
158
|
-
$select: Q[
|
|
159
|
-
$limit: Q[
|
|
160
|
-
$skip: Q[
|
|
161
|
-
$sort: Q[
|
|
162
|
-
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'>;
|
|
163
165
|
};
|
|
164
166
|
/**
|
|
165
167
|
* Extracts $select, $limit, $skip, $sort from a query and returns the rest as a query object.
|
|
@@ -176,7 +178,7 @@ declare function reassembleQuery(query: FilterQueryResult): Query;
|
|
|
176
178
|
* 2. it uses `service.options.paginate` if it exists
|
|
177
179
|
* 3. it uses `context.params.adapter` if it exists
|
|
178
180
|
*/
|
|
179
|
-
declare const getPaginate: <H extends HookContext
|
|
181
|
+
declare const getPaginate: <H extends HookContext = HookContext>(context: H) => PaginationOptions | undefined;
|
|
180
182
|
|
|
181
183
|
/**
|
|
182
184
|
* util to check if a hook is a multi hook:
|
|
@@ -187,19 +189,19 @@ declare const getPaginate: <H extends HookContext<_feathersjs_feathers.Applicati
|
|
|
187
189
|
* - patch: `context.id == null`
|
|
188
190
|
* - remove: `context.id == null`
|
|
189
191
|
*/
|
|
190
|
-
declare const isMulti: <H extends HookContext
|
|
192
|
+
declare const isMulti: <H extends HookContext = HookContext>(context: H) => boolean;
|
|
191
193
|
|
|
192
194
|
/**
|
|
193
195
|
* util to check if a hook is a paginated hook using `getPaginate`
|
|
194
196
|
*/
|
|
195
|
-
declare const isPaginated: <H extends HookContext
|
|
197
|
+
declare const isPaginated: <H extends HookContext = HookContext>(context: H) => boolean;
|
|
196
198
|
|
|
197
199
|
/**
|
|
198
200
|
* util to mark a hook for skip, has to be used with `shouldSkip`
|
|
199
201
|
*/
|
|
200
|
-
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;
|
|
201
203
|
|
|
202
|
-
type Handle =
|
|
204
|
+
type Handle = 'target' | 'source' | 'combine' | 'intersect' | 'intersectOrFull';
|
|
203
205
|
type ActionOnEmptyIntersect = (target: unknown, source: unknown, prependKey: Path) => void;
|
|
204
206
|
interface MergeQueryOptions {
|
|
205
207
|
defaultHandle: Handle;
|
|
@@ -237,7 +239,7 @@ declare const setQueryKeySafely: (params: Params, key: string, value: any, opera
|
|
|
237
239
|
/**
|
|
238
240
|
* util to set `context.result` to an empty array or object, depending on the hook type
|
|
239
241
|
*/
|
|
240
|
-
declare const setResultEmpty: <H extends HookContext
|
|
242
|
+
declare const setResultEmpty: <H extends HookContext = HookContext>(context: H) => H;
|
|
241
243
|
|
|
242
244
|
type ShouldSkipOptions = {
|
|
243
245
|
notSkippable?: boolean;
|
|
@@ -245,7 +247,7 @@ type ShouldSkipOptions = {
|
|
|
245
247
|
/**
|
|
246
248
|
* util to detect if a hook should be skipped
|
|
247
249
|
*/
|
|
248
|
-
declare const shouldSkip: <H extends HookContext
|
|
250
|
+
declare const shouldSkip: <H extends HookContext = HookContext>(hookName: string, context: H, options?: ShouldSkipOptions) => boolean;
|
|
249
251
|
|
|
250
252
|
declare const toJSON: (context: HookContext) => HookContext<_feathersjs_feathers.Application<any, any>, any>;
|
|
251
253
|
|
|
@@ -258,10 +260,10 @@ type OptimizeBatchPatchOptions<IdKey extends string> = {
|
|
|
258
260
|
/** the key of the id property */
|
|
259
261
|
id?: IdKey;
|
|
260
262
|
};
|
|
261
|
-
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];
|
|
262
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>[];
|
|
263
265
|
|
|
264
|
-
declare function flattenQuery(q: Query):
|
|
266
|
+
declare function flattenQuery(q: Query): Query;
|
|
265
267
|
|
|
266
268
|
declare function deflattenQuery(query: Query): Query;
|
|
267
269
|
|
|
@@ -300,7 +302,7 @@ type InferPatchResult<S, IdOrNullable = any> = S extends {
|
|
|
300
302
|
type InferRemoveResult<S, IdOrNullable = any> = S extends {
|
|
301
303
|
remove: (id: IdOrNullable, params: any) => infer R;
|
|
302
304
|
} ? IdOrNullable extends Id ? Single<Awaited<R>> : IdOrNullable extends null ? AsArray<Awaited<R>> : Awaited<R> : never;
|
|
303
|
-
type GetService<App extends Application, Path extends string> = App[
|
|
305
|
+
type GetService<App extends Application, Path extends string> = App['services'][Path];
|
|
304
306
|
type InferGetResultFromPath<App extends Application, Path extends string> = InferGetResult<GetService<App, Path>>;
|
|
305
307
|
type InferFindResultFromPath<App extends Application, Path extends string> = InferFindResult<GetService<App, Path>>;
|
|
306
308
|
type InferCreateDataFromPath<App extends Application, Path extends string> = InferCreateData<GetService<App, Path>>;
|
|
@@ -312,7 +314,7 @@ type InferPatchDataFromPath<App extends Application, Path extends string> = Infe
|
|
|
312
314
|
type InferUpdateResultFromPath<App extends Application, Path extends string> = InferUpdateResult<GetService<App, Path>>;
|
|
313
315
|
type InferPatchResultFromPath<App extends Application, Path extends string, IdOrNullable = any> = InferPatchResult<GetService<App, Path>, IdOrNullable>;
|
|
314
316
|
type InferRemoveResultFromPath<App extends Application, Path extends string, IdOrNullable = any> = InferRemoveResult<GetService<App, Path>, IdOrNullable>;
|
|
315
|
-
type InferDataFromPath<App extends Application, Path extends string, Method extends
|
|
316
|
-
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;
|
|
317
319
|
|
|
318
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 };
|