feathers-utils 2.0.0-9 → 2.1.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/LICENSE +1 -1
- package/README.md +3 -1
- package/dist/index.cjs +964 -0
- package/dist/index.d.ts +262 -5
- package/dist/index.mjs +938 -0
- package/package.json +35 -38
- package/src/filters/object.ts +1 -1
- package/src/hooks/forEach.ts +47 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/makeSequelizeQuery.ts_ +4 -4
- package/src/hooks/parseFields.ts +27 -0
- package/src/hooks/runPerItem.ts +4 -6
- package/src/hooks/setData.ts +4 -5
- package/src/index.ts +1 -0
- package/src/typesInternal.ts +7 -0
- package/src/utility-types/index.ts +116 -0
- package/src/utils/getItemsIsArray.ts +27 -11
- package/src/utils/getPaginate.ts +2 -1
- package/src/utils/internal.utils.ts +6 -0
- package/src/utils/mergeQuery/mergeQuery.ts +62 -25
- package/src/utils/mergeQuery/utils.ts +82 -29
- package/dist/esm/filters/array.d.ts +0 -2
- package/dist/esm/filters/array.js +0 -17
- package/dist/esm/filters/index.d.ts +0 -2
- package/dist/esm/filters/index.js +0 -2
- package/dist/esm/filters/object.d.ts +0 -2
- package/dist/esm/filters/object.js +0 -15
- package/dist/esm/hooks/checkMulti.d.ts +0 -5
- package/dist/esm/hooks/checkMulti.js +0 -20
- package/dist/esm/hooks/createRelated.d.ts +0 -12
- package/dist/esm/hooks/createRelated.js +0 -31
- package/dist/esm/hooks/index.d.ts +0 -6
- package/dist/esm/hooks/index.js +0 -6
- package/dist/esm/hooks/onDelete.d.ts +0 -12
- package/dist/esm/hooks/onDelete.js +0 -47
- package/dist/esm/hooks/removeRelated.d.ts +0 -11
- package/dist/esm/hooks/removeRelated.js +0 -37
- package/dist/esm/hooks/runPerItem.d.ts +0 -10
- package/dist/esm/hooks/runPerItem.js +0 -29
- package/dist/esm/hooks/setData.d.ts +0 -11
- package/dist/esm/hooks/setData.js +0 -46
- package/dist/esm/index.d.ts +0 -5
- package/dist/esm/index.js +0 -5
- package/dist/esm/mixins/debounce-mixin/DebouncedStore.d.ts +0 -18
- package/dist/esm/mixins/debounce-mixin/DebouncedStore.js +0 -46
- package/dist/esm/mixins/debounce-mixin/debounceMixin.d.ts +0 -3
- package/dist/esm/mixins/debounce-mixin/debounceMixin.js +0 -19
- package/dist/esm/mixins/debounce-mixin/index.d.ts +0 -3
- package/dist/esm/mixins/debounce-mixin/index.js +0 -3
- package/dist/esm/mixins/debounce-mixin/types.d.ts +0 -13
- package/dist/esm/mixins/debounce-mixin/types.js +0 -1
- package/dist/esm/mixins/index.d.ts +0 -1
- package/dist/esm/mixins/index.js +0 -1
- package/dist/esm/types.d.ts +0 -3
- package/dist/esm/types.js +0 -1
- package/dist/esm/typesInternal.d.ts +0 -3
- package/dist/esm/typesInternal.js +0 -3
- package/dist/esm/utils/filterQuery.d.ts +0 -8
- package/dist/esm/utils/filterQuery.js +0 -30
- package/dist/esm/utils/getItemsIsArray.d.ts +0 -10
- package/dist/esm/utils/getItemsIsArray.js +0 -16
- package/dist/esm/utils/getPaginate.d.ts +0 -9
- package/dist/esm/utils/getPaginate.js +0 -20
- package/dist/esm/utils/index.d.ts +0 -11
- package/dist/esm/utils/index.js +0 -11
- package/dist/esm/utils/isMulti.d.ts +0 -11
- package/dist/esm/utils/isMulti.js +0 -26
- package/dist/esm/utils/isPaginated.d.ts +0 -5
- package/dist/esm/utils/isPaginated.js +0 -11
- package/dist/esm/utils/markHookForSkip.d.ts +0 -7
- package/dist/esm/utils/markHookForSkip.js +0 -18
- package/dist/esm/utils/mergeQuery/index.d.ts +0 -3
- package/dist/esm/utils/mergeQuery/index.js +0 -3
- package/dist/esm/utils/mergeQuery/mergeArrays.d.ts +0 -3
- package/dist/esm/utils/mergeQuery/mergeArrays.js +0 -37
- package/dist/esm/utils/mergeQuery/mergeQuery.d.ts +0 -3
- package/dist/esm/utils/mergeQuery/mergeQuery.js +0 -70
- package/dist/esm/utils/mergeQuery/types.d.ts +0 -13
- package/dist/esm/utils/mergeQuery/types.js +0 -1
- package/dist/esm/utils/mergeQuery/utils.d.ts +0 -11
- package/dist/esm/utils/mergeQuery/utils.js +0 -272
- package/dist/esm/utils/pushSet.d.ts +0 -8
- package/dist/esm/utils/pushSet.js +0 -22
- package/dist/esm/utils/setResultEmpty.d.ts +0 -5
- package/dist/esm/utils/setResultEmpty.js +0 -28
- package/dist/esm/utils/shouldSkip.d.ts +0 -8
- package/dist/esm/utils/shouldSkip.js +0 -29
- package/dist/esm/utils/validateQueryProperty.d.ts +0 -5
- package/dist/esm/utils/validateQueryProperty.js +0 -23
- package/dist/filters/array.d.ts +0 -2
- package/dist/filters/array.js +0 -21
- package/dist/filters/index.d.ts +0 -2
- package/dist/filters/index.js +0 -18
- package/dist/filters/object.d.ts +0 -2
- package/dist/filters/object.js +0 -22
- package/dist/hooks/checkMulti.d.ts +0 -5
- package/dist/hooks/checkMulti.js +0 -24
- package/dist/hooks/createRelated.d.ts +0 -12
- package/dist/hooks/createRelated.js +0 -44
- package/dist/hooks/index.d.ts +0 -6
- package/dist/hooks/index.js +0 -22
- package/dist/hooks/onDelete.d.ts +0 -12
- package/dist/hooks/onDelete.js +0 -60
- package/dist/hooks/removeRelated.d.ts +0 -11
- package/dist/hooks/removeRelated.js +0 -50
- package/dist/hooks/runPerItem.d.ts +0 -10
- package/dist/hooks/runPerItem.js +0 -42
- package/dist/hooks/setData.d.ts +0 -11
- package/dist/hooks/setData.js +0 -54
- package/dist/index.js +0 -21
- package/dist/mixins/debounce-mixin/DebouncedStore.d.ts +0 -18
- package/dist/mixins/debounce-mixin/DebouncedStore.js +0 -65
- package/dist/mixins/debounce-mixin/debounceMixin.d.ts +0 -3
- package/dist/mixins/debounce-mixin/debounceMixin.js +0 -23
- package/dist/mixins/debounce-mixin/index.d.ts +0 -3
- package/dist/mixins/debounce-mixin/index.js +0 -19
- package/dist/mixins/debounce-mixin/types.d.ts +0 -13
- package/dist/mixins/debounce-mixin/types.js +0 -2
- package/dist/mixins/index.d.ts +0 -1
- package/dist/mixins/index.js +0 -17
- package/dist/types.d.ts +0 -3
- package/dist/types.js +0 -2
- package/dist/typesInternal.d.ts +0 -3
- package/dist/typesInternal.js +0 -4
- package/dist/utils/filterQuery.d.ts +0 -8
- package/dist/utils/filterQuery.js +0 -46
- package/dist/utils/getItemsIsArray.d.ts +0 -10
- package/dist/utils/getItemsIsArray.js +0 -20
- package/dist/utils/getPaginate.d.ts +0 -9
- package/dist/utils/getPaginate.js +0 -22
- package/dist/utils/index.d.ts +0 -11
- package/dist/utils/index.js +0 -27
- package/dist/utils/isMulti.d.ts +0 -11
- package/dist/utils/isMulti.js +0 -30
- package/dist/utils/isPaginated.d.ts +0 -5
- package/dist/utils/isPaginated.js +0 -15
- package/dist/utils/markHookForSkip.d.ts +0 -7
- package/dist/utils/markHookForSkip.js +0 -22
- package/dist/utils/mergeQuery/index.d.ts +0 -3
- package/dist/utils/mergeQuery/index.js +0 -19
- package/dist/utils/mergeQuery/mergeArrays.d.ts +0 -3
- package/dist/utils/mergeQuery/mergeArrays.js +0 -41
- package/dist/utils/mergeQuery/mergeQuery.d.ts +0 -3
- package/dist/utils/mergeQuery/mergeQuery.js +0 -77
- package/dist/utils/mergeQuery/types.d.ts +0 -13
- package/dist/utils/mergeQuery/types.js +0 -2
- package/dist/utils/mergeQuery/utils.d.ts +0 -11
- package/dist/utils/mergeQuery/utils.js +0 -287
- package/dist/utils/pushSet.d.ts +0 -8
- package/dist/utils/pushSet.js +0 -29
- package/dist/utils/setResultEmpty.d.ts +0 -5
- package/dist/utils/setResultEmpty.js +0 -32
- package/dist/utils/shouldSkip.d.ts +0 -8
- package/dist/utils/shouldSkip.js +0 -33
- package/dist/utils/validateQueryProperty.d.ts +0 -5
- package/dist/utils/validateQueryProperty.js +0 -25
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import _isEqual from "lodash/isEqual.js";
|
|
2
|
-
import _get from "lodash/get.js";
|
|
3
|
-
import _set from "lodash/set.js";
|
|
4
|
-
/**
|
|
5
|
-
* util to push a value to an array at a given path in an object
|
|
6
|
-
*/
|
|
7
|
-
export const pushSet = (obj, path, val, options) => {
|
|
8
|
-
options = options || {};
|
|
9
|
-
let arr = _get(obj, path);
|
|
10
|
-
if (!arr || !Array.isArray(arr)) {
|
|
11
|
-
arr = [val];
|
|
12
|
-
_set(obj, path, arr);
|
|
13
|
-
return arr;
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
if (options.unique && arr.some((x) => _isEqual(x, val))) {
|
|
17
|
-
return arr;
|
|
18
|
-
}
|
|
19
|
-
arr.push(val);
|
|
20
|
-
return arr;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { HookContext } from "@feathersjs/feathers";
|
|
2
|
-
/**
|
|
3
|
-
* util to set `context.result` to an empty array or object, depending on the hook type
|
|
4
|
-
*/
|
|
5
|
-
export declare const setResultEmpty: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any> = HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(context: H) => H;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { isMulti } from "./isMulti";
|
|
2
|
-
import { isPaginated } from "./isPaginated";
|
|
3
|
-
/**
|
|
4
|
-
* util to set `context.result` to an empty array or object, depending on the hook type
|
|
5
|
-
*/
|
|
6
|
-
export const setResultEmpty = (context) => {
|
|
7
|
-
if (context.result) {
|
|
8
|
-
return context;
|
|
9
|
-
}
|
|
10
|
-
const multi = isMulti(context);
|
|
11
|
-
if (multi) {
|
|
12
|
-
if (context.method === "find" && isPaginated(context)) {
|
|
13
|
-
context.result = {
|
|
14
|
-
total: 0,
|
|
15
|
-
skip: 0,
|
|
16
|
-
limit: 0,
|
|
17
|
-
data: [],
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
context.result = [];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
context.result = null;
|
|
26
|
-
}
|
|
27
|
-
return context;
|
|
28
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { HookContext } from "@feathersjs/feathers";
|
|
2
|
-
export type ShouldSkipOptions = {
|
|
3
|
-
notSkippable?: boolean;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* util to detect if a hook should be skipped
|
|
7
|
-
*/
|
|
8
|
-
export declare const shouldSkip: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any> = HookContext<import("@feathersjs/feathers").Application<any, any>, any>, O extends ShouldSkipOptions = ShouldSkipOptions>(hookName: string, context: H, options?: O | undefined) => boolean;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// Kudos to @DaddyWarbucks! This is a cheeky copy of his awesome library: 'feathers-fletching'.
|
|
2
|
-
// Definitely check it out! https://daddywarbucks.github.io/feathers-fletching/overview.html
|
|
3
|
-
import { GeneralError } from "@feathersjs/errors";
|
|
4
|
-
/**
|
|
5
|
-
* util to detect if a hook should be skipped
|
|
6
|
-
*/
|
|
7
|
-
export const shouldSkip = (hookName, context, options) => {
|
|
8
|
-
if (!context.params || !context.params.skipHooks || options?.notSkippable) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
const { skipHooks } = context.params;
|
|
12
|
-
if (!Array.isArray(skipHooks)) {
|
|
13
|
-
throw new GeneralError("The `skipHooks` param must be an Array of Strings");
|
|
14
|
-
}
|
|
15
|
-
const { type } = context;
|
|
16
|
-
if (skipHooks.includes(hookName)) {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
else if (skipHooks.includes("all")) {
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
else if (skipHooks.includes(type)) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
else if (skipHooks.includes(`${type}:${hookName}`)) {
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
return false;
|
|
29
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { _ } from "@feathersjs/commons";
|
|
2
|
-
import { BadRequest } from "@feathersjs/errors";
|
|
3
|
-
const isPlainObject = (value) => _.isObject(value) && value.constructor === {}.constructor;
|
|
4
|
-
/**
|
|
5
|
-
* util to validate a query for operators
|
|
6
|
-
*/
|
|
7
|
-
export const validateQueryProperty = (query, operators = []) => {
|
|
8
|
-
if (!isPlainObject(query)) {
|
|
9
|
-
return query;
|
|
10
|
-
}
|
|
11
|
-
for (const key of Object.keys(query)) {
|
|
12
|
-
if (key.startsWith("$") && !operators.includes(key)) {
|
|
13
|
-
throw new BadRequest(`Invalid query parameter ${key}`, query);
|
|
14
|
-
}
|
|
15
|
-
const value = query[key];
|
|
16
|
-
if (isPlainObject(value)) {
|
|
17
|
-
query[key] = validateQueryProperty(value, operators);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return {
|
|
21
|
-
...query,
|
|
22
|
-
};
|
|
23
|
-
};
|
package/dist/filters/array.d.ts
DELETED
package/dist/filters/array.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.filterArray = void 0;
|
|
4
|
-
const validateQueryProperty_1 = require("../utils/validateQueryProperty");
|
|
5
|
-
const filterQueryArray = (key) => (arr, { operators }) => {
|
|
6
|
-
if (arr && !Array.isArray(arr)) {
|
|
7
|
-
throw new Error(`Invalid query parameter '${key}'. It has to be an array`);
|
|
8
|
-
}
|
|
9
|
-
if (Array.isArray(arr)) {
|
|
10
|
-
return arr.map((current) => (0, validateQueryProperty_1.validateQueryProperty)(current, operators));
|
|
11
|
-
}
|
|
12
|
-
return arr;
|
|
13
|
-
};
|
|
14
|
-
const filterArray = (...keys) => {
|
|
15
|
-
const result = {};
|
|
16
|
-
for (const key of keys) {
|
|
17
|
-
result[key] = filterQueryArray(key);
|
|
18
|
-
}
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
exports.filterArray = filterArray;
|
package/dist/filters/index.d.ts
DELETED
package/dist/filters/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./array"), exports);
|
|
18
|
-
__exportStar(require("./object"), exports);
|
package/dist/filters/object.d.ts
DELETED
package/dist/filters/object.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.filterObject = void 0;
|
|
7
|
-
const validateQueryProperty_1 = require("../utils/validateQueryProperty");
|
|
8
|
-
const isObject_1 = __importDefault(require("lodash/isObject"));
|
|
9
|
-
const filterQueryObject = (key) => (obj, { operators }) => {
|
|
10
|
-
if (obj && !(0, isObject_1.default)(obj)) {
|
|
11
|
-
throw new Error(`Invalid query parameter: '${key}'. It has to be an object`);
|
|
12
|
-
}
|
|
13
|
-
return (0, validateQueryProperty_1.validateQueryProperty)(obj, operators);
|
|
14
|
-
};
|
|
15
|
-
const filterObject = (...keys) => {
|
|
16
|
-
const result = {};
|
|
17
|
-
for (const key of keys) {
|
|
18
|
-
result[key] = filterQueryObject(key);
|
|
19
|
-
}
|
|
20
|
-
return result;
|
|
21
|
-
};
|
|
22
|
-
exports.filterObject = filterObject;
|
package/dist/hooks/checkMulti.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkMulti = void 0;
|
|
4
|
-
const errors_1 = require("@feathersjs/errors");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
|
-
/**
|
|
7
|
-
* hook to check if context is multi patch/remove and if the service allows it
|
|
8
|
-
*/
|
|
9
|
-
function checkMulti() {
|
|
10
|
-
return (context) => {
|
|
11
|
-
if ((0, utils_1.shouldSkip)("checkMulti", context)) {
|
|
12
|
-
return context;
|
|
13
|
-
}
|
|
14
|
-
const { service, method } = context;
|
|
15
|
-
if (!service.allowsMulti || !(0, utils_1.isMulti)(context) || method === "find") {
|
|
16
|
-
return context;
|
|
17
|
-
}
|
|
18
|
-
if (!service.allowsMulti(method)) {
|
|
19
|
-
throw new errors_1.MethodNotAllowed(`Can not ${method} multiple entries`);
|
|
20
|
-
}
|
|
21
|
-
return context;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
exports.checkMulti = checkMulti;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { HookContext } from "@feathersjs/feathers";
|
|
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
|
-
/**
|
|
10
|
-
* hook to create related items
|
|
11
|
-
*/
|
|
12
|
-
export declare function createRelated<S = Record<string, any>, H extends HookContext = HookContext>({ service, multi, data, createItemsInDataArraySeparately, }: CreateRelatedOptions<S>): (context: H) => Promise<H>;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.createRelated = void 0;
|
|
13
|
-
const feathers_hooks_common_1 = require("feathers-hooks-common");
|
|
14
|
-
const utils_1 = require("../utils");
|
|
15
|
-
/**
|
|
16
|
-
* hook to create related items
|
|
17
|
-
*/
|
|
18
|
-
function createRelated({ service, multi = true, data, createItemsInDataArraySeparately = true, }) {
|
|
19
|
-
if (!service || !data) {
|
|
20
|
-
throw "initialize hook 'createRelated' completely!";
|
|
21
|
-
}
|
|
22
|
-
return (context) => __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
if ((0, utils_1.shouldSkip)("createRelated", context)) {
|
|
24
|
-
return context;
|
|
25
|
-
}
|
|
26
|
-
(0, feathers_hooks_common_1.checkContext)(context, "after", undefined, "createRelated");
|
|
27
|
-
const { items } = (0, utils_1.getItemsIsArray)(context);
|
|
28
|
-
let dataToCreate = (yield Promise.all(items.map((item) => __awaiter(this, void 0, void 0, function* () { return data(item, context); })))).filter((x) => !!x);
|
|
29
|
-
if (createItemsInDataArraySeparately) {
|
|
30
|
-
dataToCreate = dataToCreate.flat();
|
|
31
|
-
}
|
|
32
|
-
if (!dataToCreate || dataToCreate.length <= 0) {
|
|
33
|
-
return context;
|
|
34
|
-
}
|
|
35
|
-
if (multi) {
|
|
36
|
-
yield context.app.service(service).create(dataToCreate);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
yield Promise.all(dataToCreate.map((item) => __awaiter(this, void 0, void 0, function* () { return context.app.service(service).create(item); })));
|
|
40
|
-
}
|
|
41
|
-
return context;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
exports.createRelated = createRelated;
|
package/dist/hooks/index.d.ts
DELETED
package/dist/hooks/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./checkMulti"), exports);
|
|
18
|
-
__exportStar(require("./createRelated"), exports);
|
|
19
|
-
__exportStar(require("./onDelete"), exports);
|
|
20
|
-
__exportStar(require("./removeRelated"), exports);
|
|
21
|
-
__exportStar(require("./runPerItem"), exports);
|
|
22
|
-
__exportStar(require("./setData"), exports);
|
package/dist/hooks/onDelete.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { HookContext } from "@feathersjs/feathers";
|
|
2
|
-
export type OnDeleteAction = "cascade" | "set null";
|
|
3
|
-
export interface OnDeleteOptions {
|
|
4
|
-
keyThere: string;
|
|
5
|
-
keyHere: string;
|
|
6
|
-
onDelete: OnDeleteAction;
|
|
7
|
-
blocking?: boolean;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* hook to manipulate related items on delete
|
|
11
|
-
*/
|
|
12
|
-
export declare function onDelete<S = Record<string, any>, H extends HookContext = HookContext>(service: keyof S, { keyThere, keyHere, onDelete, blocking, }: OnDeleteOptions): (context: H) => Promise<H>;
|
package/dist/hooks/onDelete.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.onDelete = void 0;
|
|
13
|
-
const feathers_hooks_common_1 = require("feathers-hooks-common");
|
|
14
|
-
const utils_1 = require("../utils");
|
|
15
|
-
/**
|
|
16
|
-
* hook to manipulate related items on delete
|
|
17
|
-
*/
|
|
18
|
-
function onDelete(service, { keyThere, keyHere = "id", onDelete = "cascade", blocking = true, }) {
|
|
19
|
-
if (!service || !keyThere) {
|
|
20
|
-
throw "initialize hook 'removeRelated' completely!";
|
|
21
|
-
}
|
|
22
|
-
if (!["cascade", "set null"].includes(onDelete)) {
|
|
23
|
-
throw "onDelete must be 'cascade' or 'set null'";
|
|
24
|
-
}
|
|
25
|
-
return (context) => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
if ((0, utils_1.shouldSkip)("onDelete", context)) {
|
|
27
|
-
return context;
|
|
28
|
-
}
|
|
29
|
-
(0, feathers_hooks_common_1.checkContext)(context, "after", "remove", "onDelete");
|
|
30
|
-
const { items } = (0, utils_1.getItemsIsArray)(context);
|
|
31
|
-
let ids = items.map((x) => x[keyHere]).filter((x) => !!x);
|
|
32
|
-
ids = [...new Set(ids)];
|
|
33
|
-
if (!ids || ids.length <= 0) {
|
|
34
|
-
return context;
|
|
35
|
-
}
|
|
36
|
-
const params = {
|
|
37
|
-
query: {
|
|
38
|
-
[keyThere]: {
|
|
39
|
-
$in: ids,
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
paginate: false,
|
|
43
|
-
};
|
|
44
|
-
let promise;
|
|
45
|
-
if (onDelete === "cascade") {
|
|
46
|
-
promise = context.app.service(service).remove(null, params);
|
|
47
|
-
}
|
|
48
|
-
else if (onDelete === "set null") {
|
|
49
|
-
const data = { [keyThere]: null };
|
|
50
|
-
promise = context.app
|
|
51
|
-
.service(service)
|
|
52
|
-
.patch(null, data, params);
|
|
53
|
-
}
|
|
54
|
-
if (blocking) {
|
|
55
|
-
yield promise;
|
|
56
|
-
}
|
|
57
|
-
return context;
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
exports.onDelete = onDelete;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { HookContext } from "@feathersjs/feathers";
|
|
2
|
-
export interface RemoveRelatedOptions<S = Record<string, any>> {
|
|
3
|
-
service: keyof S;
|
|
4
|
-
keyThere: string;
|
|
5
|
-
keyHere: string;
|
|
6
|
-
blocking?: boolean;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* hook to remove related items
|
|
10
|
-
*/
|
|
11
|
-
export declare function removeRelated<S = Record<string, any>, H extends HookContext = HookContext>({ service, keyThere, keyHere, blocking, }: RemoveRelatedOptions<S>): (context: H) => Promise<H>;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.removeRelated = void 0;
|
|
13
|
-
const feathers_hooks_common_1 = require("feathers-hooks-common");
|
|
14
|
-
const utils_1 = require("../utils");
|
|
15
|
-
/**
|
|
16
|
-
* hook to remove related items
|
|
17
|
-
*/
|
|
18
|
-
function removeRelated({ service, keyThere, keyHere = "id", blocking = true, }) {
|
|
19
|
-
if (!service || !keyThere) {
|
|
20
|
-
throw "initialize hook 'removeRelated' completely!";
|
|
21
|
-
}
|
|
22
|
-
return (context) => __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
if ((0, utils_1.shouldSkip)("removeRelated", context)) {
|
|
24
|
-
return context;
|
|
25
|
-
}
|
|
26
|
-
(0, feathers_hooks_common_1.checkContext)(context, "after", "remove", "removeRelated");
|
|
27
|
-
const { items } = (0, utils_1.getItemsIsArray)(context);
|
|
28
|
-
let ids = items.map((x) => x[keyHere]).filter((x) => !!x);
|
|
29
|
-
ids = [...new Set(ids)];
|
|
30
|
-
if (!ids || ids.length <= 0) {
|
|
31
|
-
return context;
|
|
32
|
-
}
|
|
33
|
-
// feathers does not accept `paginate: false` for remove, but some adapters need it to work properly
|
|
34
|
-
const promise = context.app
|
|
35
|
-
.service(service)
|
|
36
|
-
.remove(null, {
|
|
37
|
-
query: {
|
|
38
|
-
[keyThere]: {
|
|
39
|
-
$in: ids,
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
paginate: false,
|
|
43
|
-
});
|
|
44
|
-
if (blocking) {
|
|
45
|
-
yield promise;
|
|
46
|
-
}
|
|
47
|
-
return context;
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
exports.removeRelated = removeRelated;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { HookContext } from "@feathersjs/feathers";
|
|
2
|
-
import type { Promisable } from "../typesInternal";
|
|
3
|
-
export interface HookRunPerItemOptions {
|
|
4
|
-
wait?: boolean;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* hook to run a hook for each item in the context
|
|
8
|
-
* uses `context.result` if it is existent. otherwise uses context.data
|
|
9
|
-
*/
|
|
10
|
-
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>;
|
package/dist/hooks/runPerItem.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.runPerItem = void 0;
|
|
13
|
-
const utils_1 = require("../utils");
|
|
14
|
-
const makeOptions = (options) => {
|
|
15
|
-
options = options || {};
|
|
16
|
-
return Object.assign({
|
|
17
|
-
wait: true,
|
|
18
|
-
}, options);
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* hook to run a hook for each item in the context
|
|
22
|
-
* uses `context.result` if it is existent. otherwise uses context.data
|
|
23
|
-
*/
|
|
24
|
-
const runPerItem = (
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
-
actionPerItem, _options) => {
|
|
27
|
-
const options = makeOptions(_options);
|
|
28
|
-
return (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
-
if ((0, utils_1.shouldSkip)("runForItems", context)) {
|
|
30
|
-
return context;
|
|
31
|
-
}
|
|
32
|
-
const { items } = (0, utils_1.getItemsIsArray)(context);
|
|
33
|
-
const promises = items.map((item) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
-
yield actionPerItem(item, context);
|
|
35
|
-
}));
|
|
36
|
-
if (options.wait) {
|
|
37
|
-
yield Promise.all(promises);
|
|
38
|
-
}
|
|
39
|
-
return context;
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
exports.runPerItem = runPerItem;
|
package/dist/hooks/setData.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { HookContext } from "@feathersjs/feathers";
|
|
2
|
-
import type { PropertyPath } from "lodash";
|
|
3
|
-
import type { PredicateWithContext } from "../types";
|
|
4
|
-
export interface HookSetDataOptions {
|
|
5
|
-
allowUndefined?: boolean;
|
|
6
|
-
overwrite?: boolean | PredicateWithContext;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* hook to set properties on `context.result` (if existent) or `context.data` (otherwise)
|
|
10
|
-
*/
|
|
11
|
-
export declare function setData<H extends HookContext = HookContext>(from: PropertyPath, to: PropertyPath, _options?: HookSetDataOptions): (context: H) => H;
|
package/dist/hooks/setData.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.setData = void 0;
|
|
7
|
-
const get_js_1 = __importDefault(require("lodash/get.js"));
|
|
8
|
-
const set_js_1 = __importDefault(require("lodash/set.js"));
|
|
9
|
-
const has_js_1 = __importDefault(require("lodash/has.js"));
|
|
10
|
-
const errors_1 = require("@feathersjs/errors");
|
|
11
|
-
const utils_1 = require("../utils");
|
|
12
|
-
const defaultOptions = {
|
|
13
|
-
allowUndefined: false,
|
|
14
|
-
overwrite: true,
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* hook to set properties on `context.result` (if existent) or `context.data` (otherwise)
|
|
18
|
-
*/
|
|
19
|
-
function setData(from, to, _options) {
|
|
20
|
-
const options = Object.assign({}, defaultOptions, _options);
|
|
21
|
-
return (context) => {
|
|
22
|
-
var _a;
|
|
23
|
-
if ((0, utils_1.shouldSkip)("setData", context)) {
|
|
24
|
-
return context;
|
|
25
|
-
}
|
|
26
|
-
const { items } = (0, utils_1.getItemsIsArray)(context);
|
|
27
|
-
if (!(0, has_js_1.default)(context, from)) {
|
|
28
|
-
if (!((_a = context.params) === null || _a === void 0 ? void 0 : _a.provider) || options.allowUndefined === true) {
|
|
29
|
-
return context;
|
|
30
|
-
}
|
|
31
|
-
if (!options.overwrite &&
|
|
32
|
-
items.every((item) => (0, has_js_1.default)(item, to))) {
|
|
33
|
-
return context;
|
|
34
|
-
}
|
|
35
|
-
throw new errors_1.Forbidden(`Expected field ${from.toString()} not available`);
|
|
36
|
-
}
|
|
37
|
-
const val = (0, get_js_1.default)(context, from);
|
|
38
|
-
items.forEach((item) => {
|
|
39
|
-
let overwrite;
|
|
40
|
-
if (typeof options.overwrite === "function") {
|
|
41
|
-
overwrite = options.overwrite(item, context);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
overwrite = options.overwrite;
|
|
45
|
-
}
|
|
46
|
-
if (!overwrite && (0, has_js_1.default)(item, to)) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
(0, set_js_1.default)(item, to, val);
|
|
50
|
-
});
|
|
51
|
-
return context;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
exports.setData = setData;
|
package/dist/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./hooks"), exports);
|
|
18
|
-
__exportStar(require("./mixins"), exports);
|
|
19
|
-
__exportStar(require("./utils"), exports);
|
|
20
|
-
__exportStar(require("./filters"), exports);
|
|
21
|
-
__exportStar(require("./types"), exports);
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { DebouncedFunc } from "lodash";
|
|
2
|
-
import type { Application, Id } from "@feathersjs/feathers";
|
|
3
|
-
import type { DebouncedFunctionApp, DebouncedStoreOptions } from "./types";
|
|
4
|
-
export declare const makeDefaultOptions: () => DebouncedStoreOptions;
|
|
5
|
-
export type DebouncedService<T = any> = T & {
|
|
6
|
-
debouncedStore: DebouncedStore;
|
|
7
|
-
};
|
|
8
|
-
export declare class DebouncedStore {
|
|
9
|
-
private _app;
|
|
10
|
-
private _options;
|
|
11
|
-
private _isRunningById;
|
|
12
|
-
_queueById: Record<string, DebouncedFunc<(id: Id, action: DebouncedFunctionApp) => void | Promise<void>>>;
|
|
13
|
-
add: (id: Id, action: (app?: Application) => void | Promise<void>) => void | Promise<void> | undefined;
|
|
14
|
-
constructor(app: Application, options?: Partial<DebouncedStoreOptions>);
|
|
15
|
-
private unbounced;
|
|
16
|
-
private debounceById;
|
|
17
|
-
cancel(id: Id): void;
|
|
18
|
-
}
|