feathers-utils 2.0.0-9 → 2.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.
Files changed (150) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +3 -1
  3. package/dist/index.cjs +918 -0
  4. package/dist/index.d.ts +255 -5
  5. package/dist/index.mjs +892 -0
  6. package/package.json +34 -38
  7. package/src/filters/object.ts +1 -1
  8. package/src/hooks/forEach.ts +47 -0
  9. package/src/hooks/index.ts +3 -0
  10. package/src/hooks/makeSequelizeQuery.ts_ +4 -4
  11. package/src/hooks/parseFields.ts +27 -0
  12. package/src/index.ts +1 -0
  13. package/src/typesInternal.ts +7 -0
  14. package/src/utility-types/index.ts +116 -0
  15. package/src/utils/getItemsIsArray.ts +27 -11
  16. package/dist/esm/filters/array.d.ts +0 -2
  17. package/dist/esm/filters/array.js +0 -17
  18. package/dist/esm/filters/index.d.ts +0 -2
  19. package/dist/esm/filters/index.js +0 -2
  20. package/dist/esm/filters/object.d.ts +0 -2
  21. package/dist/esm/filters/object.js +0 -15
  22. package/dist/esm/hooks/checkMulti.d.ts +0 -5
  23. package/dist/esm/hooks/checkMulti.js +0 -20
  24. package/dist/esm/hooks/createRelated.d.ts +0 -12
  25. package/dist/esm/hooks/createRelated.js +0 -31
  26. package/dist/esm/hooks/index.d.ts +0 -6
  27. package/dist/esm/hooks/index.js +0 -6
  28. package/dist/esm/hooks/onDelete.d.ts +0 -12
  29. package/dist/esm/hooks/onDelete.js +0 -47
  30. package/dist/esm/hooks/removeRelated.d.ts +0 -11
  31. package/dist/esm/hooks/removeRelated.js +0 -37
  32. package/dist/esm/hooks/runPerItem.d.ts +0 -10
  33. package/dist/esm/hooks/runPerItem.js +0 -29
  34. package/dist/esm/hooks/setData.d.ts +0 -11
  35. package/dist/esm/hooks/setData.js +0 -46
  36. package/dist/esm/index.d.ts +0 -5
  37. package/dist/esm/index.js +0 -5
  38. package/dist/esm/mixins/debounce-mixin/DebouncedStore.d.ts +0 -18
  39. package/dist/esm/mixins/debounce-mixin/DebouncedStore.js +0 -46
  40. package/dist/esm/mixins/debounce-mixin/debounceMixin.d.ts +0 -3
  41. package/dist/esm/mixins/debounce-mixin/debounceMixin.js +0 -19
  42. package/dist/esm/mixins/debounce-mixin/index.d.ts +0 -3
  43. package/dist/esm/mixins/debounce-mixin/index.js +0 -3
  44. package/dist/esm/mixins/debounce-mixin/types.d.ts +0 -13
  45. package/dist/esm/mixins/debounce-mixin/types.js +0 -1
  46. package/dist/esm/mixins/index.d.ts +0 -1
  47. package/dist/esm/mixins/index.js +0 -1
  48. package/dist/esm/types.d.ts +0 -3
  49. package/dist/esm/types.js +0 -1
  50. package/dist/esm/typesInternal.d.ts +0 -3
  51. package/dist/esm/typesInternal.js +0 -3
  52. package/dist/esm/utils/filterQuery.d.ts +0 -8
  53. package/dist/esm/utils/filterQuery.js +0 -30
  54. package/dist/esm/utils/getItemsIsArray.d.ts +0 -10
  55. package/dist/esm/utils/getItemsIsArray.js +0 -16
  56. package/dist/esm/utils/getPaginate.d.ts +0 -9
  57. package/dist/esm/utils/getPaginate.js +0 -20
  58. package/dist/esm/utils/index.d.ts +0 -11
  59. package/dist/esm/utils/index.js +0 -11
  60. package/dist/esm/utils/isMulti.d.ts +0 -11
  61. package/dist/esm/utils/isMulti.js +0 -26
  62. package/dist/esm/utils/isPaginated.d.ts +0 -5
  63. package/dist/esm/utils/isPaginated.js +0 -11
  64. package/dist/esm/utils/markHookForSkip.d.ts +0 -7
  65. package/dist/esm/utils/markHookForSkip.js +0 -18
  66. package/dist/esm/utils/mergeQuery/index.d.ts +0 -3
  67. package/dist/esm/utils/mergeQuery/index.js +0 -3
  68. package/dist/esm/utils/mergeQuery/mergeArrays.d.ts +0 -3
  69. package/dist/esm/utils/mergeQuery/mergeArrays.js +0 -37
  70. package/dist/esm/utils/mergeQuery/mergeQuery.d.ts +0 -3
  71. package/dist/esm/utils/mergeQuery/mergeQuery.js +0 -70
  72. package/dist/esm/utils/mergeQuery/types.d.ts +0 -13
  73. package/dist/esm/utils/mergeQuery/types.js +0 -1
  74. package/dist/esm/utils/mergeQuery/utils.d.ts +0 -11
  75. package/dist/esm/utils/mergeQuery/utils.js +0 -272
  76. package/dist/esm/utils/pushSet.d.ts +0 -8
  77. package/dist/esm/utils/pushSet.js +0 -22
  78. package/dist/esm/utils/setResultEmpty.d.ts +0 -5
  79. package/dist/esm/utils/setResultEmpty.js +0 -28
  80. package/dist/esm/utils/shouldSkip.d.ts +0 -8
  81. package/dist/esm/utils/shouldSkip.js +0 -29
  82. package/dist/esm/utils/validateQueryProperty.d.ts +0 -5
  83. package/dist/esm/utils/validateQueryProperty.js +0 -23
  84. package/dist/filters/array.d.ts +0 -2
  85. package/dist/filters/array.js +0 -21
  86. package/dist/filters/index.d.ts +0 -2
  87. package/dist/filters/index.js +0 -18
  88. package/dist/filters/object.d.ts +0 -2
  89. package/dist/filters/object.js +0 -22
  90. package/dist/hooks/checkMulti.d.ts +0 -5
  91. package/dist/hooks/checkMulti.js +0 -24
  92. package/dist/hooks/createRelated.d.ts +0 -12
  93. package/dist/hooks/createRelated.js +0 -44
  94. package/dist/hooks/index.d.ts +0 -6
  95. package/dist/hooks/index.js +0 -22
  96. package/dist/hooks/onDelete.d.ts +0 -12
  97. package/dist/hooks/onDelete.js +0 -60
  98. package/dist/hooks/removeRelated.d.ts +0 -11
  99. package/dist/hooks/removeRelated.js +0 -50
  100. package/dist/hooks/runPerItem.d.ts +0 -10
  101. package/dist/hooks/runPerItem.js +0 -42
  102. package/dist/hooks/setData.d.ts +0 -11
  103. package/dist/hooks/setData.js +0 -54
  104. package/dist/index.js +0 -21
  105. package/dist/mixins/debounce-mixin/DebouncedStore.d.ts +0 -18
  106. package/dist/mixins/debounce-mixin/DebouncedStore.js +0 -65
  107. package/dist/mixins/debounce-mixin/debounceMixin.d.ts +0 -3
  108. package/dist/mixins/debounce-mixin/debounceMixin.js +0 -23
  109. package/dist/mixins/debounce-mixin/index.d.ts +0 -3
  110. package/dist/mixins/debounce-mixin/index.js +0 -19
  111. package/dist/mixins/debounce-mixin/types.d.ts +0 -13
  112. package/dist/mixins/debounce-mixin/types.js +0 -2
  113. package/dist/mixins/index.d.ts +0 -1
  114. package/dist/mixins/index.js +0 -17
  115. package/dist/types.d.ts +0 -3
  116. package/dist/types.js +0 -2
  117. package/dist/typesInternal.d.ts +0 -3
  118. package/dist/typesInternal.js +0 -4
  119. package/dist/utils/filterQuery.d.ts +0 -8
  120. package/dist/utils/filterQuery.js +0 -46
  121. package/dist/utils/getItemsIsArray.d.ts +0 -10
  122. package/dist/utils/getItemsIsArray.js +0 -20
  123. package/dist/utils/getPaginate.d.ts +0 -9
  124. package/dist/utils/getPaginate.js +0 -22
  125. package/dist/utils/index.d.ts +0 -11
  126. package/dist/utils/index.js +0 -27
  127. package/dist/utils/isMulti.d.ts +0 -11
  128. package/dist/utils/isMulti.js +0 -30
  129. package/dist/utils/isPaginated.d.ts +0 -5
  130. package/dist/utils/isPaginated.js +0 -15
  131. package/dist/utils/markHookForSkip.d.ts +0 -7
  132. package/dist/utils/markHookForSkip.js +0 -22
  133. package/dist/utils/mergeQuery/index.d.ts +0 -3
  134. package/dist/utils/mergeQuery/index.js +0 -19
  135. package/dist/utils/mergeQuery/mergeArrays.d.ts +0 -3
  136. package/dist/utils/mergeQuery/mergeArrays.js +0 -41
  137. package/dist/utils/mergeQuery/mergeQuery.d.ts +0 -3
  138. package/dist/utils/mergeQuery/mergeQuery.js +0 -77
  139. package/dist/utils/mergeQuery/types.d.ts +0 -13
  140. package/dist/utils/mergeQuery/types.js +0 -2
  141. package/dist/utils/mergeQuery/utils.d.ts +0 -11
  142. package/dist/utils/mergeQuery/utils.js +0 -287
  143. package/dist/utils/pushSet.d.ts +0 -8
  144. package/dist/utils/pushSet.js +0 -29
  145. package/dist/utils/setResultEmpty.d.ts +0 -5
  146. package/dist/utils/setResultEmpty.js +0 -32
  147. package/dist/utils/shouldSkip.d.ts +0 -8
  148. package/dist/utils/shouldSkip.js +0 -33
  149. package/dist/utils/validateQueryProperty.d.ts +0 -5
  150. package/dist/utils/validateQueryProperty.js +0 -25
