feathers-utils 2.0.0-2 → 2.0.0-4
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/dist/esm/filters/array.d.ts +1 -1
- package/dist/esm/filters/array.js +2 -2
- package/dist/esm/filters/object.d.ts +2 -0
- package/dist/esm/filters/object.js +8 -0
- package/dist/esm/hooks/checkMulti.d.ts +2 -2
- package/dist/esm/hooks/createRelated.d.ts +8 -2
- package/dist/esm/hooks/createRelated.js +2 -3
- package/dist/esm/hooks/onDelete.d.ts +8 -2
- package/dist/esm/hooks/onDelete.js +8 -7
- package/dist/esm/hooks/removeRelated.d.ts +7 -2
- package/dist/esm/hooks/removeRelated.js +8 -7
- package/dist/esm/hooks/runPerItem.d.ts +5 -2
- package/dist/esm/hooks/runPerItem.js +1 -1
- package/dist/esm/hooks/setData.d.ts +7 -2
- package/dist/esm/hooks/setData.js +3 -2
- package/dist/esm/index.d.ts +19 -34
- package/dist/esm/index.js +21 -33
- package/dist/esm/mixins/debounce-mixin/DebouncedStore.d.ts +5 -2
- package/dist/esm/mixins/debounce-mixin/DebouncedStore.js +2 -2
- package/dist/esm/mixins/debounce-mixin/debounceMixin.d.ts +3 -0
- package/dist/esm/mixins/debounce-mixin/debounceMixin.js +19 -0
- package/dist/esm/mixins/debounce-mixin/index.d.ts +3 -8
- package/dist/esm/mixins/debounce-mixin/index.js +3 -20
- package/dist/esm/mixins/debounce-mixin/types.d.ts +13 -0
- package/dist/esm/mixins/debounce-mixin/types.js +1 -0
- package/dist/esm/types.d.ts +1 -77
- package/dist/esm/types.js +0 -1
- package/dist/esm/typesInternal.d.ts +3 -0
- package/dist/esm/typesInternal.js +3 -0
- package/dist/esm/utils/filterQuery.d.ts +6 -1
- package/dist/esm/utils/filterQuery.js +5 -3
- package/dist/esm/utils/getItemsIsArray.d.ts +5 -2
- package/dist/esm/utils/getItemsIsArray.js +7 -12
- package/dist/esm/utils/getPaginate.d.ts +2 -6
- package/dist/esm/utils/getPaginate.js +1 -1
- package/dist/esm/utils/isMulti.d.ts +1 -1
- package/dist/esm/utils/isPaginated.d.ts +1 -1
- package/dist/esm/utils/markHookForSkip.d.ts +3 -2
- package/dist/esm/utils/markHookForSkip.js +6 -5
- package/dist/esm/utils/mergeQuery/index.d.ts +3 -3
- package/dist/esm/utils/mergeQuery/index.js +3 -338
- package/dist/esm/utils/mergeQuery/mergeArrays.d.ts +2 -1
- package/dist/esm/utils/mergeQuery/mergeArrays.js +2 -2
- package/dist/esm/utils/mergeQuery/mergeQuery.d.ts +3 -0
- package/dist/esm/utils/mergeQuery/mergeQuery.js +68 -0
- package/dist/esm/utils/mergeQuery/types.d.ts +13 -0
- package/dist/esm/utils/mergeQuery/types.js +1 -0
- package/dist/esm/utils/mergeQuery/utils.d.ts +11 -0
- package/dist/esm/utils/mergeQuery/utils.js +272 -0
- package/dist/esm/utils/pushSet.d.ts +4 -1
- package/dist/esm/utils/pushSet.js +1 -1
- package/dist/esm/utils/setResultEmpty.d.ts +1 -1
- package/dist/esm/utils/setResultEmpty.js +1 -1
- package/dist/esm/utils/shouldSkip.d.ts +1 -1
- package/dist/esm/utils/validateQueryProperty.js +1 -1
- package/dist/filters/array.d.ts +1 -1
- package/dist/filters/array.js +2 -2
- package/dist/filters/object.d.ts +2 -0
- package/dist/filters/object.js +15 -0
- package/dist/hooks/checkMulti.d.ts +2 -2
- package/dist/hooks/createRelated.d.ts +8 -2
- package/dist/hooks/createRelated.js +2 -3
- package/dist/hooks/onDelete.d.ts +8 -2
- package/dist/hooks/onDelete.js +8 -7
- package/dist/hooks/removeRelated.d.ts +7 -2
- package/dist/hooks/removeRelated.js +8 -7
- package/dist/hooks/runPerItem.d.ts +5 -2
- package/dist/hooks/runPerItem.js +1 -1
- package/dist/hooks/setData.d.ts +7 -2
- package/dist/hooks/setData.js +3 -2
- package/dist/index.d.ts +19 -34
- package/dist/index.js +23 -49
- package/dist/mixins/debounce-mixin/DebouncedStore.d.ts +5 -2
- package/dist/mixins/debounce-mixin/DebouncedStore.js +2 -2
- package/dist/mixins/debounce-mixin/debounceMixin.d.ts +3 -0
- package/dist/mixins/debounce-mixin/debounceMixin.js +23 -0
- package/dist/mixins/debounce-mixin/index.d.ts +3 -8
- package/dist/mixins/debounce-mixin/index.js +17 -22
- package/dist/mixins/debounce-mixin/types.d.ts +13 -0
- package/dist/mixins/debounce-mixin/types.js +2 -0
- package/dist/types.d.ts +1 -77
- package/dist/types.js +0 -1
- package/dist/typesInternal.d.ts +3 -0
- package/dist/typesInternal.js +4 -0
- package/dist/utils/filterQuery.d.ts +6 -1
- package/dist/utils/filterQuery.js +4 -2
- package/dist/utils/getItemsIsArray.d.ts +5 -2
- package/dist/utils/getItemsIsArray.js +7 -12
- package/dist/utils/getPaginate.d.ts +2 -6
- package/dist/utils/isMulti.d.ts +1 -1
- package/dist/utils/isPaginated.d.ts +1 -1
- package/dist/utils/markHookForSkip.d.ts +3 -2
- package/dist/utils/markHookForSkip.js +6 -5
- package/dist/utils/mergeQuery/index.d.ts +3 -3
- package/dist/utils/mergeQuery/index.js +16 -342
- package/dist/utils/mergeQuery/mergeArrays.d.ts +2 -1
- package/dist/utils/mergeQuery/mergeArrays.js +2 -2
- package/dist/utils/mergeQuery/mergeQuery.d.ts +3 -0
- package/dist/utils/mergeQuery/mergeQuery.js +75 -0
- package/dist/utils/mergeQuery/types.d.ts +13 -0
- package/dist/utils/mergeQuery/types.js +2 -0
- package/dist/utils/mergeQuery/utils.d.ts +11 -0
- package/dist/utils/mergeQuery/utils.js +287 -0
- package/dist/utils/pushSet.d.ts +4 -1
- package/dist/utils/pushSet.js +1 -1
- package/dist/utils/setResultEmpty.d.ts +1 -1
- package/dist/utils/setResultEmpty.js +1 -1
- package/dist/utils/shouldSkip.d.ts +1 -1
- package/package.json +5 -2
- package/src/filters/array.ts +13 -9
- package/src/filters/object.ts +15 -0
- package/src/hooks/checkMulti.ts +8 -6
- package/src/hooks/createRelated.ts +21 -12
- package/src/hooks/onDelete.ts +28 -13
- package/src/hooks/removeRelated.ts +28 -16
- package/src/hooks/runPerItem.ts +19 -10
- package/src/hooks/setData.ts +24 -15
- package/src/index.ts +21 -38
- package/src/mixins/debounce-mixin/DebouncedStore.ts +29 -24
- package/src/mixins/debounce-mixin/debounceMixin.ts +33 -0
- package/src/mixins/debounce-mixin/index.ts +3 -39
- package/src/mixins/debounce-mixin/types.ts +16 -0
- package/src/types.ts +6 -117
- package/src/typesInternal.ts +6 -0
- package/src/utils/filterQuery.ts +22 -10
- package/src/utils/getItemsIsArray.ts +15 -16
- package/src/utils/getPaginate.ts +11 -14
- package/src/utils/isMulti.ts +3 -3
- package/src/utils/isPaginated.ts +6 -4
- package/src/utils/markHookForSkip.ts +18 -16
- package/src/utils/mergeQuery/index.ts +3 -379
- package/src/utils/mergeQuery/mergeArrays.ts +25 -18
- package/src/utils/mergeQuery/mergeQuery.ts +102 -0
- package/src/utils/mergeQuery/types.ts +25 -0
- package/src/utils/mergeQuery/utils.ts +342 -0
- package/src/utils/pushSet.ts +14 -7
- package/src/utils/setResultEmpty.ts +8 -6
- package/src/utils/shouldSkip.ts +4 -4
- package/src/utils/validateQueryProperty.ts +8 -4
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { FilterQueryOptions } from "@feathersjs/adapter-commons";
|
|
2
|
-
export declare const filterArray: () => (arr: any, { operators }: FilterQueryOptions) => any;
|
|
2
|
+
export declare const filterArray: (key: string) => (arr: any, { operators }: FilterQueryOptions) => any;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { validateQueryProperty } from "../utils/validateQueryProperty";
|
|
2
|
-
export const filterArray = () => (arr, { operators }) => {
|
|
2
|
+
export const filterArray = (key) => (arr, { operators }) => {
|
|
3
3
|
if (arr && !Array.isArray(arr)) {
|
|
4
|
-
throw new Error(
|
|
4
|
+
throw new Error(`Invalid query parameter '${key}'. It has to be an array`);
|
|
5
5
|
}
|
|
6
6
|
if (Array.isArray(arr)) {
|
|
7
7
|
return arr.map((current) => validateQueryProperty(current, operators));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { validateQueryProperty } from "../utils/validateQueryProperty";
|
|
2
|
+
import _isObject from "lodash/isObject";
|
|
3
|
+
export const filterObject = (key) => (obj, { operators }) => {
|
|
4
|
+
if (obj && !_isObject(obj)) {
|
|
5
|
+
throw new Error(`Invalid query parameter: '${key}'. It has to be an object`);
|
|
6
|
+
}
|
|
7
|
+
return validateQueryProperty(obj, operators);
|
|
8
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function checkMulti():
|
|
1
|
+
import type { HookContext } from "@feathersjs/feathers";
|
|
2
|
+
export declare function checkMulti<H extends HookContext = HookContext>(): (context: H) => H;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import type { HookContext } from "@feathersjs/feathers";
|
|
2
|
-
import type {
|
|
3
|
-
export
|
|
2
|
+
import type { Promisable } from "../typesInternal";
|
|
3
|
+
export interface CreateRelatedOptions<S = Record<string, any>> {
|
|
4
|
+
service: keyof S;
|
|
5
|
+
multi?: boolean;
|
|
6
|
+
data: (item: any, context: HookContext) => Promisable<Record<string, any>>;
|
|
7
|
+
createItemsInDataArraySeparately?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function createRelated<S = Record<string, any>, H extends HookContext = HookContext>({ service, multi, data, createItemsInDataArraySeparately, }: CreateRelatedOptions<S>): (context: H) => Promise<H>;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { checkContext } from "feathers-hooks-common";
|
|
2
2
|
import { getItemsIsArray } from "../utils/getItemsIsArray";
|
|
3
|
-
export function createRelated({ service, multi = true, data, createItemsInDataArraySeparately = true }) {
|
|
3
|
+
export function createRelated({ service, multi = true, data, createItemsInDataArraySeparately = true, }) {
|
|
4
4
|
if (!service || !data) {
|
|
5
5
|
throw "initialize hook 'createRelated' completely!";
|
|
6
6
|
}
|
|
7
7
|
return async (context) => {
|
|
8
|
-
// @ts-expect-error wait for feathers-hooks-common to update
|
|
9
8
|
checkContext(context, "after", undefined, "createRelated");
|
|
10
9
|
const { items } = getItemsIsArray(context);
|
|
11
|
-
let dataToCreate = (await Promise.all(items.map(async (item) => data(item, context)))).filter(x => !!x);
|
|
10
|
+
let dataToCreate = (await Promise.all(items.map(async (item) => data(item, context)))).filter((x) => !!x);
|
|
12
11
|
if (createItemsInDataArraySeparately) {
|
|
13
12
|
dataToCreate = dataToCreate.flat();
|
|
14
13
|
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import type { HookContext } from "@feathersjs/feathers";
|
|
2
|
-
|
|
3
|
-
export
|
|
2
|
+
export declare type OnDeleteAction = "cascade" | "set null";
|
|
3
|
+
export interface OnDeleteOptions {
|
|
4
|
+
keyThere: string;
|
|
5
|
+
keyHere: string;
|
|
6
|
+
onDelete: OnDeleteAction;
|
|
7
|
+
blocking?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function onDelete<S = Record<string, any>, H extends HookContext = HookContext>(service: keyof S, { keyThere, keyHere, onDelete, blocking, }: OnDeleteOptions): (context: H) => Promise<H>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { checkContext } from "feathers-hooks-common";
|
|
2
2
|
import { getItemsIsArray } from "../utils/getItemsIsArray";
|
|
3
|
-
export function onDelete(service, { keyThere, keyHere = "id", onDelete = "cascade", blocking = true }) {
|
|
3
|
+
export function onDelete(service, { keyThere, keyHere = "id", onDelete = "cascade", blocking = true, }) {
|
|
4
4
|
if (!service || !keyThere) {
|
|
5
5
|
throw "initialize hook 'removeRelated' completely!";
|
|
6
6
|
}
|
|
@@ -8,10 +8,9 @@ export function onDelete(service, { keyThere, keyHere = "id", onDelete = "cascad
|
|
|
8
8
|
throw "onDelete must be 'cascade' or 'set null'";
|
|
9
9
|
}
|
|
10
10
|
return async (context) => {
|
|
11
|
-
// @ts-expect-error wait for feathers-hooks-common to update
|
|
12
11
|
checkContext(context, "after", "remove", "onDelete");
|
|
13
12
|
const { items } = getItemsIsArray(context);
|
|
14
|
-
let ids = items.map(x => x[keyHere]).filter(x => !!x);
|
|
13
|
+
let ids = items.map((x) => x[keyHere]).filter((x) => !!x);
|
|
15
14
|
ids = [...new Set(ids)];
|
|
16
15
|
if (!ids || ids.length <= 0) {
|
|
17
16
|
return context;
|
|
@@ -19,10 +18,10 @@ export function onDelete(service, { keyThere, keyHere = "id", onDelete = "cascad
|
|
|
19
18
|
const params = {
|
|
20
19
|
query: {
|
|
21
20
|
[keyThere]: {
|
|
22
|
-
$in: ids
|
|
23
|
-
}
|
|
21
|
+
$in: ids,
|
|
22
|
+
},
|
|
24
23
|
},
|
|
25
|
-
paginate: false
|
|
24
|
+
paginate: false,
|
|
26
25
|
};
|
|
27
26
|
let promise;
|
|
28
27
|
if (onDelete === "cascade") {
|
|
@@ -30,7 +29,9 @@ export function onDelete(service, { keyThere, keyHere = "id", onDelete = "cascad
|
|
|
30
29
|
}
|
|
31
30
|
else if (onDelete === "set null") {
|
|
32
31
|
const data = { [keyThere]: null };
|
|
33
|
-
promise = context.app
|
|
32
|
+
promise = context.app
|
|
33
|
+
.service(service)
|
|
34
|
+
.patch(null, data, params);
|
|
34
35
|
}
|
|
35
36
|
if (blocking) {
|
|
36
37
|
await promise;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import type { HookContext } from "@feathersjs/feathers";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
export interface RemoveRelatedOptions<S = Record<string, any>> {
|
|
3
|
+
service: keyof S;
|
|
4
|
+
keyThere: string;
|
|
5
|
+
keyHere: string;
|
|
6
|
+
blocking?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function removeRelated<S = Record<string, any>, H extends HookContext = HookContext>({ service, keyThere, keyHere, blocking, }: RemoveRelatedOptions<S>): (context: H) => Promise<H>;
|
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
import { checkContext } from "feathers-hooks-common";
|
|
2
2
|
import { getItemsIsArray } from "../utils/getItemsIsArray";
|
|
3
|
-
export function removeRelated({ service, keyThere, keyHere = "id", blocking = true }) {
|
|
3
|
+
export function removeRelated({ service, keyThere, keyHere = "id", blocking = true, }) {
|
|
4
4
|
if (!service || !keyThere) {
|
|
5
5
|
throw "initialize hook 'removeRelated' completely!";
|
|
6
6
|
}
|
|
7
7
|
return async (context) => {
|
|
8
|
-
// @ts-expect-error wait for feathers-hooks-common to update
|
|
9
8
|
checkContext(context, "after", "remove", "removeRelated");
|
|
10
9
|
const { items } = getItemsIsArray(context);
|
|
11
|
-
let ids = items.map(x => x[keyHere]).filter(x => !!x);
|
|
10
|
+
let ids = items.map((x) => x[keyHere]).filter((x) => !!x);
|
|
12
11
|
ids = [...new Set(ids)];
|
|
13
12
|
if (!ids || ids.length <= 0) {
|
|
14
13
|
return context;
|
|
15
14
|
}
|
|
16
15
|
// feathers does not accept `paginate: false` for remove, but some adapters need it to work properly
|
|
17
|
-
const promise = context.app
|
|
16
|
+
const promise = context.app
|
|
17
|
+
.service(service)
|
|
18
|
+
.remove(null, {
|
|
18
19
|
query: {
|
|
19
20
|
[keyThere]: {
|
|
20
|
-
$in: ids
|
|
21
|
-
}
|
|
21
|
+
$in: ids,
|
|
22
|
+
},
|
|
22
23
|
},
|
|
23
|
-
paginate: false
|
|
24
|
+
paginate: false,
|
|
24
25
|
});
|
|
25
26
|
if (blocking) {
|
|
26
27
|
await promise;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import type { HookRunPerItemOptions, ReturnAsyncHook, Promisable } from "../types";
|
|
2
1
|
import type { HookContext } from "@feathersjs/feathers";
|
|
3
|
-
|
|
2
|
+
import type { Promisable } from "../typesInternal";
|
|
3
|
+
export interface HookRunPerItemOptions {
|
|
4
|
+
wait?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare const runPerItem: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any> = HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(actionPerItem: (item: any, context: H) => Promisable<any>, _options?: HookRunPerItemOptions) => (context: H) => Promise<H>;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import type { HookContext } from "@feathersjs/feathers";
|
|
1
2
|
import type { PropertyPath } from "lodash";
|
|
2
|
-
import type {
|
|
3
|
-
export
|
|
3
|
+
import type { PredicateWithContext } from "../types";
|
|
4
|
+
export interface HookSetDataOptions {
|
|
5
|
+
allowUndefined?: boolean;
|
|
6
|
+
overwrite?: boolean | PredicateWithContext;
|
|
7
|
+
}
|
|
8
|
+
export declare function setData<H extends HookContext = HookContext>(from: PropertyPath, to: PropertyPath, _options?: HookSetDataOptions): (context: H) => H;
|
|
@@ -5,7 +5,7 @@ import { Forbidden } from "@feathersjs/errors";
|
|
|
5
5
|
import { getItemsIsArray } from "../utils/getItemsIsArray";
|
|
6
6
|
const defaultOptions = {
|
|
7
7
|
allowUndefined: false,
|
|
8
|
-
overwrite: true
|
|
8
|
+
overwrite: true,
|
|
9
9
|
};
|
|
10
10
|
export function setData(from, to, _options) {
|
|
11
11
|
const options = Object.assign({}, defaultOptions, _options);
|
|
@@ -15,7 +15,8 @@ export function setData(from, to, _options) {
|
|
|
15
15
|
if (!context.params?.provider || options.allowUndefined === true) {
|
|
16
16
|
return context;
|
|
17
17
|
}
|
|
18
|
-
if (!options.overwrite &&
|
|
18
|
+
if (!options.overwrite &&
|
|
19
|
+
items.every((item) => _has(item, to))) {
|
|
19
20
|
return context;
|
|
20
21
|
}
|
|
21
22
|
throw new Forbidden(`Expected field ${from.toString()} not available`);
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,36 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export { debounceMixin };
|
|
20
|
-
export { DebouncedService };
|
|
21
|
-
export { DebouncedStore };
|
|
22
|
-
export { getPaginate } from "./utils/getPaginate";
|
|
23
|
-
export { isMulti } from "./utils/isMulti";
|
|
24
|
-
export { isPaginated } from "./utils/isPaginated";
|
|
25
|
-
export { mergeQuery } from "./utils/mergeQuery/index";
|
|
26
|
-
export { mergeArrays } from "./utils/mergeQuery/mergeArrays";
|
|
27
|
-
export { pushSet } from "./utils/pushSet";
|
|
28
|
-
export { setResultEmpty } from "./utils/setResultEmpty";
|
|
29
|
-
export { markHookForSkip } from "./utils/markHookForSkip";
|
|
30
|
-
export { filterQuery } from "./utils/filterQuery";
|
|
31
|
-
export { getItemsIsArray } from "./utils/getItemsIsArray";
|
|
32
|
-
export { onDelete } from "./hooks/onDelete";
|
|
33
|
-
export { shouldSkip } from "./utils/shouldSkip";
|
|
34
|
-
export { validateQueryProperty } from "./utils/validateQueryProperty";
|
|
1
|
+
export * from "./hooks/checkMulti";
|
|
2
|
+
export * from "./hooks/createRelated";
|
|
3
|
+
export * from "./hooks/onDelete";
|
|
4
|
+
export * from "./hooks/removeRelated";
|
|
5
|
+
export * from "./hooks/runPerItem";
|
|
6
|
+
export * from "./hooks/setData";
|
|
7
|
+
export * from "./mixins/debounce-mixin";
|
|
8
|
+
export * from "./utils/isMulti";
|
|
9
|
+
export * from "./utils/getPaginate";
|
|
10
|
+
export * from "./utils/isPaginated";
|
|
11
|
+
export * from "./utils/mergeQuery";
|
|
12
|
+
export * from "./utils/pushSet";
|
|
13
|
+
export * from "./utils/setResultEmpty";
|
|
14
|
+
export * from "./utils/filterQuery";
|
|
15
|
+
export * from "./utils/getItemsIsArray";
|
|
16
|
+
export * from "./utils/shouldSkip";
|
|
17
|
+
export * from "./utils/markHookForSkip";
|
|
18
|
+
export * from "./utils/validateQueryProperty";
|
|
35
19
|
export { filterArray } from "./filters/array";
|
|
20
|
+
export { filterObject } from "./filters/object";
|
|
36
21
|
export * from "./types";
|
package/dist/esm/index.js
CHANGED
|
@@ -1,37 +1,25 @@
|
|
|
1
1
|
// hooks
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export
|
|
21
|
-
export
|
|
22
|
-
export { getPaginate } from "./utils/getPaginate";
|
|
23
|
-
export { isMulti } from "./utils/isMulti";
|
|
24
|
-
export { isPaginated } from "./utils/isPaginated";
|
|
25
|
-
export { mergeQuery } from "./utils/mergeQuery/index";
|
|
26
|
-
export { mergeArrays } from "./utils/mergeQuery/mergeArrays";
|
|
27
|
-
export { pushSet } from "./utils/pushSet";
|
|
28
|
-
export { setResultEmpty } from "./utils/setResultEmpty";
|
|
29
|
-
export { markHookForSkip } from "./utils/markHookForSkip";
|
|
30
|
-
export { filterQuery } from "./utils/filterQuery";
|
|
31
|
-
export { getItemsIsArray } from "./utils/getItemsIsArray";
|
|
32
|
-
export { onDelete } from "./hooks/onDelete";
|
|
33
|
-
export { shouldSkip } from "./utils/shouldSkip";
|
|
34
|
-
export { validateQueryProperty } from "./utils/validateQueryProperty";
|
|
2
|
+
export * from "./hooks/checkMulti";
|
|
3
|
+
export * from "./hooks/createRelated";
|
|
4
|
+
export * from "./hooks/onDelete";
|
|
5
|
+
export * from "./hooks/removeRelated";
|
|
6
|
+
export * from "./hooks/runPerItem";
|
|
7
|
+
export * from "./hooks/setData";
|
|
8
|
+
// mixins
|
|
9
|
+
export * from "./mixins/debounce-mixin";
|
|
10
|
+
// utils
|
|
11
|
+
export * from "./utils/isMulti";
|
|
12
|
+
export * from "./utils/getPaginate";
|
|
13
|
+
export * from "./utils/isPaginated";
|
|
14
|
+
export * from "./utils/mergeQuery";
|
|
15
|
+
export * from "./utils/pushSet";
|
|
16
|
+
export * from "./utils/setResultEmpty";
|
|
17
|
+
export * from "./utils/filterQuery";
|
|
18
|
+
export * from "./utils/getItemsIsArray";
|
|
19
|
+
export * from "./utils/shouldSkip";
|
|
20
|
+
export * from "./utils/markHookForSkip";
|
|
21
|
+
export * from "./utils/validateQueryProperty";
|
|
35
22
|
// query filters
|
|
36
23
|
export { filterArray } from "./filters/array";
|
|
24
|
+
export { filterObject } from "./filters/object";
|
|
37
25
|
export * from "./types";
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { DebouncedFunc } from "lodash";
|
|
2
2
|
import type { Application, Id } from "@feathersjs/feathers";
|
|
3
|
-
import type { DebouncedFunctionApp, DebouncedStoreOptions } from "
|
|
3
|
+
import type { DebouncedFunctionApp, DebouncedStoreOptions } from "./types";
|
|
4
4
|
export declare const makeDefaultOptions: () => DebouncedStoreOptions;
|
|
5
|
+
export declare type DebouncedService<T = any> = T & {
|
|
6
|
+
debouncedStore: DebouncedStore;
|
|
7
|
+
};
|
|
5
8
|
export declare class DebouncedStore {
|
|
6
9
|
private _app;
|
|
7
10
|
private _options;
|
|
8
11
|
private _isRunningById;
|
|
9
|
-
_queueById: Record<string, DebouncedFunc<(
|
|
12
|
+
_queueById: Record<string, DebouncedFunc<(id: Id, action: DebouncedFunctionApp) => void | Promise<void>>>;
|
|
10
13
|
add: (id: Id, action: (app?: Application) => void | Promise<void>) => void | Promise<void> | undefined;
|
|
11
14
|
constructor(app: Application, options?: Partial<DebouncedStoreOptions>);
|
|
12
15
|
private unbounced;
|
|
@@ -4,7 +4,7 @@ export const makeDefaultOptions = () => {
|
|
|
4
4
|
leading: false,
|
|
5
5
|
maxWait: undefined,
|
|
6
6
|
trailing: true,
|
|
7
|
-
wait: 100
|
|
7
|
+
wait: 100,
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
10
|
export class DebouncedStore {
|
|
@@ -17,7 +17,7 @@ export class DebouncedStore {
|
|
|
17
17
|
this.add = this.debounceById(this.unbounced, this._options.wait, {
|
|
18
18
|
leading: this._options.leading,
|
|
19
19
|
maxWait: this._options.maxWait,
|
|
20
|
-
trailing: this._options.trailing
|
|
20
|
+
trailing: this._options.trailing,
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
async unbounced(id, action) {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DebouncedStore, makeDefaultOptions } from "./DebouncedStore";
|
|
2
|
+
export function debounceMixin(options) {
|
|
3
|
+
return (app) => {
|
|
4
|
+
options = options || {};
|
|
5
|
+
const defaultOptions = Object.assign(makeDefaultOptions(), options?.default);
|
|
6
|
+
app.mixins.push((service, path) => {
|
|
7
|
+
// if path is on blacklist, don't add debouncedStore to service
|
|
8
|
+
if (options?.blacklist && options.blacklist.includes(path))
|
|
9
|
+
return;
|
|
10
|
+
// if service already has registered something on `debouncedStore`
|
|
11
|
+
if (service.debouncedStore) {
|
|
12
|
+
console.warn(`[feathers-utils] service: '${path}' already has a property 'debouncedStore'. Mixin will skip creating a new debouncedStore`);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const serviceOptions = Object.assign({}, defaultOptions, options?.[path]);
|
|
16
|
+
service.debouncedStore = new DebouncedStore(app, serviceOptions);
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare type DebouncedService = FeathersService & {
|
|
5
|
-
debouncedStore: DebouncedStore;
|
|
6
|
-
};
|
|
7
|
-
export declare function debounceMixin(options?: Partial<InitDebounceMixinOptions>): ((app: Application) => void);
|
|
8
|
-
export { DebouncedStore };
|
|
1
|
+
export * from "./types";
|
|
2
|
+
export * from "./DebouncedStore";
|
|
3
|
+
export * from "./debounceMixin";
|
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
options = options || {};
|
|
5
|
-
const defaultOptions = Object.assign(makeDefaultOptions(), options?.default);
|
|
6
|
-
app.mixins.push((service, path) => {
|
|
7
|
-
// if path is on blacklist, don't add debouncedStore to service
|
|
8
|
-
if (options?.blacklist && options.blacklist.includes(path))
|
|
9
|
-
return;
|
|
10
|
-
// if service already has registered something on `debouncedStore`
|
|
11
|
-
if (service.debouncedStore) {
|
|
12
|
-
console.warn(`[feathers-utils] service: '${path}' already has a property 'debouncedStore'. Mixin will skip creating a new debouncedStore`);
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
const serviceOptions = Object.assign({}, defaultOptions, options?.[path]);
|
|
16
|
-
service.debouncedStore = new DebouncedStore(app, serviceOptions);
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
export { DebouncedStore };
|
|
1
|
+
export * from "./types";
|
|
2
|
+
export * from "./DebouncedStore";
|
|
3
|
+
export * from "./debounceMixin";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Application } from "@feathersjs/feathers";
|
|
2
|
+
export interface InitDebounceMixinOptions {
|
|
3
|
+
default: Partial<DebouncedStoreOptions>;
|
|
4
|
+
blacklist: string[];
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
export declare type DebouncedFunctionApp = (app?: Application) => void | Promise<void>;
|
|
8
|
+
export interface DebouncedStoreOptions {
|
|
9
|
+
leading: boolean;
|
|
10
|
+
maxWait: number | undefined;
|
|
11
|
+
trailing: boolean;
|
|
12
|
+
wait: number;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,79 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { AdapterBase, FilterQueryOptions as PlainFilterQueryOptions } from "@feathersjs/adapter-commons";
|
|
3
|
-
export declare type Path = Array<string | number>;
|
|
4
|
-
export declare type MaybeArray<T> = T | T[];
|
|
5
|
-
export declare type Promisable<T> = T | Promise<T>;
|
|
6
|
-
export declare type HookType = "before" | "after" | "error";
|
|
7
|
-
export declare type ServiceMethodName = "find" | "get" | "create" | "update" | "patch" | "remove";
|
|
8
|
-
export declare type ReturnSyncHook = (context: HookContext) => HookContext;
|
|
9
|
-
export declare type ReturnAsyncHook = (context: HookContext) => Promise<HookContext>;
|
|
10
|
-
export declare type Handle = "target" | "source" | "combine" | "intersect" | "intersectOrFull";
|
|
11
|
-
export declare type FirstLast = "first" | "last";
|
|
1
|
+
import type { HookContext } from "@feathersjs/feathers";
|
|
12
2
|
export declare type Predicate<T = any> = (item: T) => boolean;
|
|
13
3
|
export declare type PredicateWithContext<T = any> = (item: T, context: HookContext) => boolean;
|
|
14
|
-
export interface HookSetDataOptions {
|
|
15
|
-
allowUndefined?: boolean;
|
|
16
|
-
overwrite?: boolean | PredicateWithContext;
|
|
17
|
-
}
|
|
18
|
-
export interface AddHookOptions {
|
|
19
|
-
types: HookType[];
|
|
20
|
-
methods: ServiceMethodName[];
|
|
21
|
-
orderByType: Record<HookType, FirstLast>;
|
|
22
|
-
whitelist?: string[];
|
|
23
|
-
blacklist?: string[];
|
|
24
|
-
}
|
|
25
|
-
export interface HookRunPerItemOptions {
|
|
26
|
-
wait?: boolean;
|
|
27
|
-
}
|
|
28
|
-
export interface RemoveRelatedOptions<S = Record<string, any>> {
|
|
29
|
-
service: keyof S;
|
|
30
|
-
keyThere: string;
|
|
31
|
-
keyHere: string;
|
|
32
|
-
blocking?: boolean;
|
|
33
|
-
}
|
|
34
|
-
export interface CreateRelatedOptions<S = Record<string, any>> {
|
|
35
|
-
service: keyof S;
|
|
36
|
-
multi?: boolean;
|
|
37
|
-
data: (item: any, context: HookContext) => Promisable<Record<string, any>>;
|
|
38
|
-
createItemsInDataArraySeparately?: boolean;
|
|
39
|
-
}
|
|
40
|
-
export declare type OnDeleteAction = "cascade" | "set null";
|
|
41
|
-
export interface OnDeleteOptions {
|
|
42
|
-
keyThere: string;
|
|
43
|
-
keyHere: string;
|
|
44
|
-
onDelete: OnDeleteAction;
|
|
45
|
-
blocking?: boolean;
|
|
46
|
-
}
|
|
47
|
-
export interface InitDebounceMixinOptions {
|
|
48
|
-
default: Partial<DebouncedStoreOptions>;
|
|
49
|
-
blacklist: string[];
|
|
50
|
-
[key: string]: unknown;
|
|
51
|
-
}
|
|
52
|
-
export declare type DebouncedFunctionApp = (app?: Application) => void | Promise<void>;
|
|
53
|
-
export interface DebouncedStoreOptions {
|
|
54
|
-
leading: boolean;
|
|
55
|
-
maxWait: number | undefined;
|
|
56
|
-
trailing: boolean;
|
|
57
|
-
wait: number;
|
|
58
|
-
}
|
|
59
|
-
export interface PushSetOptions {
|
|
60
|
-
unique?: boolean;
|
|
61
|
-
}
|
|
62
|
-
export declare type ActionOnEmptyIntersect = (target: unknown, source: unknown, prependKey: Path) => void;
|
|
63
|
-
export interface MergeQueryOptions<T> extends FilterQueryOptions<T> {
|
|
64
|
-
defaultHandle: Handle;
|
|
65
|
-
actionOnEmptyIntersect: ActionOnEmptyIntersect;
|
|
66
|
-
useLogicalConjunction: boolean;
|
|
67
|
-
handle?: {
|
|
68
|
-
[key: string]: Handle;
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
export interface FilterQueryOptions<T> {
|
|
72
|
-
service?: AdapterBase<T>;
|
|
73
|
-
operators?: PlainFilterQueryOptions["operators"];
|
|
74
|
-
filters?: PlainFilterQueryOptions["filters"];
|
|
75
|
-
}
|
|
76
|
-
export interface GetItemsIsArrayOptions<T = any> {
|
|
77
|
-
items: T[];
|
|
78
|
-
isArray: boolean;
|
|
79
|
-
}
|
package/dist/esm/types.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import type { FilterQueryOptions as PlainFilterQueryOptions, AdapterBase } from "@feathersjs/adapter-commons";
|
|
1
2
|
import type { Query } from "@feathersjs/feathers";
|
|
2
|
-
|
|
3
|
+
export interface FilterQueryOptions<T> {
|
|
4
|
+
service?: AdapterBase<T>;
|
|
5
|
+
operators?: PlainFilterQueryOptions["operators"];
|
|
6
|
+
filters?: PlainFilterQueryOptions["filters"];
|
|
7
|
+
}
|
|
3
8
|
export declare function filterQuery<T>(query: Query, _options?: FilterQueryOptions<T>): any;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { filterQuery as plainFilterQuery
|
|
1
|
+
import { filterQuery as plainFilterQuery } from "@feathersjs/adapter-commons";
|
|
2
2
|
export function filterQuery(query, _options) {
|
|
3
3
|
query = query || {};
|
|
4
4
|
_options = _options || {};
|
|
@@ -17,8 +17,10 @@ export function filterQuery(query, _options) {
|
|
|
17
17
|
if (filters) {
|
|
18
18
|
optionsForFilterQuery.filters = filters;
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
if (service &&
|
|
21
|
+
"filterQuery" in service &&
|
|
22
|
+
// @ts-expect-error service is of type 'never'
|
|
23
|
+
typeof service.filterQuery === "function") {
|
|
22
24
|
// @ts-expect-error service has no filterQuery method
|
|
23
25
|
return service.filterQuery({ query }, optionsForFilterQuery);
|
|
24
26
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import type { HookContext } from "@feathersjs/feathers";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
export interface GetItemsIsArrayOptions<T = any> {
|
|
3
|
+
items: T[];
|
|
4
|
+
isArray: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare const getItemsIsArray: <T = any, H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any> = HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(context: H) => GetItemsIsArrayOptions<T>;
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2
2
|
export const getItemsIsArray = (context) => {
|
|
3
|
-
let itemOrItems = context.type === "before"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
: itemOrItems;
|
|
3
|
+
let itemOrItems = context.type === "before" ? context.data : context.result;
|
|
4
|
+
itemOrItems =
|
|
5
|
+
itemOrItems && context.method === "find"
|
|
6
|
+
? itemOrItems.data || itemOrItems
|
|
7
|
+
: itemOrItems;
|
|
9
8
|
const isArray = Array.isArray(itemOrItems);
|
|
10
9
|
return {
|
|
11
|
-
items:
|
|
12
|
-
|
|
13
|
-
: (itemOrItems != null)
|
|
14
|
-
? [itemOrItems]
|
|
15
|
-
: [],
|
|
16
|
-
isArray
|
|
10
|
+
items: isArray ? itemOrItems : itemOrItems != null ? [itemOrItems] : [],
|
|
11
|
+
isArray,
|
|
17
12
|
};
|
|
18
13
|
};
|