feathers-utils 1.7.2 → 2.0.0-0
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/runPerItem.js +1 -0
- package/dist/esm/hooks/setData.js +1 -0
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.js +0 -1
- package/dist/esm/mixins/debounce-mixin/DebouncedStore.d.ts +1 -1
- package/dist/esm/mixins/debounce-mixin/index.d.ts +4 -1
- package/dist/esm/types.d.ts +3 -2
- package/dist/esm/utils/getPaginate.d.ts +6 -1
- package/dist/hooks/checkMulti.js +2 -2
- package/dist/hooks/runPerItem.js +3 -2
- package/dist/hooks/setData.js +7 -6
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -3
- package/dist/mixins/debounce-mixin/DebouncedStore.d.ts +1 -1
- package/dist/mixins/debounce-mixin/DebouncedStore.js +2 -2
- package/dist/mixins/debounce-mixin/index.d.ts +4 -1
- package/dist/mixins/debounce-mixin/index.js +1 -1
- package/dist/types.d.ts +3 -2
- package/dist/utils/filterQuery.js +2 -2
- package/dist/utils/getPaginate.d.ts +6 -1
- package/dist/utils/isPaginated.js +1 -1
- package/dist/utils/markHookForSkip.js +1 -1
- package/dist/utils/mergeQuery/index.js +38 -38
- package/dist/utils/pushSet.js +3 -3
- package/dist/utils/setResultEmpty.js +2 -2
- package/package.json +5 -5
- package/src/hooks/runPerItem.ts +2 -0
- package/src/hooks/setData.ts +1 -0
- package/src/index.ts +3 -3
- package/src/mixins/debounce-mixin/index.ts +7 -3
- package/src/types.ts +4 -3
- package/src/utils/filterQuery.ts +2 -2
- package/src/utils/getPaginate.ts +10 -2
- package/dist/esm/utils/addHook.d.ts +0 -3
- package/dist/esm/utils/addHook.js +0 -36
- package/dist/utils/addHook.d.ts +0 -3
- package/dist/utils/addHook.js +0 -40
- package/src/utils/addHook.ts +0 -49
|
@@ -12,6 +12,7 @@ export const runPerItem = (actionPerItem, options) => {
|
|
|
12
12
|
if (shouldSkip("runForItems", context)) {
|
|
13
13
|
return context;
|
|
14
14
|
}
|
|
15
|
+
//@ts-expect-error type error because feathers-hooks-common is feathers@4
|
|
15
16
|
let items = getItems(context);
|
|
16
17
|
items = (Array.isArray(items)) ? items : [items];
|
|
17
18
|
const promises = items.map(async (item) => {
|
|
@@ -10,6 +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
|
+
//@ts-expect-error type error because feathers-hooks-common is feathers@4
|
|
13
14
|
let items = getItems(context);
|
|
14
15
|
items = (Array.isArray(items)) ? items : [items];
|
|
15
16
|
if (!_has(context, from)) {
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -4,19 +4,19 @@ 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<
|
|
7
|
+
runPerItem: (actionPerItem: (item: any, context: import("@feathersjs/feathers/lib").HookContext<import("@feathersjs/feathers/lib").Application<any, any>, any>) => any, options: import("./types").HookRunPerItemOptions) => (context: import("@feathersjs/feathers/lib").HookContext<import("@feathersjs/feathers/lib").Application<any, any>, any>) => Promise<import("@feathersjs/feathers/lib").HookContext<import("@feathersjs/feathers/lib").Application<any, any>, any>>;
|
|
8
8
|
};
|
|
9
9
|
export { checkMulti };
|
|
10
10
|
export { setData };
|
|
11
11
|
export { runPerItem };
|
|
12
|
-
import { debounceMixin, DebouncedStore } from "./mixins/debounce-mixin";
|
|
12
|
+
import { debounceMixin, DebouncedService, DebouncedStore } from "./mixins/debounce-mixin";
|
|
13
13
|
export declare const mixins: {
|
|
14
14
|
debounceMixin: typeof debounceMixin;
|
|
15
15
|
DebouncedStore: typeof DebouncedStore;
|
|
16
16
|
};
|
|
17
17
|
export { debounceMixin };
|
|
18
|
+
export { DebouncedService };
|
|
18
19
|
export { DebouncedStore };
|
|
19
|
-
export { addHook } from "./utils/addHook";
|
|
20
20
|
export { getPaginate } from "./utils/getPaginate";
|
|
21
21
|
export { isMulti } from "./utils/isMulti";
|
|
22
22
|
export { isPaginated } from "./utils/isPaginated";
|
package/dist/esm/index.js
CHANGED
|
@@ -17,7 +17,6 @@ export const mixins = {
|
|
|
17
17
|
};
|
|
18
18
|
export { debounceMixin };
|
|
19
19
|
export { DebouncedStore };
|
|
20
|
-
export { addHook } from "./utils/addHook";
|
|
21
20
|
export { getPaginate } from "./utils/getPaginate";
|
|
22
21
|
export { isMulti } from "./utils/isMulti";
|
|
23
22
|
export { isPaginated } from "./utils/isPaginated";
|
|
@@ -7,7 +7,7 @@ export declare class DebouncedStore {
|
|
|
7
7
|
private _options;
|
|
8
8
|
private _isRunningById;
|
|
9
9
|
_queueById: Record<string, DebouncedFunc<((id: Id, action: DebouncedFunctionApp) => void | Promise<void>)>>;
|
|
10
|
-
add: (id: Id, action: (app?: Application<
|
|
10
|
+
add: (id: Id, action: (app?: Application<any, any> | undefined) => void | Promise<void>) => void | Promise<void> | undefined;
|
|
11
11
|
constructor(app: Application, options?: Partial<DebouncedStoreOptions>);
|
|
12
12
|
private unbounced;
|
|
13
13
|
private debounceById;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { DebouncedStore } from "./DebouncedStore";
|
|
2
|
-
import type { Application } from "@feathersjs/feathers";
|
|
2
|
+
import type { Application, FeathersService } from "@feathersjs/feathers";
|
|
3
3
|
import type { InitDebounceMixinOptions } from "../../types";
|
|
4
|
+
export declare type DebouncedService = FeathersService & {
|
|
5
|
+
debouncedStore?: DebouncedStore;
|
|
6
|
+
};
|
|
4
7
|
export declare function debounceMixin(options?: Partial<InitDebounceMixinOptions>): ((app: Application) => void);
|
|
5
8
|
export { DebouncedStore };
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Application
|
|
1
|
+
import type { Application } from "@feathersjs/feathers";
|
|
2
|
+
import type { AdapterService } from "@feathersjs/adapter-commons";
|
|
2
3
|
export declare type Path = Array<string | number>;
|
|
3
4
|
export declare type HookType = "before" | "after" | "error";
|
|
4
5
|
export declare type ServiceMethodName = "find" | "get" | "create" | "update" | "patch" | "remove";
|
|
@@ -43,7 +44,7 @@ export interface MergeQueryOptions<T> extends FilterQueryOptions<T> {
|
|
|
43
44
|
};
|
|
44
45
|
}
|
|
45
46
|
export interface FilterQueryOptions<T> {
|
|
46
|
-
service?:
|
|
47
|
+
service?: AdapterService<T>;
|
|
47
48
|
operators?: string[];
|
|
48
49
|
filters?: string[];
|
|
49
50
|
}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import { HookContext
|
|
1
|
+
import { HookContext } from "@feathersjs/feathers";
|
|
2
|
+
interface PaginationOptions {
|
|
3
|
+
default: number;
|
|
4
|
+
max: number;
|
|
5
|
+
}
|
|
2
6
|
export declare const getPaginate: (context: HookContext) => PaginationOptions | undefined;
|
|
7
|
+
export {};
|
package/dist/hooks/checkMulti.js
CHANGED
|
@@ -6,11 +6,11 @@ const shouldSkip_1 = require("../utils/shouldSkip");
|
|
|
6
6
|
const isMulti_1 = require("../utils/isMulti");
|
|
7
7
|
function checkMulti() {
|
|
8
8
|
return (context) => {
|
|
9
|
-
if (shouldSkip_1.shouldSkip("checkMulti", context)) {
|
|
9
|
+
if ((0, shouldSkip_1.shouldSkip)("checkMulti", context)) {
|
|
10
10
|
return context;
|
|
11
11
|
}
|
|
12
12
|
const { service, method } = context;
|
|
13
|
-
if (!service.allowsMulti || !isMulti_1.isMulti(context) || method === "find") {
|
|
13
|
+
if (!service.allowsMulti || !(0, isMulti_1.isMulti)(context) || method === "find") {
|
|
14
14
|
return context;
|
|
15
15
|
}
|
|
16
16
|
if (!service.allowsMulti(method)) {
|
package/dist/hooks/runPerItem.js
CHANGED
|
@@ -21,10 +21,11 @@ const makeOptions = (options) => {
|
|
|
21
21
|
const runPerItem = (actionPerItem, options) => {
|
|
22
22
|
options = makeOptions(options);
|
|
23
23
|
return (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
-
if (shouldSkip_1.shouldSkip("runForItems", context)) {
|
|
24
|
+
if ((0, shouldSkip_1.shouldSkip)("runForItems", context)) {
|
|
25
25
|
return context;
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
//@ts-expect-error type error because feathers-hooks-common is feathers@4
|
|
28
|
+
let items = (0, feathers_hooks_common_1.getItems)(context);
|
|
28
29
|
items = (Array.isArray(items)) ? items : [items];
|
|
29
30
|
const promises = items.map((item) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
31
|
yield actionPerItem(item, context);
|
package/dist/hooks/setData.js
CHANGED
|
@@ -17,23 +17,24 @@ function setData(from, to, _options) {
|
|
|
17
17
|
const options = Object.assign({}, defaultOptions, _options);
|
|
18
18
|
return (context) => {
|
|
19
19
|
var _a;
|
|
20
|
-
|
|
20
|
+
//@ts-expect-error type error because feathers-hooks-common is feathers@4
|
|
21
|
+
let items = (0, feathers_hooks_common_1.getItems)(context);
|
|
21
22
|
items = (Array.isArray(items)) ? items : [items];
|
|
22
|
-
if (!has_1.default(context, from)) {
|
|
23
|
+
if (!(0, has_1.default)(context, from)) {
|
|
23
24
|
if (!((_a = context.params) === null || _a === void 0 ? void 0 : _a.provider) || options.allowUndefined === true) {
|
|
24
25
|
return context;
|
|
25
26
|
}
|
|
26
|
-
if (!options.overwrite && items.every((item) => has_1.default(item, to))) {
|
|
27
|
+
if (!options.overwrite && items.every((item) => (0, has_1.default)(item, to))) {
|
|
27
28
|
return context;
|
|
28
29
|
}
|
|
29
30
|
throw new errors_1.Forbidden(`Expected field ${from.toString()} not available`);
|
|
30
31
|
}
|
|
31
|
-
const val = get_1.default(context, from);
|
|
32
|
+
const val = (0, get_1.default)(context, from);
|
|
32
33
|
items.forEach((item) => {
|
|
33
|
-
if (!options.overwrite && has_1.default(item, to)) {
|
|
34
|
+
if (!options.overwrite && (0, has_1.default)(item, to)) {
|
|
34
35
|
return;
|
|
35
36
|
}
|
|
36
|
-
set_1.default(item, to, val);
|
|
37
|
+
(0, set_1.default)(item, to, val);
|
|
37
38
|
});
|
|
38
39
|
return context;
|
|
39
40
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -4,19 +4,19 @@ 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<
|
|
7
|
+
runPerItem: (actionPerItem: (item: any, context: import("@feathersjs/feathers/lib").HookContext<import("@feathersjs/feathers/lib").Application<any, any>, any>) => any, options: import("./types").HookRunPerItemOptions) => (context: import("@feathersjs/feathers/lib").HookContext<import("@feathersjs/feathers/lib").Application<any, any>, any>) => Promise<import("@feathersjs/feathers/lib").HookContext<import("@feathersjs/feathers/lib").Application<any, any>, any>>;
|
|
8
8
|
};
|
|
9
9
|
export { checkMulti };
|
|
10
10
|
export { setData };
|
|
11
11
|
export { runPerItem };
|
|
12
|
-
import { debounceMixin, DebouncedStore } from "./mixins/debounce-mixin";
|
|
12
|
+
import { debounceMixin, DebouncedService, DebouncedStore } from "./mixins/debounce-mixin";
|
|
13
13
|
export declare const mixins: {
|
|
14
14
|
debounceMixin: typeof debounceMixin;
|
|
15
15
|
DebouncedStore: typeof DebouncedStore;
|
|
16
16
|
};
|
|
17
17
|
export { debounceMixin };
|
|
18
|
+
export { DebouncedService };
|
|
18
19
|
export { DebouncedStore };
|
|
19
|
-
export { addHook } from "./utils/addHook";
|
|
20
20
|
export { getPaginate } from "./utils/getPaginate";
|
|
21
21
|
export { isMulti } from "./utils/isMulti";
|
|
22
22
|
export { isPaginated } from "./utils/isPaginated";
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.filterQuery = exports.shouldSkip = exports.markHookForSkip = exports.setResultEmpty = exports.pushSet = exports.mergeArrays = exports.mergeQuery = exports.isPaginated = exports.isMulti = exports.getPaginate = exports.
|
|
13
|
+
exports.filterQuery = exports.shouldSkip = exports.markHookForSkip = exports.setResultEmpty = exports.pushSet = exports.mergeArrays = exports.mergeQuery = exports.isPaginated = exports.isMulti = exports.getPaginate = exports.DebouncedStore = exports.debounceMixin = exports.mixins = exports.runPerItem = exports.setData = exports.checkMulti = exports.hooks = void 0;
|
|
14
14
|
// hooks
|
|
15
15
|
const checkMulti_1 = require("./hooks/checkMulti");
|
|
16
16
|
Object.defineProperty(exports, "checkMulti", { enumerable: true, get: function () { return checkMulti_1.checkMulti; } });
|
|
@@ -30,8 +30,6 @@ exports.mixins = {
|
|
|
30
30
|
debounceMixin: debounce_mixin_1.debounceMixin,
|
|
31
31
|
DebouncedStore: debounce_mixin_1.DebouncedStore
|
|
32
32
|
};
|
|
33
|
-
var addHook_1 = require("./utils/addHook");
|
|
34
|
-
Object.defineProperty(exports, "addHook", { enumerable: true, get: function () { return addHook_1.addHook; } });
|
|
35
33
|
var getPaginate_1 = require("./utils/getPaginate");
|
|
36
34
|
Object.defineProperty(exports, "getPaginate", { enumerable: true, get: function () { return getPaginate_1.getPaginate; } });
|
|
37
35
|
var isMulti_1 = require("./utils/isMulti");
|
|
@@ -7,7 +7,7 @@ export declare class DebouncedStore {
|
|
|
7
7
|
private _options;
|
|
8
8
|
private _isRunningById;
|
|
9
9
|
_queueById: Record<string, DebouncedFunc<((id: Id, action: DebouncedFunctionApp) => void | Promise<void>)>>;
|
|
10
|
-
add: (id: Id, action: (app?: Application<
|
|
10
|
+
add: (id: Id, action: (app?: Application<any, any> | undefined) => void | Promise<void>) => void | Promise<void> | undefined;
|
|
11
11
|
constructor(app: Application, options?: Partial<DebouncedStoreOptions>);
|
|
12
12
|
private unbounced;
|
|
13
13
|
private debounceById;
|
|
@@ -26,7 +26,7 @@ exports.makeDefaultOptions = makeDefaultOptions;
|
|
|
26
26
|
class DebouncedStore {
|
|
27
27
|
constructor(app, options) {
|
|
28
28
|
this._app = app;
|
|
29
|
-
this._options = Object.assign(exports.makeDefaultOptions(), options);
|
|
29
|
+
this._options = Object.assign((0, exports.makeDefaultOptions)(), options);
|
|
30
30
|
this._queueById = {};
|
|
31
31
|
this._isRunningById = {};
|
|
32
32
|
//this._waitingById = {};
|
|
@@ -52,7 +52,7 @@ class DebouncedStore {
|
|
|
52
52
|
if (typeof this._queueById[id] === "function") {
|
|
53
53
|
return this._queueById[id](id, action);
|
|
54
54
|
}
|
|
55
|
-
this._queueById[id] = debounce_1.default((id, action) => {
|
|
55
|
+
this._queueById[id] = (0, debounce_1.default)((id, action) => {
|
|
56
56
|
this.unbounced(id, action);
|
|
57
57
|
}, wait, Object.assign(Object.assign({}, options), { leading: false })); // leading required for return promise
|
|
58
58
|
return this._queueById[id](id, action);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { DebouncedStore } from "./DebouncedStore";
|
|
2
|
-
import type { Application } from "@feathersjs/feathers";
|
|
2
|
+
import type { Application, FeathersService } from "@feathersjs/feathers";
|
|
3
3
|
import type { InitDebounceMixinOptions } from "../../types";
|
|
4
|
+
export declare type DebouncedService = FeathersService & {
|
|
5
|
+
debouncedStore?: DebouncedStore;
|
|
6
|
+
};
|
|
4
7
|
export declare function debounceMixin(options?: Partial<InitDebounceMixinOptions>): ((app: Application) => void);
|
|
5
8
|
export { DebouncedStore };
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "DebouncedStore", { enumerable: true, get: functi
|
|
|
6
6
|
function debounceMixin(options) {
|
|
7
7
|
return (app) => {
|
|
8
8
|
options = options || {};
|
|
9
|
-
const defaultOptions = Object.assign(DebouncedStore_1.makeDefaultOptions(), options === null || options === void 0 ? void 0 : options.default);
|
|
9
|
+
const defaultOptions = Object.assign((0, DebouncedStore_1.makeDefaultOptions)(), options === null || options === void 0 ? void 0 : options.default);
|
|
10
10
|
app.mixins.push((service, path) => {
|
|
11
11
|
// if path is on blacklist, don't add debouncedStore to service
|
|
12
12
|
if ((options === null || options === void 0 ? void 0 : options.blacklist) && options.blacklist.includes(path))
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Application
|
|
1
|
+
import type { Application } from "@feathersjs/feathers";
|
|
2
|
+
import type { AdapterService } from "@feathersjs/adapter-commons";
|
|
2
3
|
export declare type Path = Array<string | number>;
|
|
3
4
|
export declare type HookType = "before" | "after" | "error";
|
|
4
5
|
export declare type ServiceMethodName = "find" | "get" | "create" | "update" | "patch" | "remove";
|
|
@@ -43,7 +44,7 @@ export interface MergeQueryOptions<T> extends FilterQueryOptions<T> {
|
|
|
43
44
|
};
|
|
44
45
|
}
|
|
45
46
|
export interface FilterQueryOptions<T> {
|
|
46
|
-
service?:
|
|
47
|
+
service?: AdapterService<T>;
|
|
47
48
|
operators?: string[];
|
|
48
49
|
filters?: string[];
|
|
49
50
|
}
|
|
@@ -25,9 +25,9 @@ function filterQuery(query, options) {
|
|
|
25
25
|
return service.filterQuery({ query }, optionsForFilterQuery);
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
|
-
return adapter_commons_1.filterQuery(query, optionsForFilterQuery);
|
|
28
|
+
return (0, adapter_commons_1.filterQuery)(query, optionsForFilterQuery);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
return adapter_commons_1.filterQuery(query, options);
|
|
31
|
+
return (0, adapter_commons_1.filterQuery)(query, options);
|
|
32
32
|
}
|
|
33
33
|
exports.filterQuery = filterQuery;
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import { HookContext
|
|
1
|
+
import { HookContext } from "@feathersjs/feathers";
|
|
2
|
+
interface PaginationOptions {
|
|
3
|
+
default: number;
|
|
4
|
+
max: number;
|
|
5
|
+
}
|
|
2
6
|
export declare const getPaginate: (context: HookContext) => PaginationOptions | undefined;
|
|
7
|
+
export {};
|
|
@@ -6,7 +6,7 @@ const isPaginated = (context) => {
|
|
|
6
6
|
if (context.params.paginate === false) {
|
|
7
7
|
return false;
|
|
8
8
|
}
|
|
9
|
-
const paginate = getPaginate_1.getPaginate(context);
|
|
9
|
+
const paginate = (0, getPaginate_1.getPaginate)(context);
|
|
10
10
|
return !!paginate;
|
|
11
11
|
};
|
|
12
12
|
exports.isPaginated = isPaginated;
|
|
@@ -10,7 +10,7 @@ function markHookForSkip(hookName, type, context) {
|
|
|
10
10
|
const combinedName = (t === "all")
|
|
11
11
|
? hookName
|
|
12
12
|
: `${type}:${hookName}`;
|
|
13
|
-
pushSet_1.pushSet(params, ["skipHooks"], combinedName, { unique: true });
|
|
13
|
+
(0, pushSet_1.pushSet)(params, ["skipHooks"], combinedName, { unique: true });
|
|
14
14
|
});
|
|
15
15
|
context.params = params;
|
|
16
16
|
return context;
|
|
@@ -18,14 +18,14 @@ const hasOwnProperty = (obj, key) => {
|
|
|
18
18
|
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
19
19
|
};
|
|
20
20
|
function handleArray(target, source, key, options) {
|
|
21
|
-
const targetVal = get_1.default(target, key);
|
|
22
|
-
const sourceVal = get_1.default(source, key);
|
|
21
|
+
const targetVal = (0, get_1.default)(target, key);
|
|
22
|
+
const sourceVal = (0, get_1.default)(source, key);
|
|
23
23
|
if (!sourceVal && !targetVal) {
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
-
const handle = get_1.default(options, ["handle", ...key], options.defaultHandle);
|
|
27
|
-
const arr = mergeArrays_1.mergeArrays(targetVal, sourceVal, handle, key, options.actionOnEmptyIntersect);
|
|
28
|
-
set_1.default(target, key, arr);
|
|
26
|
+
const handle = (0, get_1.default)(options, ["handle", ...key], options.defaultHandle);
|
|
27
|
+
const arr = (0, mergeArrays_1.mergeArrays)(targetVal, sourceVal, handle, key, options.actionOnEmptyIntersect);
|
|
28
|
+
(0, set_1.default)(target, key, arr);
|
|
29
29
|
}
|
|
30
30
|
function handleCircular(target, source, prependKey, options) {
|
|
31
31
|
if (target === null || target === void 0 ? void 0 : target.$or) {
|
|
@@ -52,11 +52,11 @@ function handleCircular(target, source, prependKey, options) {
|
|
|
52
52
|
delete source.$and;
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
if (!has_1.default(source, prependKey)) {
|
|
55
|
+
if (!(0, has_1.default)(source, prependKey)) {
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
|
-
if (!has_1.default(target, prependKey)) {
|
|
59
|
-
set_1.default(target, prependKey, get_1.default(source, prependKey));
|
|
58
|
+
if (!(0, has_1.default)(target, prependKey)) {
|
|
59
|
+
(0, set_1.default)(target, prependKey, (0, get_1.default)(source, prependKey));
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
62
|
const { defaultHandle, actionOnEmptyIntersect } = options;
|
|
@@ -64,22 +64,22 @@ function handleCircular(target, source, prependKey, options) {
|
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
const getTargetVal = () => {
|
|
67
|
-
return (prependKey.length > 0) ? get_1.default(target, prependKey) : target;
|
|
67
|
+
return (prependKey.length > 0) ? (0, get_1.default)(target, prependKey) : target;
|
|
68
68
|
};
|
|
69
69
|
const getSourceVal = () => {
|
|
70
|
-
return (prependKey.length > 0) ? get_1.default(source, prependKey) : source;
|
|
70
|
+
return (prependKey.length > 0) ? (0, get_1.default)(source, prependKey) : source;
|
|
71
71
|
};
|
|
72
72
|
const targetVal = getTargetVal();
|
|
73
73
|
const sourceVal = getSourceVal();
|
|
74
|
-
if (isEqual_1.default(targetVal, sourceVal)) {
|
|
74
|
+
if ((0, isEqual_1.default)(targetVal, sourceVal)) {
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
77
|
if (defaultHandle === "source") {
|
|
78
|
-
set_1.default(target, prependKey, sourceVal);
|
|
78
|
+
(0, set_1.default)(target, prependKey, sourceVal);
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
81
81
|
if (targetVal === null || sourceVal === null) {
|
|
82
|
-
set_1.default(target, prependKey, sourceVal);
|
|
82
|
+
(0, set_1.default)(target, prependKey, sourceVal);
|
|
83
83
|
return;
|
|
84
84
|
}
|
|
85
85
|
const typeOfTargetVal = typeof targetVal;
|
|
@@ -87,7 +87,7 @@ function handleCircular(target, source, prependKey, options) {
|
|
|
87
87
|
if (defaultHandle === "intersect") {
|
|
88
88
|
actionOnEmptyIntersect(target, source, prependKey);
|
|
89
89
|
}
|
|
90
|
-
set_1.default(target, prependKey, sourceVal);
|
|
90
|
+
(0, set_1.default)(target, prependKey, sourceVal);
|
|
91
91
|
return;
|
|
92
92
|
}
|
|
93
93
|
const typeOfSourceVal = typeof sourceVal;
|
|
@@ -96,7 +96,7 @@ function handleCircular(target, source, prependKey, options) {
|
|
|
96
96
|
if (isTargetSimple || isSourceSimple) {
|
|
97
97
|
if (isTargetSimple && isSourceSimple) {
|
|
98
98
|
if (defaultHandle === "combine") {
|
|
99
|
-
set_1.default(target, prependKey, { $in: [...new Set([targetVal, sourceVal])] });
|
|
99
|
+
(0, set_1.default)(target, prependKey, { $in: [...new Set([targetVal, sourceVal])] });
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
102
102
|
else if (defaultHandle === "intersect") {
|
|
@@ -110,20 +110,20 @@ function handleCircular(target, source, prependKey, options) {
|
|
|
110
110
|
const targetHasIn = hasOwnProperty(targetVal, "$in");
|
|
111
111
|
const $in = (targetHasIn) ? targetVal["$in"] : sourceVal["$in"];
|
|
112
112
|
const otherVal = (isTargetSimple) ? targetVal : sourceVal;
|
|
113
|
-
if ($in.length === 1 && isEqual_1.default($in[0], otherVal)) {
|
|
114
|
-
set_1.default(target, prependKey, otherVal);
|
|
113
|
+
if ($in.length === 1 && (0, isEqual_1.default)($in[0], otherVal)) {
|
|
114
|
+
(0, set_1.default)(target, prependKey, otherVal);
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
117
117
|
else if (defaultHandle === "combine") {
|
|
118
|
-
if (!$in.some((x) => isEqual_1.default(x, otherVal))) {
|
|
118
|
+
if (!$in.some((x) => (0, isEqual_1.default)(x, otherVal))) {
|
|
119
119
|
$in.push(otherVal);
|
|
120
120
|
}
|
|
121
|
-
set_1.default(target, `${prependKey}.$in`, $in);
|
|
121
|
+
(0, set_1.default)(target, `${prependKey}.$in`, $in);
|
|
122
122
|
return;
|
|
123
123
|
}
|
|
124
124
|
else if (defaultHandle === "intersect") {
|
|
125
|
-
if ($in.some((x) => isEqual_1.default(x, otherVal))) {
|
|
126
|
-
set_1.default(target, prependKey, otherVal);
|
|
125
|
+
if ($in.some((x) => (0, isEqual_1.default)(x, otherVal))) {
|
|
126
|
+
(0, set_1.default)(target, prependKey, otherVal);
|
|
127
127
|
}
|
|
128
128
|
else {
|
|
129
129
|
actionOnEmptyIntersect(target, source, prependKey);
|
|
@@ -139,7 +139,7 @@ function handleCircular(target, source, prependKey, options) {
|
|
|
139
139
|
const key = prependKey[prependKey.length - 1];
|
|
140
140
|
if (key === "$or") {
|
|
141
141
|
if (defaultHandle === "combine") {
|
|
142
|
-
const newVals = sourceVal.filter((x) => !targetVal.some((y) => isEqual_1.default(x, y)));
|
|
142
|
+
const newVals = sourceVal.filter((x) => !targetVal.some((y) => (0, isEqual_1.default)(x, y)));
|
|
143
143
|
targetVal.push(...newVals);
|
|
144
144
|
}
|
|
145
145
|
else if (defaultHandle === "intersect") {
|
|
@@ -176,7 +176,7 @@ function handleCircular(target, source, prependKey, options) {
|
|
|
176
176
|
return;
|
|
177
177
|
}
|
|
178
178
|
else if (defaultHandle === "intersect") {
|
|
179
|
-
const newVals = sourceVal.filter((x) => !targetVal.some((y) => isEqual_1.default(x, y)));
|
|
179
|
+
const newVals = sourceVal.filter((x) => !targetVal.some((y) => (0, isEqual_1.default)(x, y)));
|
|
180
180
|
targetVal.push(...newVals);
|
|
181
181
|
return;
|
|
182
182
|
}
|
|
@@ -185,29 +185,29 @@ function handleCircular(target, source, prependKey, options) {
|
|
|
185
185
|
if (defaultHandle === "combine") {
|
|
186
186
|
let $in = targetVal.concat(sourceVal);
|
|
187
187
|
$in = [...new Set($in)];
|
|
188
|
-
set_1.default(target, prependKey, $in);
|
|
188
|
+
(0, set_1.default)(target, prependKey, $in);
|
|
189
189
|
return;
|
|
190
190
|
}
|
|
191
191
|
else if (defaultHandle === "intersect") {
|
|
192
|
-
const $in = targetVal.filter((x) => sourceVal.some((y) => isEqual_1.default(x, y)));
|
|
192
|
+
const $in = targetVal.filter((x) => sourceVal.some((y) => (0, isEqual_1.default)(x, y)));
|
|
193
193
|
if ($in.length === 0) {
|
|
194
194
|
actionOnEmptyIntersect(target, source, prependKey);
|
|
195
195
|
}
|
|
196
196
|
else if ($in.length === 1) {
|
|
197
|
-
set_1.default(target, prependKey.slice(0, -1), $in[0]);
|
|
197
|
+
(0, set_1.default)(target, prependKey.slice(0, -1), $in[0]);
|
|
198
198
|
return;
|
|
199
199
|
}
|
|
200
200
|
else {
|
|
201
|
-
set_1.default(target, prependKey, $in);
|
|
201
|
+
(0, set_1.default)(target, prependKey, $in);
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
return;
|
|
205
205
|
}
|
|
206
|
-
set_1.default(target, prependKey, sourceVal);
|
|
206
|
+
(0, set_1.default)(target, prependKey, sourceVal);
|
|
207
207
|
return;
|
|
208
208
|
}
|
|
209
209
|
if (typeOfTargetVal !== "object" || typeOfSourceVal !== "object") {
|
|
210
|
-
set_1.default(target, prependKey, sourceVal);
|
|
210
|
+
(0, set_1.default)(target, prependKey, sourceVal);
|
|
211
211
|
return;
|
|
212
212
|
}
|
|
213
213
|
// both are objects
|
|
@@ -235,7 +235,7 @@ function makeDefaultOptions(options) {
|
|
|
235
235
|
}
|
|
236
236
|
function mergeQuery(target, source, options) {
|
|
237
237
|
const fullOptions = makeDefaultOptions(options);
|
|
238
|
-
const { filters: targetFilters, query: targetQuery } = filterQuery_1.filterQuery(target, {
|
|
238
|
+
const { filters: targetFilters, query: targetQuery } = (0, filterQuery_1.filterQuery)(target, {
|
|
239
239
|
operators: fullOptions.operators,
|
|
240
240
|
service: fullOptions.service
|
|
241
241
|
});
|
|
@@ -244,7 +244,7 @@ function mergeQuery(target, source, options) {
|
|
|
244
244
|
}
|
|
245
245
|
let {
|
|
246
246
|
// eslint-disable-next-line prefer-const
|
|
247
|
-
filters: sourceFilters, query: sourceQuery } = filterQuery_1.filterQuery(source, {
|
|
247
|
+
filters: sourceFilters, query: sourceQuery } = (0, filterQuery_1.filterQuery)(source, {
|
|
248
248
|
operators: fullOptions.operators,
|
|
249
249
|
service: fullOptions.service
|
|
250
250
|
});
|
|
@@ -265,13 +265,13 @@ function mergeQuery(target, source, options) {
|
|
|
265
265
|
handleArray(targetFilters, sourceFilters, ["$select"], fullOptions);
|
|
266
266
|
// remaining filters
|
|
267
267
|
delete sourceFilters["$select"];
|
|
268
|
-
merge_1.default(targetFilters, sourceFilters);
|
|
268
|
+
(0, merge_1.default)(targetFilters, sourceFilters);
|
|
269
269
|
//#endregion
|
|
270
270
|
//#region '$or' / '$and'
|
|
271
271
|
if ((options === null || options === void 0 ? void 0 : options.useLogicalConjunction) &&
|
|
272
272
|
(options.defaultHandle === "combine" ||
|
|
273
273
|
options.defaultHandle === "intersect") &&
|
|
274
|
-
!isEmpty_1.default(targetQuery)) {
|
|
274
|
+
!(0, isEmpty_1.default)(targetQuery)) {
|
|
275
275
|
const logicalOp = (options.defaultHandle === "combine")
|
|
276
276
|
? "$or"
|
|
277
277
|
: "$and";
|
|
@@ -301,13 +301,13 @@ function getParentProp(target, path) {
|
|
|
301
301
|
return target;
|
|
302
302
|
}
|
|
303
303
|
const pathOneUp = path.slice(0, -1);
|
|
304
|
-
return get_1.default(target, pathOneUp);
|
|
304
|
+
return (0, get_1.default)(target, pathOneUp);
|
|
305
305
|
}
|
|
306
306
|
function cleanOr(target) {
|
|
307
307
|
if (!target || !Array.isArray(target) || target.length <= 0) {
|
|
308
308
|
return target;
|
|
309
309
|
}
|
|
310
|
-
if (target.some(x => isEmpty_1.default(x))) {
|
|
310
|
+
if (target.some(x => (0, isEmpty_1.default)(x))) {
|
|
311
311
|
return undefined;
|
|
312
312
|
}
|
|
313
313
|
else {
|
|
@@ -318,11 +318,11 @@ function cleanAnd(target) {
|
|
|
318
318
|
if (!target || !Array.isArray(target) || target.length <= 0) {
|
|
319
319
|
return target;
|
|
320
320
|
}
|
|
321
|
-
if (target.every(x => isEmpty_1.default(x))) {
|
|
321
|
+
if (target.every(x => (0, isEmpty_1.default)(x))) {
|
|
322
322
|
return undefined;
|
|
323
323
|
}
|
|
324
324
|
else {
|
|
325
|
-
target = target.filter(x => !isEmpty_1.default(x));
|
|
325
|
+
target = target.filter(x => !(0, isEmpty_1.default)(x));
|
|
326
326
|
return arrayWithoutDuplicates(target);
|
|
327
327
|
}
|
|
328
328
|
}
|
|
@@ -330,5 +330,5 @@ function arrayWithoutDuplicates(target) {
|
|
|
330
330
|
if (!target || !Array.isArray(target)) {
|
|
331
331
|
return target;
|
|
332
332
|
}
|
|
333
|
-
return uniqWith_1.default(target, isEqual_1.default);
|
|
333
|
+
return (0, uniqWith_1.default)(target, isEqual_1.default);
|
|
334
334
|
}
|
package/dist/utils/pushSet.js
CHANGED
|
@@ -9,14 +9,14 @@ const get_1 = __importDefault(require("lodash/get"));
|
|
|
9
9
|
const set_1 = __importDefault(require("lodash/set"));
|
|
10
10
|
const pushSet = (obj, path, val, options) => {
|
|
11
11
|
options = options || {};
|
|
12
|
-
let arr = get_1.default(obj, path);
|
|
12
|
+
let arr = (0, get_1.default)(obj, path);
|
|
13
13
|
if (!arr || !Array.isArray(arr)) {
|
|
14
14
|
arr = [val];
|
|
15
|
-
set_1.default(obj, path, arr);
|
|
15
|
+
(0, set_1.default)(obj, path, arr);
|
|
16
16
|
return arr;
|
|
17
17
|
}
|
|
18
18
|
else {
|
|
19
|
-
if (options.unique && arr.some(x => isEqual_1.default(x, val))) {
|
|
19
|
+
if (options.unique && arr.some(x => (0, isEqual_1.default)(x, val))) {
|
|
20
20
|
return arr;
|
|
21
21
|
}
|
|
22
22
|
arr.push(val);
|
|
@@ -7,9 +7,9 @@ const setResultEmpty = (context) => {
|
|
|
7
7
|
if (context.result) {
|
|
8
8
|
return context;
|
|
9
9
|
}
|
|
10
|
-
const multi = __1.isMulti(context);
|
|
10
|
+
const multi = (0, __1.isMulti)(context);
|
|
11
11
|
if (multi) {
|
|
12
|
-
if (context.method === "find" && isPaginated_1.isPaginated(context)) {
|
|
12
|
+
if (context.method === "find" && (0, isPaginated_1.isPaginated)(context)) {
|
|
13
13
|
context.result = {
|
|
14
14
|
total: 0,
|
|
15
15
|
skip: 0,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "feathers-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-0",
|
|
4
4
|
"description": "Some utils for projects using '@feathersjs/feathers'",
|
|
5
5
|
"author": "fratzinger",
|
|
6
6
|
"repository": {
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@feathersjs/adapter-commons": "
|
|
35
|
-
"@feathersjs/errors": "
|
|
36
|
-
"@feathersjs/feathers": "
|
|
37
|
-
"feathers-hooks-common": "^5.0.
|
|
34
|
+
"@feathersjs/adapter-commons": "5.0.0-pre.15",
|
|
35
|
+
"@feathersjs/errors": "5.0.0-pre.15",
|
|
36
|
+
"@feathersjs/feathers": "5.0.0-pre.15",
|
|
37
|
+
"feathers-hooks-common": "^5.0.6",
|
|
38
38
|
"lodash": "^4.17.21",
|
|
39
39
|
"type-fest": "^2.5.4"
|
|
40
40
|
},
|
package/src/hooks/runPerItem.ts
CHANGED
|
@@ -22,6 +22,8 @@ export const runPerItem = (
|
|
|
22
22
|
options = makeOptions(options);
|
|
23
23
|
return async (context: HookContext): Promise<HookContext> => {
|
|
24
24
|
if (shouldSkip("runForItems", context)) { return context; }
|
|
25
|
+
|
|
26
|
+
//@ts-expect-error type error because feathers-hooks-common is feathers@4
|
|
25
27
|
let items = getItems(context);
|
|
26
28
|
items = (Array.isArray(items)) ? items : [items];
|
|
27
29
|
|
package/src/hooks/setData.ts
CHANGED
|
@@ -26,6 +26,7 @@ export function setData(
|
|
|
26
26
|
const options: Required<HookSetDataOptions> = Object.assign({}, defaultOptions, _options);
|
|
27
27
|
return (context: HookContext): HookContext => {
|
|
28
28
|
|
|
29
|
+
//@ts-expect-error type error because feathers-hooks-common is feathers@4
|
|
29
30
|
let items = getItems(context);
|
|
30
31
|
items = (Array.isArray(items)) ? items : [items];
|
|
31
32
|
|
package/src/index.ts
CHANGED
|
@@ -13,7 +13,7 @@ export { checkMulti };
|
|
|
13
13
|
export { setData };
|
|
14
14
|
export { runPerItem };
|
|
15
15
|
|
|
16
|
-
import { debounceMixin, DebouncedStore } from "./mixins/debounce-mixin";
|
|
16
|
+
import { debounceMixin, DebouncedService, DebouncedStore } from "./mixins/debounce-mixin";
|
|
17
17
|
|
|
18
18
|
export const mixins = {
|
|
19
19
|
debounceMixin,
|
|
@@ -21,9 +21,9 @@ export const mixins = {
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export { debounceMixin };
|
|
24
|
+
export { DebouncedService };
|
|
24
25
|
export { DebouncedStore };
|
|
25
26
|
|
|
26
|
-
export { addHook } from "./utils/addHook";
|
|
27
27
|
export { getPaginate } from "./utils/getPaginate";
|
|
28
28
|
export { isMulti } from "./utils/isMulti";
|
|
29
29
|
export { isPaginated } from "./utils/isPaginated";
|
|
@@ -37,4 +37,4 @@ export { shouldSkip } from "./utils/shouldSkip";
|
|
|
37
37
|
|
|
38
38
|
export { filterQuery } from "./utils/filterQuery";
|
|
39
39
|
|
|
40
|
-
export * from "./types";
|
|
40
|
+
export * from "./types";
|
|
@@ -3,18 +3,22 @@ import {
|
|
|
3
3
|
makeDefaultOptions
|
|
4
4
|
} from "./DebouncedStore";
|
|
5
5
|
|
|
6
|
-
import type { Application } from "@feathersjs/feathers";
|
|
6
|
+
import type { Application, FeathersService } from "@feathersjs/feathers";
|
|
7
7
|
|
|
8
8
|
import type {
|
|
9
9
|
InitDebounceMixinOptions,
|
|
10
10
|
DebouncedStoreOptions,
|
|
11
11
|
} from "../../types";
|
|
12
12
|
|
|
13
|
+
export type DebouncedService = FeathersService & {
|
|
14
|
+
debouncedStore?: DebouncedStore;
|
|
15
|
+
};
|
|
16
|
+
|
|
13
17
|
export function debounceMixin(options?: Partial<InitDebounceMixinOptions>): ((app: Application) => void) {
|
|
14
18
|
return (app: Application): void => {
|
|
15
19
|
options = options || {};
|
|
16
20
|
const defaultOptions = Object.assign(makeDefaultOptions(), options?.default);
|
|
17
|
-
app.mixins.push((service, path) => {
|
|
21
|
+
app.mixins.push((service: DebouncedService, path) => {
|
|
18
22
|
// if path is on blacklist, don't add debouncedStore to service
|
|
19
23
|
if (options?.blacklist && options.blacklist.includes(path)) return;
|
|
20
24
|
// if service already has registered something on `debouncedStore`
|
|
@@ -29,4 +33,4 @@ export function debounceMixin(options?: Partial<InitDebounceMixinOptions>): ((ap
|
|
|
29
33
|
};
|
|
30
34
|
}
|
|
31
35
|
|
|
32
|
-
export { DebouncedStore };
|
|
36
|
+
export { DebouncedStore };
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Application
|
|
1
|
+
import type { Application } from "@feathersjs/feathers";
|
|
2
|
+
import type { AdapterService } from "@feathersjs/adapter-commons";
|
|
2
3
|
|
|
3
4
|
export type Path = Array<string|number>;
|
|
4
5
|
export type HookType = "before" | "after" | "error";
|
|
@@ -69,7 +70,7 @@ export interface MergeQueryOptions<T> extends FilterQueryOptions<T> {
|
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
export interface FilterQueryOptions<T> {
|
|
72
|
-
service?:
|
|
73
|
+
service?: AdapterService<T>
|
|
73
74
|
operators?: string[],
|
|
74
75
|
filters?: string[],
|
|
75
76
|
}
|
|
@@ -86,4 +87,4 @@ export interface FilterQueryResult {
|
|
|
86
87
|
[key: string]: unknown
|
|
87
88
|
}
|
|
88
89
|
|
|
89
|
-
//#endregion
|
|
90
|
+
//#endregion
|
package/src/utils/filterQuery.ts
CHANGED
|
@@ -25,10 +25,10 @@ export function filterQuery<T>(query: Query, options?: FilterQueryOptions<T>): F
|
|
|
25
25
|
if (operators) { optionsForFilterQuery.operators = operators; }
|
|
26
26
|
if (filters) { optionsForFilterQuery.filters = filters; }
|
|
27
27
|
if (typeof service?.filterQuery === "function") {
|
|
28
|
-
return service.filterQuery({ query }, optionsForFilterQuery);
|
|
28
|
+
return service.filterQuery({ query }, optionsForFilterQuery) as FilterQueryResult;
|
|
29
29
|
} else {
|
|
30
30
|
return plainFilterQuery(query, optionsForFilterQuery) as FilterQueryResult;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
return plainFilterQuery(query, options) as FilterQueryResult;
|
|
34
|
-
}
|
|
34
|
+
}
|
package/src/utils/getPaginate.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import { HookContext
|
|
1
|
+
import { HookContext } from "@feathersjs/feathers";
|
|
2
|
+
|
|
3
|
+
// TODO: seems like this does no longer exist in feathers
|
|
4
|
+
interface PaginationOptions {
|
|
5
|
+
default: number;
|
|
6
|
+
max: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
2
9
|
|
|
3
10
|
export const getPaginate = (
|
|
4
11
|
context: HookContext
|
|
@@ -6,6 +13,7 @@ export const getPaginate = (
|
|
|
6
13
|
if (Object.prototype.hasOwnProperty.call(context.params, "paginate")) {
|
|
7
14
|
return context.params.paginate as PaginationOptions || undefined;
|
|
8
15
|
}
|
|
16
|
+
|
|
9
17
|
if (context.params.paginate === false) { return undefined; }
|
|
10
18
|
let options = context.service.options || {};
|
|
11
19
|
|
|
@@ -15,4 +23,4 @@ export const getPaginate = (
|
|
|
15
23
|
};
|
|
16
24
|
|
|
17
25
|
return options.paginate || undefined;
|
|
18
|
-
};
|
|
26
|
+
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const defaultOptions = () => {
|
|
2
|
-
return {
|
|
3
|
-
whitelist: ["*"],
|
|
4
|
-
blacklist: []
|
|
5
|
-
};
|
|
6
|
-
};
|
|
7
|
-
export const addHook = (app, hook, options) => {
|
|
8
|
-
options = Object.assign(defaultOptions(), options);
|
|
9
|
-
const { types, methods, whitelist, blacklist, orderByType } = options;
|
|
10
|
-
if (types.some(x => !(Object.keys(orderByType).includes(x)))) {
|
|
11
|
-
throw new Error("'feathers-utils/addHook': some types in 'orderByType' are undefined");
|
|
12
|
-
}
|
|
13
|
-
if (Object.keys(orderByType).some(type => !((["first", "last"]).includes(orderByType[type])))) {
|
|
14
|
-
throw new Error("'feathers-utils/addHook': only allowed values for 'orderByType' are 'first' or 'last'");
|
|
15
|
-
}
|
|
16
|
-
const allServices = app.services;
|
|
17
|
-
for (const servicePath in allServices) {
|
|
18
|
-
if (!Object.prototype.hasOwnProperty.call(allServices, servicePath)) {
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
const service = app.service(servicePath);
|
|
22
|
-
if (blacklist && blacklist.includes(servicePath)) {
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
if (whitelist && !whitelist.includes("*") && !whitelist.includes(servicePath)) {
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
types.forEach(type => {
|
|
29
|
-
const order = orderByType[type];
|
|
30
|
-
const unshiftOrPush = (order === "first") ? "unshift" : "push";
|
|
31
|
-
methods.forEach(method => {
|
|
32
|
-
service.__hooks[type][method][unshiftOrPush](hook);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
};
|
package/dist/utils/addHook.d.ts
DELETED
package/dist/utils/addHook.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addHook = void 0;
|
|
4
|
-
const defaultOptions = () => {
|
|
5
|
-
return {
|
|
6
|
-
whitelist: ["*"],
|
|
7
|
-
blacklist: []
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
const addHook = (app, hook, options) => {
|
|
11
|
-
options = Object.assign(defaultOptions(), options);
|
|
12
|
-
const { types, methods, whitelist, blacklist, orderByType } = options;
|
|
13
|
-
if (types.some(x => !(Object.keys(orderByType).includes(x)))) {
|
|
14
|
-
throw new Error("'feathers-utils/addHook': some types in 'orderByType' are undefined");
|
|
15
|
-
}
|
|
16
|
-
if (Object.keys(orderByType).some(type => !((["first", "last"]).includes(orderByType[type])))) {
|
|
17
|
-
throw new Error("'feathers-utils/addHook': only allowed values for 'orderByType' are 'first' or 'last'");
|
|
18
|
-
}
|
|
19
|
-
const allServices = app.services;
|
|
20
|
-
for (const servicePath in allServices) {
|
|
21
|
-
if (!Object.prototype.hasOwnProperty.call(allServices, servicePath)) {
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
const service = app.service(servicePath);
|
|
25
|
-
if (blacklist && blacklist.includes(servicePath)) {
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
if (whitelist && !whitelist.includes("*") && !whitelist.includes(servicePath)) {
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
types.forEach(type => {
|
|
32
|
-
const order = orderByType[type];
|
|
33
|
-
const unshiftOrPush = (order === "first") ? "unshift" : "push";
|
|
34
|
-
methods.forEach(method => {
|
|
35
|
-
service.__hooks[type][method][unshiftOrPush](hook);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
exports.addHook = addHook;
|
package/src/utils/addHook.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { Application } from "@feathersjs/feathers";
|
|
2
|
-
import type { AddHookOptions, HookType } from "../types";
|
|
3
|
-
|
|
4
|
-
const defaultOptions = (): Partial<AddHookOptions> => {
|
|
5
|
-
return {
|
|
6
|
-
whitelist: ["*"],
|
|
7
|
-
blacklist: []
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const addHook = (app: Application, hook: unknown, options: AddHookOptions): void => {
|
|
12
|
-
options = Object.assign(defaultOptions(), options);
|
|
13
|
-
|
|
14
|
-
const {
|
|
15
|
-
types,
|
|
16
|
-
methods,
|
|
17
|
-
whitelist,
|
|
18
|
-
blacklist,
|
|
19
|
-
orderByType
|
|
20
|
-
} = options;
|
|
21
|
-
|
|
22
|
-
if (types.some(
|
|
23
|
-
x => !(Object.keys(orderByType).includes(x)))
|
|
24
|
-
) {
|
|
25
|
-
throw new Error("'feathers-utils/addHook': some types in 'orderByType' are undefined");
|
|
26
|
-
}
|
|
27
|
-
if (
|
|
28
|
-
(Object.keys(orderByType) as HookType[]).some(
|
|
29
|
-
type => !((["first", "last"]).includes(orderByType[type])))
|
|
30
|
-
) {
|
|
31
|
-
throw new Error("'feathers-utils/addHook': only allowed values for 'orderByType' are 'first' or 'last'");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const allServices = app.services;
|
|
35
|
-
|
|
36
|
-
for (const servicePath in allServices) {
|
|
37
|
-
if(!Object.prototype.hasOwnProperty.call(allServices, servicePath)) { continue; }
|
|
38
|
-
const service = app.service(servicePath);
|
|
39
|
-
if (blacklist && blacklist.includes(servicePath)) { continue; }
|
|
40
|
-
if (whitelist && !whitelist.includes("*") && !whitelist.includes(servicePath)) { continue; }
|
|
41
|
-
types.forEach(type => {
|
|
42
|
-
const order = orderByType[type];
|
|
43
|
-
const unshiftOrPush = (order === "first") ? "unshift" : "push";
|
|
44
|
-
methods.forEach(method => {
|
|
45
|
-
service.__hooks[type][method][unshiftOrPush](hook);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
};
|