@@ -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>;
@@ -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;
@@ -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;
@@ -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
- }
@@ -1,65 +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
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.DebouncedStore = exports.makeDefaultOptions = void 0;
16
- const debounce_js_1 = __importDefault(require("lodash/debounce.js"));
17
- const makeDefaultOptions = () => {
18
- return {
19
- leading: false,
20
- maxWait: undefined,
21
- trailing: true,
22
- wait: 100,
23
- };
24
- };
25
- exports.makeDefaultOptions = makeDefaultOptions;
26
- class DebouncedStore {
27
- constructor(app, options) {
28
- this._app = app;
29
- this._options = Object.assign((0, exports.makeDefaultOptions)(), options);
30
- this._queueById = {};
31
- this._isRunningById = {};
32
- //this._waitingById = {};
33
- this.add = this.debounceById(this.unbounced, this._options.wait, {
34
- leading: this._options.leading,
35
- maxWait: this._options.maxWait,
36
- trailing: this._options.trailing,
37
- });
38
- }
39
- unbounced(id, action) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- if (this._queueById[id] === undefined) {
42
- return;
43
- }
44
- delete this._queueById[id];
45
- this._isRunningById[id] = true;
46
- yield action(this._app);
47
- delete this._isRunningById[id];
48
- });
49
- }
50
- debounceById(func, wait, options) {
51
- return (id, action) => {
52
- if (typeof this._queueById[id] === "function") {
53
- return this._queueById[id](id, action);
54
- }
55
- this._queueById[id] = (0, debounce_js_1.default)((id, action) => {
56
- this.unbounced(id, action);
57
- }, wait, Object.assign(Object.assign({}, options), { leading: false })); // leading required for return promise
58
- return this._queueById[id](id, action);
59
- };
60
- }
61
- cancel(id) {
62
- delete this._queueById[id];
63
- }
64
- }
65
- exports.DebouncedStore = DebouncedStore;
@@ -1,3 +0,0 @@
1
- import type { Application } from "@feathersjs/feathers/lib";
2
- import type { InitDebounceMixinOptions } from "./types";
3
- export declare function debounceMixin(options?: Partial<InitDebounceMixinOptions>): (app: Application) => void;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.debounceMixin = void 0;
4
- const DebouncedStore_1 = require("./DebouncedStore");
5
- function debounceMixin(options) {
6
- return (app) => {
7
- options = options || {};
8
- const defaultOptions = Object.assign((0, DebouncedStore_1.makeDefaultOptions)(), options === null || options === void 0 ? void 0 : options.default);
9
- app.mixins.push((service, path) => {
10
- // if path is on blacklist, don't add debouncedStore to service
11
- if ((options === null || options === void 0 ? void 0 : options.blacklist) && options.blacklist.includes(path))
12
- return;
13
- // if service already has registered something on `debouncedStore`
14
- if (service.debouncedStore) {
15
- console.warn(`[feathers-utils] service: '${path}' already has a property 'debouncedStore'. Mixin will skip creating a new debouncedStore`);
16
- return;
17
- }
18
- const serviceOptions = Object.assign({}, defaultOptions, options === null || options === void 0 ? void 0 : options[path]);
19
- service.debouncedStore = new DebouncedStore_1.DebouncedStore(app, serviceOptions);
20
- });
21
- };
22
- }
23
- exports.debounceMixin = debounceMixin;
@@ -1,3 +0,0 @@
1
- export * from "./types";
2
- export * from "./DebouncedStore";
3
- export * from "./debounceMixin";
@@ -1,19 +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("./types"), exports);
18
- __exportStar(require("./DebouncedStore"), exports);
19
- __exportStar(require("./debounceMixin"), exports);
@@ -1,13 +0,0 @@
1
- import type { Application } from "@feathersjs/feathers";
2
- export interface InitDebounceMixinOptions {
3
- default: Partial<DebouncedStoreOptions>;
4
- blacklist: string[];
5
- [key: string]: unknown;
6
- }
7
- export type DebouncedFunctionApp = (app?: Application) => void | Promise<void>;
8
- export interface DebouncedStoreOptions {
9
- leading: boolean;
10
- maxWait: number | undefined;
11
- trailing: boolean;
12
- wait: number;
13
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +0,0 @@
1
- export * from "./debounce-mixin";
@@ -1,17 +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("./debounce-mixin"), exports);
package/dist/types.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import type { HookContext } from "@feathersjs/feathers";
2
- export type Predicate<T = any> = (item: T) => boolean;
3
- export type PredicateWithContext<T = any> = (item: T, context: HookContext) => boolean;
package/dist/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +0,0 @@
1
- export type MaybeArray<T> = T | T[];
2
- export type Promisable<T> = T | Promise<T>;
3
- export type Path = Array<string | number>;
@@ -1,4 +0,0 @@
1
- "use strict";
2
- // here are types that are not meant to be exported!
3
- // just for internal use of this package
4
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,8 +0,0 @@
1
- import type { FilterQueryOptions as PlainFilterQueryOptions, AdapterBase } from "@feathersjs/adapter-commons";
2
- import type { Query } from "@feathersjs/feathers";
3
- export interface FilterQueryOptions<T> {
4
- service?: AdapterBase<T>;
5
- operators?: PlainFilterQueryOptions["operators"];
6
- filters?: PlainFilterQueryOptions["filters"];
7
- }
8
- export declare function filterQuery<T>(query: Query, _options?: FilterQueryOptions<T>): any;
@@ -1,46 +0,0 @@
1
- "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.filterQuery = void 0;
15
- const adapter_commons_1 = require("@feathersjs/adapter-commons");
16
- function filterQuery(query, _options) {
17
- var _a, _b;
18
- query = query || {};
19
- _options = _options || {};
20
- const { service } = _options, options = __rest(_options, ["service"]);
21
- if (service) {
22
- const operators = options.operators
23
- ? options.operators
24
- : (_a = service.options) === null || _a === void 0 ? void 0 : _a.operators;
25
- const filters = options.filters
26
- ? options.filters
27
- : (_b = service.options) === null || _b === void 0 ? void 0 : _b.filters;
28
- const optionsForFilterQuery = {};
29
- if (operators) {
30
- optionsForFilterQuery.operators = operators;
31
- }
32
- if (filters) {
33
- optionsForFilterQuery.filters = filters;
34
- }
35
- if (service &&
36
- "filterQuery" in service &&
37
- typeof service.filterQuery === "function") {
38
- return service.filterQuery({ query }, optionsForFilterQuery);
39
- }
40
- else {
41
- return (0, adapter_commons_1.filterQuery)(query, optionsForFilterQuery);
42
- }
43
- }
44
- return (0, adapter_commons_1.filterQuery)(query, options);
45
- }
46
- exports.filterQuery = filterQuery;
@@ -1,10 +0,0 @@
1
- import type { HookContext } from "@feathersjs/feathers";
2
- export interface GetItemsIsArrayResult<T = any> {
3
- items: T[];
4
- isArray: boolean;
5
- }
6
- /**
7
- * util to get items from context, return it as an array, no matter if it is an array or not
8
- * uses `context.result` if existent. uses `context.data` otherwise
9
- */
10
- export declare const getItemsIsArray: <T = any, H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any> = HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(context: H) => GetItemsIsArrayResult<T>;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getItemsIsArray = void 0;
4
- /**
5
- * util to get items from context, return it as an array, no matter if it is an array or not
6
- * uses `context.result` if existent. uses `context.data` otherwise
7
- */
8
- const getItemsIsArray = (context) => {
9
- let itemOrItems = context.result !== undefined ? context.result : context.data;
10
- itemOrItems =
11
- itemOrItems && context.method === "find"
12
- ? itemOrItems.data || itemOrItems
13
- : itemOrItems;
14
- const isArray = Array.isArray(itemOrItems);
15
- return {
16
- items: isArray ? itemOrItems : itemOrItems != null ? [itemOrItems] : [],
17
- isArray,
18
- };
19
- };
20
- exports.getItemsIsArray = getItemsIsArray;
@@ -1,9 +0,0 @@
1
- import type { PaginationOptions } from "@feathersjs/adapter-commons";
2
- import type { HookContext } from "@feathersjs/feathers";
3
- /**
4
- * util to get paginate options from context
5
- * 1. it uses `context.params.paginate` if it exists
6
- * 2. it uses `service.options.paginate` if it exists
7
- * 3. it uses `context.params.adapter` if it exists
8
- */
9
- export declare const getPaginate: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any> = HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(context: H) => PaginationOptions | undefined;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPaginate = void 0;
4
- /**
5
- * util to get paginate options from context
6
- * 1. it uses `context.params.paginate` if it exists
7
- * 2. it uses `service.options.paginate` if it exists
8
- * 3. it uses `context.params.adapter` if it exists
9
- */
10
- const getPaginate = (context) => {
11
- var _a;
12
- if (Object.prototype.hasOwnProperty.call(context.params, "paginate")) {
13
- return context.params.paginate || undefined;
14
- }
15
- if (context.params.paginate === false) {
16
- return undefined;
17
- }
18
- let options = ((_a = context.service) === null || _a === void 0 ? void 0 : _a.options) || {};
19
- options = Object.assign(Object.assign({}, options), context.params.adapter);
20
- return options.paginate || undefined;
21
- };
22
- exports.getPaginate = getPaginate;
@@ -1,11 +0,0 @@
1
- export * from "./mergeQuery";
2
- export * from "./filterQuery";
3
- export * from "./getItemsIsArray";
4
- export * from "./getPaginate";
5
- export * from "./isMulti";
6
- export * from "./isPaginated";
7
- export * from "./markHookForSkip";
8
- export * from "./pushSet";
9
- export * from "./setResultEmpty";
10
- export * from "./shouldSkip";
11
- export * from "./validateQueryProperty";
@@ -1,27 +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("./mergeQuery"), exports);
18
- __exportStar(require("./filterQuery"), exports);
19
- __exportStar(require("./getItemsIsArray"), exports);
20
- __exportStar(require("./getPaginate"), exports);
21
- __exportStar(require("./isMulti"), exports);
22
- __exportStar(require("./isPaginated"), exports);
23
- __exportStar(require("./markHookForSkip"), exports);
24
- __exportStar(require("./pushSet"), exports);
25
- __exportStar(require("./setResultEmpty"), exports);
26
- __exportStar(require("./shouldSkip"), exports);
27
- __exportStar(require("./validateQueryProperty"), exports);
@@ -1,11 +0,0 @@
1
- import type { HookContext } from "@feathersjs/feathers";
2
- /**
3
- * util to check if a hook is a multi hook:
4
- * - find: true
5
- * - get: false
6
- * - create: `context.data` is an array
7
- * - update: false
8
- * - patch: `context.id == null`
9
- * - remove: `context.id == null`
10
- */
11
- export declare const isMulti: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any> = HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(context: H) => boolean;