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,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,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,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
|
-
}
|
package/dist/mixins/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./debounce-mixin";
|
package/dist/mixins/index.js
DELETED
|
@@ -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
package/dist/types.js
DELETED
package/dist/typesInternal.d.ts
DELETED
package/dist/typesInternal.js
DELETED
|
@@ -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;
|
package/dist/utils/index.d.ts
DELETED
|
@@ -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";
|
package/dist/utils/index.js
DELETED
|
@@ -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);
|
package/dist/utils/isMulti.d.ts
DELETED
|
@@ -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;
|
package/dist/utils/isMulti.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isMulti = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* util to check if a hook is a multi hook:
|
|
6
|
-
* - find: true
|
|
7
|
-
* - get: false
|
|
8
|
-
* - create: `context.data` is an array
|
|
9
|
-
* - update: false
|
|
10
|
-
* - patch: `context.id == null`
|
|
11
|
-
* - remove: `context.id == null`
|
|
12
|
-
*/
|
|
13
|
-
const isMulti = (context) => {
|
|
14
|
-
const { method } = context;
|
|
15
|
-
if (method === "find") {
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
else if (["patch", "remove"].includes(method)) {
|
|
19
|
-
return context.id == null;
|
|
20
|
-
}
|
|
21
|
-
else if (method === "create") {
|
|
22
|
-
const items = context.type === "before" ? context.data : context.result;
|
|
23
|
-
return Array.isArray(items);
|
|
24
|
-
}
|
|
25
|
-
else if (["get", "update"].includes(method)) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
return false;
|
|
29
|
-
};
|
|
30
|
-
exports.isMulti = isMulti;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { HookContext } from "@feathersjs/feathers";
|
|
2
|
-
/**
|
|
3
|
-
* util to check if a hook is a paginated hook using `getPaginate`
|
|
4
|
-
*/
|
|
5
|
-
export declare const isPaginated: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any> = HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(context: H) => boolean;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isPaginated = void 0;
|
|
4
|
-
const getPaginate_1 = require("./getPaginate");
|
|
5
|
-
/**
|
|
6
|
-
* util to check if a hook is a paginated hook using `getPaginate`
|
|
7
|
-
*/
|
|
8
|
-
const isPaginated = (context) => {
|
|
9
|
-
if (context.params.paginate === false || context.method !== "find") {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
const paginate = (0, getPaginate_1.getPaginate)(context);
|
|
13
|
-
return !!paginate;
|
|
14
|
-
};
|
|
15
|
-
exports.isPaginated = isPaginated;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { HookContext } from "@feathersjs/feathers";
|
|
2
|
-
import type { HookType } from "feathers-hooks-common";
|
|
3
|
-
import type { MaybeArray } from "../typesInternal";
|
|
4
|
-
/**
|
|
5
|
-
* util to mark a hook for skip, has to be used with `shouldSkip`
|
|
6
|
-
*/
|
|
7
|
-
export declare function markHookForSkip<H extends HookContext = HookContext>(hookName: string, type: "all" | MaybeArray<HookType>, context?: H): H | undefined;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.markHookForSkip = void 0;
|
|
4
|
-
const pushSet_1 = require("./pushSet");
|
|
5
|
-
/**
|
|
6
|
-
* util to mark a hook for skip, has to be used with `shouldSkip`
|
|
7
|
-
*/
|
|
8
|
-
function markHookForSkip(hookName, type, context) {
|
|
9
|
-
// @ts-expect-error context is not of type 'H'
|
|
10
|
-
context = context || {};
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
12
|
-
const params = context.params || {};
|
|
13
|
-
const types = Array.isArray(type) ? type : [type];
|
|
14
|
-
types.forEach((t) => {
|
|
15
|
-
const combinedName = t === "all" ? hookName : `${type}:${hookName}`;
|
|
16
|
-
(0, pushSet_1.pushSet)(params, ["skipHooks"], combinedName, { unique: true });
|
|
17
|
-
});
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
19
|
-
context.params = params;
|
|
20
|
-
return context;
|
|
21
|
-
}
|
|
22
|
-
exports.markHookForSkip = markHookForSkip;
|
|
@@ -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("./mergeArrays"), exports);
|
|
18
|
-
__exportStar(require("./mergeQuery"), exports);
|
|
19
|
-
__exportStar(require("./types"), exports);
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { Path } from "../../typesInternal";
|
|
2
|
-
import type { Handle, ActionOnEmptyIntersect } from "./types";
|
|
3
|
-
export declare function mergeArrays<T>(targetArr: T[], sourceArr: T[], handle: Handle, prependKey?: Path, actionOnEmptyIntersect?: ActionOnEmptyIntersect): T[] | undefined;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mergeArrays = void 0;
|
|
4
|
-
function mergeArrays(targetArr, sourceArr, handle, prependKey, actionOnEmptyIntersect) {
|
|
5
|
-
if (!sourceArr && !targetArr) {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
if (handle === "target") {
|
|
9
|
-
return targetArr;
|
|
10
|
-
}
|
|
11
|
-
else if (handle === "source") {
|
|
12
|
-
return sourceArr;
|
|
13
|
-
}
|
|
14
|
-
else if (handle === "combine") {
|
|
15
|
-
if (!sourceArr || !Array.isArray(sourceArr)) {
|
|
16
|
-
return targetArr;
|
|
17
|
-
}
|
|
18
|
-
if (!targetArr || !Array.isArray(targetArr)) {
|
|
19
|
-
return sourceArr;
|
|
20
|
-
}
|
|
21
|
-
const arr = targetArr.concat(sourceArr);
|
|
22
|
-
return [...new Set(arr)];
|
|
23
|
-
}
|
|
24
|
-
else if (handle === "intersect" || handle === "intersectOrFull") {
|
|
25
|
-
const targetIsArray = !targetArr || !Array.isArray(targetArr);
|
|
26
|
-
const sourceIsArray = !sourceArr || !Array.isArray(sourceArr);
|
|
27
|
-
if ((targetIsArray || sourceIsArray) && handle === "intersect") {
|
|
28
|
-
if (actionOnEmptyIntersect) {
|
|
29
|
-
actionOnEmptyIntersect(targetArr, sourceArr, prependKey || []);
|
|
30
|
-
}
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
if (handle === "intersectOrFull") {
|
|
34
|
-
const val = !targetIsArray ? targetArr : sourceArr;
|
|
35
|
-
return val;
|
|
36
|
-
}
|
|
37
|
-
return targetArr.filter((val) => sourceArr.includes(val));
|
|
38
|
-
}
|
|
39
|
-
return undefined;
|
|
40
|
-
}
|
|
41
|
-
exports.mergeArrays = mergeArrays;
|
|
@@ -1,77 +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.mergeQuery = void 0;
|
|
7
|
-
const merge_js_1 = __importDefault(require("lodash/merge.js"));
|
|
8
|
-
const isEmpty_js_1 = __importDefault(require("lodash/isEmpty.js"));
|
|
9
|
-
const utils_1 = require("./utils");
|
|
10
|
-
const filterQuery_1 = require("../filterQuery");
|
|
11
|
-
function mergeQuery(target, source, options) {
|
|
12
|
-
const fullOptions = (0, utils_1.makeDefaultOptions)(options);
|
|
13
|
-
const { filters: targetFilters, query: targetQuery } = (0, filterQuery_1.filterQuery)(target, {
|
|
14
|
-
operators: fullOptions.operators,
|
|
15
|
-
filters: fullOptions.filters,
|
|
16
|
-
service: fullOptions.service,
|
|
17
|
-
});
|
|
18
|
-
(0, utils_1.moveProperty)(targetFilters, targetQuery, "$or");
|
|
19
|
-
(0, utils_1.moveProperty)(targetFilters, targetQuery, "$and");
|
|
20
|
-
if (target.$limit) {
|
|
21
|
-
targetFilters.$limit = target.$limit;
|
|
22
|
-
}
|
|
23
|
-
let {
|
|
24
|
-
// eslint-disable-next-line prefer-const
|
|
25
|
-
filters: sourceFilters, query: sourceQuery, } = (0, filterQuery_1.filterQuery)(source, {
|
|
26
|
-
operators: fullOptions.operators,
|
|
27
|
-
filters: fullOptions.filters,
|
|
28
|
-
service: fullOptions.service,
|
|
29
|
-
});
|
|
30
|
-
(0, utils_1.moveProperty)(sourceFilters, sourceQuery, "$or");
|
|
31
|
-
(0, utils_1.moveProperty)(sourceFilters, sourceQuery, "$and");
|
|
32
|
-
if (source.$limit) {
|
|
33
|
-
sourceFilters.$limit = source.$limit;
|
|
34
|
-
}
|
|
35
|
-
//#region filters
|
|
36
|
-
if (target &&
|
|
37
|
-
!Object.prototype.hasOwnProperty.call(target, "$limit") &&
|
|
38
|
-
Object.prototype.hasOwnProperty.call(targetFilters, "$limit")) {
|
|
39
|
-
delete targetFilters.$limit;
|
|
40
|
-
}
|
|
41
|
-
if (source &&
|
|
42
|
-
!Object.prototype.hasOwnProperty.call(source, "$limit") &&
|
|
43
|
-
Object.prototype.hasOwnProperty.call(sourceFilters, "$limit")) {
|
|
44
|
-
delete sourceFilters.$limit;
|
|
45
|
-
}
|
|
46
|
-
(0, utils_1.handleArray)(targetFilters, sourceFilters, ["$select"], fullOptions);
|
|
47
|
-
// remaining filters
|
|
48
|
-
delete sourceFilters["$select"];
|
|
49
|
-
(0, merge_js_1.default)(targetFilters, sourceFilters);
|
|
50
|
-
//#endregion
|
|
51
|
-
//#region '$or' / '$and'
|
|
52
|
-
if ((options === null || options === void 0 ? void 0 : options.useLogicalConjunction) &&
|
|
53
|
-
(options.defaultHandle === "combine" ||
|
|
54
|
-
options.defaultHandle === "intersect") &&
|
|
55
|
-
!(0, isEmpty_js_1.default)(targetQuery)) {
|
|
56
|
-
const logicalOp = options.defaultHandle === "combine" ? "$or" : "$and";
|
|
57
|
-
if (Object.prototype.hasOwnProperty.call(sourceQuery, logicalOp)) {
|
|
58
|
-
// omit '$or'/'$and' and put all other props into '$or'/'$and'
|
|
59
|
-
const andOr = sourceQuery[logicalOp];
|
|
60
|
-
delete sourceQuery[logicalOp];
|
|
61
|
-
andOr.push(sourceQuery);
|
|
62
|
-
sourceQuery = { [logicalOp]: andOr };
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
sourceQuery = { [logicalOp]: [sourceQuery] };
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
//#endregion
|
|
69
|
-
const keys = Object.keys(sourceQuery);
|
|
70
|
-
for (let i = 0, n = keys.length; i < n; i++) {
|
|
71
|
-
const key = keys[i];
|
|
72
|
-
(0, utils_1.handleCircular)(targetQuery, sourceQuery, [key], fullOptions);
|
|
73
|
-
}
|
|
74
|
-
const result = Object.assign({}, targetFilters, targetQuery);
|
|
75
|
-
return result;
|
|
76
|
-
}
|
|
77
|
-
exports.mergeQuery = mergeQuery;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Path } from "../../typesInternal";
|
|
2
|
-
import type { FilterQueryOptions } from "../filterQuery";
|
|
3
|
-
export type Handle = "target" | "source" | "combine" | "intersect" | "intersectOrFull";
|
|
4
|
-
export type FirstLast = "first" | "last";
|
|
5
|
-
export type ActionOnEmptyIntersect = (target: unknown, source: unknown, prependKey: Path) => void;
|
|
6
|
-
export interface MergeQueryOptions<T> extends FilterQueryOptions<T> {
|
|
7
|
-
defaultHandle: Handle;
|
|
8
|
-
actionOnEmptyIntersect: ActionOnEmptyIntersect;
|
|
9
|
-
useLogicalConjunction: boolean;
|
|
10
|
-
handle?: {
|
|
11
|
-
[key: string]: Handle;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Path } from "../../typesInternal";
|
|
2
|
-
import type { MergeQueryOptions } from "./types";
|
|
3
|
-
export declare const hasOwnProperty: (obj: Record<string, unknown>, key: string) => boolean;
|
|
4
|
-
export declare function handleArray<T>(target: Record<string, unknown>, source: Record<string, unknown>, key: Path, options: MergeQueryOptions<T>): void;
|
|
5
|
-
export declare function handleCircular<T>(target: Record<string, unknown>, source: Record<string, unknown>, prependKey: Path, options: MergeQueryOptions<T>): void;
|
|
6
|
-
export declare function makeDefaultOptions<T>(options?: Partial<MergeQueryOptions<T>>): MergeQueryOptions<T>;
|
|
7
|
-
export declare function moveProperty(source: Record<string, any>, target: Record<string, any>, key: string): void;
|
|
8
|
-
export declare function getParentProp(target: Record<string, unknown>, path: Path): any;
|
|
9
|
-
export declare function cleanOr(target: Record<string, unknown>[]): Record<string, unknown>[] | undefined;
|
|
10
|
-
export declare function cleanAnd(target: Record<string, unknown>[]): Record<string, unknown>[] | undefined;
|
|
11
|
-
export declare function arrayWithoutDuplicates<T>(target: T[]): T[];
|