feathers-utils 1.9.1 → 1.9.2
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/hooks/checkMulti.d.ts +2 -2
- package/dist/esm/hooks/runPerItem.d.ts +2 -3
- package/dist/esm/hooks/runPerItem.js +2 -3
- package/dist/esm/hooks/setData.d.ts +2 -3
- package/dist/esm/hooks/setData.js +2 -3
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/types.d.ts +4 -0
- package/dist/esm/utils/markHookForSkip.d.ts +2 -2
- package/dist/hooks/checkMulti.d.ts +2 -2
- package/dist/hooks/runPerItem.d.ts +2 -3
- package/dist/hooks/runPerItem.js +2 -3
- package/dist/hooks/setData.d.ts +2 -3
- package/dist/hooks/setData.js +2 -3
- package/dist/index.d.ts +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/utils/markHookForSkip.d.ts +2 -2
- package/package.json +2 -4
- package/src/hooks/checkMulti.ts +3 -1
- package/src/hooks/runPerItem.ts +4 -8
- package/src/hooks/setData.ts +6 -7
- package/src/mixins/debounce-mixin/index.ts +3 -1
- package/src/types.ts +5 -0
- package/src/utils/addHook.ts +5 -1
- package/src/utils/isMulti.ts +3 -1
- package/src/utils/markHookForSkip.ts +2 -2
- package/src/utils/shouldSkip.ts +4 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function checkMulti():
|
|
1
|
+
import type { ReturnSyncHook } from "../types";
|
|
2
|
+
export declare function checkMulti(): ReturnSyncHook;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { HookRunPerItemOptions } from "../types";
|
|
1
|
+
import type { HookRunPerItemOptions, ReturnAsyncHook, Promisable } from "../types";
|
|
2
2
|
import type { HookContext } from "@feathersjs/feathers";
|
|
3
|
-
|
|
4
|
-
export declare const runPerItem: (actionPerItem: (item: any, context: HookContext) => Promisable<any>, options: HookRunPerItemOptions) => (context: HookContext) => Promise<HookContext>;
|
|
3
|
+
export declare const runPerItem: (actionPerItem: (item: any, context: HookContext) => Promisable<any>, options: HookRunPerItemOptions) => ReturnAsyncHook;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getItems } from "feathers-hooks-common";
|
|
2
1
|
import { shouldSkip } from "../utils/shouldSkip";
|
|
2
|
+
import { getItemsIsArray } from "../utils/getItemsIsArray";
|
|
3
3
|
const makeOptions = (options) => {
|
|
4
4
|
options = options || {};
|
|
5
5
|
return Object.assign({
|
|
@@ -14,8 +14,7 @@ actionPerItem, options) => {
|
|
|
14
14
|
if (shouldSkip("runForItems", context)) {
|
|
15
15
|
return context;
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
items = (Array.isArray(items)) ? items : [items];
|
|
17
|
+
const { items } = getItemsIsArray(context);
|
|
19
18
|
const promises = items.map(async (item) => {
|
|
20
19
|
await actionPerItem(item, context);
|
|
21
20
|
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { HookContext } from "@feathersjs/feathers";
|
|
2
|
-
import type { HookSetDataOptions } from "../types";
|
|
3
1
|
import type { PropertyPath } from "lodash";
|
|
4
|
-
|
|
2
|
+
import type { HookSetDataOptions, ReturnSyncHook } from "../types";
|
|
3
|
+
export declare function setData(from: PropertyPath, to: PropertyPath, _options?: HookSetDataOptions): ReturnSyncHook;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import _get from "lodash/get";
|
|
2
2
|
import _set from "lodash/set";
|
|
3
3
|
import _has from "lodash/has";
|
|
4
|
-
import { getItems } from "feathers-hooks-common";
|
|
5
4
|
import { Forbidden } from "@feathersjs/errors";
|
|
5
|
+
import { getItemsIsArray } from "../utils/getItemsIsArray";
|
|
6
6
|
const defaultOptions = {
|
|
7
7
|
allowUndefined: false,
|
|
8
8
|
overwrite: true
|
|
@@ -10,8 +10,7 @@ const defaultOptions = {
|
|
|
10
10
|
export function setData(from, to, _options) {
|
|
11
11
|
const options = Object.assign({}, defaultOptions, _options);
|
|
12
12
|
return (context) => {
|
|
13
|
-
|
|
14
|
-
items = (Array.isArray(items)) ? items : [items];
|
|
13
|
+
const { items } = getItemsIsArray(context);
|
|
15
14
|
if (!_has(context, from)) {
|
|
16
15
|
if (!context.params?.provider || options.allowUndefined === true) {
|
|
17
16
|
return context;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { runPerItem } from "./hooks/runPerItem";
|
|
|
4
4
|
export declare const hooks: {
|
|
5
5
|
checkMulti: typeof checkMulti;
|
|
6
6
|
setData: typeof setData;
|
|
7
|
-
runPerItem: (actionPerItem: (item: any, context: import("@feathersjs/feathers").HookContext<any, import("@feathersjs/feathers").Service<any>>) => any, options: import("./types").HookRunPerItemOptions) =>
|
|
7
|
+
runPerItem: (actionPerItem: (item: any, context: import("@feathersjs/feathers").HookContext<any, import("@feathersjs/feathers").Service<any>>) => any, options: import("./types").HookRunPerItemOptions) => import("./types").ReturnAsyncHook;
|
|
8
8
|
};
|
|
9
9
|
export { checkMulti };
|
|
10
10
|
export { setData };
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { Application, HookContext, Service } from "@feathersjs/feathers";
|
|
2
2
|
export declare type Path = Array<string | number>;
|
|
3
|
+
export declare type MaybeArray<T> = T | T[];
|
|
4
|
+
export declare type Promisable<T> = T | Promise<T>;
|
|
3
5
|
export declare type HookType = "before" | "after" | "error";
|
|
4
6
|
export declare type ServiceMethodName = "find" | "get" | "create" | "update" | "patch" | "remove";
|
|
7
|
+
export declare type ReturnSyncHook = (context: HookContext) => HookContext;
|
|
8
|
+
export declare type ReturnAsyncHook = (context: HookContext) => Promise<HookContext>;
|
|
5
9
|
export declare type Handle = "target" | "source" | "combine" | "intersect" | "intersectOrFull";
|
|
6
10
|
export declare type FirstLast = "first" | "last";
|
|
7
11
|
export declare type Predicate<T = any> = (item: T) => boolean;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { HookContext } from "@feathersjs/feathers";
|
|
2
|
-
import type { HookType } from "
|
|
3
|
-
export declare function markHookForSkip<T>(hookName: string, type: "all" | HookType
|
|
2
|
+
import type { HookType, MaybeArray } from "../types";
|
|
3
|
+
export declare function markHookForSkip<T>(hookName: string, type: "all" | MaybeArray<HookType>, context?: Partial<HookContext<T>>): Partial<HookContext<T>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function checkMulti():
|
|
1
|
+
import type { ReturnSyncHook } from "../types";
|
|
2
|
+
export declare function checkMulti(): ReturnSyncHook;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { HookRunPerItemOptions } from "../types";
|
|
1
|
+
import type { HookRunPerItemOptions, ReturnAsyncHook, Promisable } from "../types";
|
|
2
2
|
import type { HookContext } from "@feathersjs/feathers";
|
|
3
|
-
|
|
4
|
-
export declare const runPerItem: (actionPerItem: (item: any, context: HookContext) => Promisable<any>, options: HookRunPerItemOptions) => (context: HookContext) => Promise<HookContext>;
|
|
3
|
+
export declare const runPerItem: (actionPerItem: (item: any, context: HookContext) => Promisable<any>, options: HookRunPerItemOptions) => ReturnAsyncHook;
|
package/dist/hooks/runPerItem.js
CHANGED
|
@@ -10,8 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.runPerItem = void 0;
|
|
13
|
-
const feathers_hooks_common_1 = require("feathers-hooks-common");
|
|
14
13
|
const shouldSkip_1 = require("../utils/shouldSkip");
|
|
14
|
+
const getItemsIsArray_1 = require("../utils/getItemsIsArray");
|
|
15
15
|
const makeOptions = (options) => {
|
|
16
16
|
options = options || {};
|
|
17
17
|
return Object.assign({
|
|
@@ -26,8 +26,7 @@ actionPerItem, options) => {
|
|
|
26
26
|
if ((0, shouldSkip_1.shouldSkip)("runForItems", context)) {
|
|
27
27
|
return context;
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
items = (Array.isArray(items)) ? items : [items];
|
|
29
|
+
const { items } = (0, getItemsIsArray_1.getItemsIsArray)(context);
|
|
31
30
|
const promises = items.map((item) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
31
|
yield actionPerItem(item, context);
|
|
33
32
|
}));
|
package/dist/hooks/setData.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { HookContext } from "@feathersjs/feathers";
|
|
2
|
-
import type { HookSetDataOptions } from "../types";
|
|
3
1
|
import type { PropertyPath } from "lodash";
|
|
4
|
-
|
|
2
|
+
import type { HookSetDataOptions, ReturnSyncHook } from "../types";
|
|
3
|
+
export declare function setData(from: PropertyPath, to: PropertyPath, _options?: HookSetDataOptions): ReturnSyncHook;
|
package/dist/hooks/setData.js
CHANGED
|
@@ -7,8 +7,8 @@ exports.setData = void 0;
|
|
|
7
7
|
const get_1 = __importDefault(require("lodash/get"));
|
|
8
8
|
const set_1 = __importDefault(require("lodash/set"));
|
|
9
9
|
const has_1 = __importDefault(require("lodash/has"));
|
|
10
|
-
const feathers_hooks_common_1 = require("feathers-hooks-common");
|
|
11
10
|
const errors_1 = require("@feathersjs/errors");
|
|
11
|
+
const getItemsIsArray_1 = require("../utils/getItemsIsArray");
|
|
12
12
|
const defaultOptions = {
|
|
13
13
|
allowUndefined: false,
|
|
14
14
|
overwrite: true
|
|
@@ -17,8 +17,7 @@ function setData(from, to, _options) {
|
|
|
17
17
|
const options = Object.assign({}, defaultOptions, _options);
|
|
18
18
|
return (context) => {
|
|
19
19
|
var _a;
|
|
20
|
-
|
|
21
|
-
items = (Array.isArray(items)) ? items : [items];
|
|
20
|
+
const { items } = (0, getItemsIsArray_1.getItemsIsArray)(context);
|
|
22
21
|
if (!(0, has_1.default)(context, from)) {
|
|
23
22
|
if (!((_a = context.params) === null || _a === void 0 ? void 0 : _a.provider) || options.allowUndefined === true) {
|
|
24
23
|
return context;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { runPerItem } from "./hooks/runPerItem";
|
|
|
4
4
|
export declare const hooks: {
|
|
5
5
|
checkMulti: typeof checkMulti;
|
|
6
6
|
setData: typeof setData;
|
|
7
|
-
runPerItem: (actionPerItem: (item: any, context: import("@feathersjs/feathers").HookContext<any, import("@feathersjs/feathers").Service<any>>) => any, options: import("./types").HookRunPerItemOptions) =>
|
|
7
|
+
runPerItem: (actionPerItem: (item: any, context: import("@feathersjs/feathers").HookContext<any, import("@feathersjs/feathers").Service<any>>) => any, options: import("./types").HookRunPerItemOptions) => import("./types").ReturnAsyncHook;
|
|
8
8
|
};
|
|
9
9
|
export { checkMulti };
|
|
10
10
|
export { setData };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { Application, HookContext, Service } from "@feathersjs/feathers";
|
|
2
2
|
export declare type Path = Array<string | number>;
|
|
3
|
+
export declare type MaybeArray<T> = T | T[];
|
|
4
|
+
export declare type Promisable<T> = T | Promise<T>;
|
|
3
5
|
export declare type HookType = "before" | "after" | "error";
|
|
4
6
|
export declare type ServiceMethodName = "find" | "get" | "create" | "update" | "patch" | "remove";
|
|
7
|
+
export declare type ReturnSyncHook = (context: HookContext) => HookContext;
|
|
8
|
+
export declare type ReturnAsyncHook = (context: HookContext) => Promise<HookContext>;
|
|
5
9
|
export declare type Handle = "target" | "source" | "combine" | "intersect" | "intersectOrFull";
|
|
6
10
|
export declare type FirstLast = "first" | "last";
|
|
7
11
|
export declare type Predicate<T = any> = (item: T) => boolean;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { HookContext } from "@feathersjs/feathers";
|
|
2
|
-
import type { HookType } from "
|
|
3
|
-
export declare function markHookForSkip<T>(hookName: string, type: "all" | HookType
|
|
2
|
+
import type { HookType, MaybeArray } from "../types";
|
|
3
|
+
export declare function markHookForSkip<T>(hookName: string, type: "all" | MaybeArray<HookType>, context?: Partial<HookContext<T>>): Partial<HookContext<T>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "feathers-utils",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.2",
|
|
4
4
|
"description": "Some utils for projects using '@feathersjs/feathers'",
|
|
5
5
|
"author": "fratzinger",
|
|
6
6
|
"repository": {
|
|
@@ -42,9 +42,7 @@
|
|
|
42
42
|
"@feathersjs/adapter-commons": "^4.5.12",
|
|
43
43
|
"@feathersjs/errors": "^4.5.12",
|
|
44
44
|
"@feathersjs/feathers": "^4.5.12",
|
|
45
|
-
"
|
|
46
|
-
"lodash": "^4.17.21",
|
|
47
|
-
"type-fest": "^2.11.1"
|
|
45
|
+
"lodash": "^4.17.21"
|
|
48
46
|
},
|
|
49
47
|
"devDependencies": {
|
|
50
48
|
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
package/src/hooks/checkMulti.ts
CHANGED
|
@@ -3,8 +3,10 @@ import { shouldSkip } from "../utils/shouldSkip";
|
|
|
3
3
|
import { isMulti } from "../utils/isMulti";
|
|
4
4
|
|
|
5
5
|
import type { HookContext } from "@feathersjs/feathers";
|
|
6
|
+
import type { ReturnSyncHook } from "../types";
|
|
6
7
|
|
|
7
|
-
export function checkMulti(
|
|
8
|
+
export function checkMulti(
|
|
9
|
+
): ReturnSyncHook {
|
|
8
10
|
return (context: HookContext): HookContext => {
|
|
9
11
|
if (shouldSkip("checkMulti", context)) { return context; }
|
|
10
12
|
const { service, method } = context;
|
package/src/hooks/runPerItem.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { getItems } from "feathers-hooks-common";
|
|
2
|
-
|
|
3
1
|
import { shouldSkip } from "../utils/shouldSkip";
|
|
4
2
|
|
|
5
|
-
import type { HookRunPerItemOptions } from "../types";
|
|
3
|
+
import type { HookRunPerItemOptions, ReturnAsyncHook, Promisable } from "../types";
|
|
6
4
|
import type { HookContext } from "@feathersjs/feathers";
|
|
7
|
-
import
|
|
5
|
+
import { getItemsIsArray } from "../utils/getItemsIsArray";
|
|
8
6
|
|
|
9
7
|
const makeOptions = (
|
|
10
8
|
options: HookRunPerItemOptions
|
|
@@ -19,13 +17,11 @@ export const runPerItem = (
|
|
|
19
17
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
18
|
actionPerItem: (item: any, context: HookContext) => Promisable<any>,
|
|
21
19
|
options: HookRunPerItemOptions
|
|
22
|
-
):
|
|
20
|
+
): ReturnAsyncHook => {
|
|
23
21
|
options = makeOptions(options);
|
|
24
22
|
return async (context: HookContext): Promise<HookContext> => {
|
|
25
23
|
if (shouldSkip("runForItems", context)) { return context; }
|
|
26
|
-
|
|
27
|
-
items = (Array.isArray(items)) ? items : [items];
|
|
28
|
-
|
|
24
|
+
const { items } = getItemsIsArray(context);
|
|
29
25
|
const promises = items.map(async (item: unknown) => {
|
|
30
26
|
await actionPerItem(item, context);
|
|
31
27
|
});
|
package/src/hooks/setData.ts
CHANGED
|
@@ -2,16 +2,16 @@ import _get from "lodash/get";
|
|
|
2
2
|
import _set from "lodash/set";
|
|
3
3
|
import _has from "lodash/has";
|
|
4
4
|
|
|
5
|
-
import { getItems } from "feathers-hooks-common";
|
|
6
|
-
|
|
7
5
|
import { Forbidden } from "@feathersjs/errors";
|
|
6
|
+
import { getItemsIsArray } from "../utils/getItemsIsArray";
|
|
8
7
|
|
|
9
8
|
import type { HookContext } from "@feathersjs/feathers";
|
|
9
|
+
import type { PropertyPath } from "lodash";
|
|
10
10
|
|
|
11
11
|
import type {
|
|
12
|
-
HookSetDataOptions
|
|
12
|
+
HookSetDataOptions,
|
|
13
|
+
ReturnSyncHook
|
|
13
14
|
} from "../types";
|
|
14
|
-
import type { PropertyPath } from "lodash";
|
|
15
15
|
|
|
16
16
|
const defaultOptions: Required<HookSetDataOptions> = {
|
|
17
17
|
allowUndefined: false,
|
|
@@ -22,12 +22,11 @@ export function setData(
|
|
|
22
22
|
from: PropertyPath,
|
|
23
23
|
to: PropertyPath,
|
|
24
24
|
_options?: HookSetDataOptions
|
|
25
|
-
):
|
|
25
|
+
): ReturnSyncHook {
|
|
26
26
|
const options: Required<HookSetDataOptions> = Object.assign({}, defaultOptions, _options);
|
|
27
27
|
return (context: HookContext): HookContext => {
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
items = (Array.isArray(items)) ? items : [items];
|
|
29
|
+
const { items } = getItemsIsArray(context);
|
|
31
30
|
|
|
32
31
|
if (!_has(context, from)) {
|
|
33
32
|
if (!context.params?.provider || options.allowUndefined === true) {
|
|
@@ -10,7 +10,9 @@ import type {
|
|
|
10
10
|
DebouncedStoreOptions,
|
|
11
11
|
} from "../../types";
|
|
12
12
|
|
|
13
|
-
export function debounceMixin(
|
|
13
|
+
export function debounceMixin(
|
|
14
|
+
options?: Partial<InitDebounceMixinOptions>
|
|
15
|
+
): ((app: Application) => void) {
|
|
14
16
|
return (app: Application): void => {
|
|
15
17
|
options = options || {};
|
|
16
18
|
const defaultOptions = Object.assign(makeDefaultOptions(), options?.default);
|
package/src/types.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import type { Application, HookContext, Service } from "@feathersjs/feathers";
|
|
2
2
|
|
|
3
3
|
export type Path = Array<string|number>;
|
|
4
|
+
export type MaybeArray<T> = T | T[]
|
|
5
|
+
export type Promisable<T> = T | Promise<T>
|
|
6
|
+
|
|
4
7
|
export type HookType = "before" | "after" | "error";
|
|
5
8
|
export type ServiceMethodName = "find" | "get" | "create" | "update" | "patch" | "remove";
|
|
9
|
+
export type ReturnSyncHook = (context: HookContext) => HookContext
|
|
10
|
+
export type ReturnAsyncHook = (context: HookContext) => Promise<HookContext>
|
|
6
11
|
|
|
7
12
|
export type Handle = "target" | "source" | "combine" | "intersect"| "intersectOrFull";
|
|
8
13
|
export type FirstLast = "first" | "last";
|
package/src/utils/addHook.ts
CHANGED
|
@@ -8,7 +8,11 @@ const defaultOptions = (): Partial<AddHookOptions> => {
|
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
export const addHook = (
|
|
11
|
+
export const addHook = (
|
|
12
|
+
app: Application,
|
|
13
|
+
hook: unknown,
|
|
14
|
+
options: AddHookOptions
|
|
15
|
+
): void => {
|
|
12
16
|
options = Object.assign(defaultOptions(), options);
|
|
13
17
|
|
|
14
18
|
const {
|
package/src/utils/isMulti.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { pushSet } from "./pushSet";
|
|
2
2
|
|
|
3
3
|
import type { HookContext } from "@feathersjs/feathers";
|
|
4
|
-
import type { HookType } from "
|
|
4
|
+
import type { HookType, MaybeArray } from "../types";
|
|
5
5
|
|
|
6
6
|
export function markHookForSkip<T>(
|
|
7
7
|
hookName: string,
|
|
8
|
-
type: "all" | HookType
|
|
8
|
+
type: "all" | MaybeArray<HookType>,
|
|
9
9
|
context?: Partial<HookContext<T>>
|
|
10
10
|
): Partial<HookContext<T>> {
|
|
11
11
|
context = context || {};
|
package/src/utils/shouldSkip.ts
CHANGED
|
@@ -5,7 +5,10 @@ import { GeneralError } from "@feathersjs/errors";
|
|
|
5
5
|
|
|
6
6
|
import type { HookContext } from "@feathersjs/feathers";
|
|
7
7
|
|
|
8
|
-
export const shouldSkip = (
|
|
8
|
+
export const shouldSkip = (
|
|
9
|
+
hookName: string,
|
|
10
|
+
context: HookContext
|
|
11
|
+
): boolean => {
|
|
9
12
|
if (!context.params || !context.params.skipHooks) {
|
|
10
13
|
return false;
|
|
11
14
|
}
|