feathers-utils 3.1.3 → 4.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/README.md +1 -0
- package/dist/index.cjs +157 -192
- package/dist/index.d.cts +56 -39
- package/dist/index.d.mts +56 -39
- package/dist/index.d.ts +56 -39
- package/dist/index.mjs +154 -190
- package/package.json +2 -2
- package/src/utils/defineHooks.ts +16 -0
- package/src/utils/filterQuery.ts +92 -39
- package/src/utils/index.ts +4 -3
- package/src/utils/mergeQuery/mergeQuery.ts +5 -45
- package/src/utils/mergeQuery/types.ts +1 -2
- package/src/utils/mergeQuery/utils.ts +9 -9
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const errors = require('@feathersjs/errors');
|
|
4
|
+
const _isEqual = require('lodash/isEqual.js');
|
|
5
|
+
const _get = require('lodash/get.js');
|
|
6
|
+
const _set = require('lodash/set.js');
|
|
4
7
|
const _merge = require('lodash/merge.js');
|
|
5
8
|
const _isEmpty = require('lodash/isEmpty.js');
|
|
6
|
-
const _get = require('lodash/get.js');
|
|
7
9
|
const _has = require('lodash/has.js');
|
|
8
|
-
const _set = require('lodash/set.js');
|
|
9
10
|
const _uniqWith = require('lodash/uniqWith.js');
|
|
10
11
|
const fastEquals = require('fast-equals');
|
|
11
|
-
const adapterCommons = require('@feathersjs/adapter-commons');
|
|
12
|
-
const _isEqual = require('lodash/isEqual.js');
|
|
13
12
|
const commons = require('@feathersjs/commons');
|
|
14
13
|
const feathersHooksCommon = require('feathers-hooks-common');
|
|
15
14
|
const _debounce = require('lodash/debounce.js');
|
|
@@ -17,16 +16,130 @@ const _isObject = require('lodash/isObject.js');
|
|
|
17
16
|
|
|
18
17
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
19
18
|
|
|
19
|
+
const _isEqual__default = /*#__PURE__*/_interopDefaultCompat(_isEqual);
|
|
20
|
+
const _get__default = /*#__PURE__*/_interopDefaultCompat(_get);
|
|
21
|
+
const _set__default = /*#__PURE__*/_interopDefaultCompat(_set);
|
|
20
22
|
const _merge__default = /*#__PURE__*/_interopDefaultCompat(_merge);
|
|
21
23
|
const _isEmpty__default = /*#__PURE__*/_interopDefaultCompat(_isEmpty);
|
|
22
|
-
const _get__default = /*#__PURE__*/_interopDefaultCompat(_get);
|
|
23
24
|
const _has__default = /*#__PURE__*/_interopDefaultCompat(_has);
|
|
24
|
-
const _set__default = /*#__PURE__*/_interopDefaultCompat(_set);
|
|
25
25
|
const _uniqWith__default = /*#__PURE__*/_interopDefaultCompat(_uniqWith);
|
|
26
|
-
const _isEqual__default = /*#__PURE__*/_interopDefaultCompat(_isEqual);
|
|
27
26
|
const _debounce__default = /*#__PURE__*/_interopDefaultCompat(_debounce);
|
|
28
27
|
const _isObject__default = /*#__PURE__*/_interopDefaultCompat(_isObject);
|
|
29
28
|
|
|
29
|
+
function defineHooks(hooks) {
|
|
30
|
+
return hooks;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function filterQuery(providedQuery) {
|
|
34
|
+
providedQuery ?? (providedQuery = {});
|
|
35
|
+
const { $select, $limit, $skip, $sort, ...query } = providedQuery;
|
|
36
|
+
const result = { query };
|
|
37
|
+
if ("$select" in providedQuery) {
|
|
38
|
+
result.$select = $select;
|
|
39
|
+
}
|
|
40
|
+
if ("$limit" in providedQuery) {
|
|
41
|
+
result.$limit = $limit;
|
|
42
|
+
}
|
|
43
|
+
if ("$skip" in providedQuery) {
|
|
44
|
+
result.$skip = $skip;
|
|
45
|
+
}
|
|
46
|
+
if ("$sort" in providedQuery) {
|
|
47
|
+
result.$sort = $sort;
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const getItemsIsArray = (context, options) => {
|
|
53
|
+
const { from = "automatic" } = options || {};
|
|
54
|
+
let itemOrItems;
|
|
55
|
+
if (from === "automatic") {
|
|
56
|
+
itemOrItems = context.type === "before" ? context.data : context.result;
|
|
57
|
+
} else if (from === "data") {
|
|
58
|
+
itemOrItems = context.data;
|
|
59
|
+
} else if (from === "result") {
|
|
60
|
+
itemOrItems = context.result;
|
|
61
|
+
}
|
|
62
|
+
if ((from === "automatic" || from === "result") && context.type === "after") {
|
|
63
|
+
itemOrItems = itemOrItems && context.method === "find" ? itemOrItems.data || itemOrItems : itemOrItems;
|
|
64
|
+
}
|
|
65
|
+
const isArray = Array.isArray(itemOrItems);
|
|
66
|
+
return {
|
|
67
|
+
items: isArray ? itemOrItems : itemOrItems != null ? [itemOrItems] : [],
|
|
68
|
+
isArray
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const hasOwnProperty = (obj, ...keys) => {
|
|
73
|
+
return keys.some((x) => Object.prototype.hasOwnProperty.call(obj, x));
|
|
74
|
+
};
|
|
75
|
+
const isPlainObject$1 = (value) => value && [void 0, Object].includes(value.constructor);
|
|
76
|
+
|
|
77
|
+
const getPaginate = (context) => {
|
|
78
|
+
if (hasOwnProperty(context.params, "paginate")) {
|
|
79
|
+
return context.params.paginate || void 0;
|
|
80
|
+
}
|
|
81
|
+
if (context.params.paginate === false) {
|
|
82
|
+
return void 0;
|
|
83
|
+
}
|
|
84
|
+
let options = context.service?.options || {};
|
|
85
|
+
options = {
|
|
86
|
+
...options,
|
|
87
|
+
...context.params.adapter
|
|
88
|
+
};
|
|
89
|
+
return options.paginate || void 0;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const isMulti = (context) => {
|
|
93
|
+
const { method } = context;
|
|
94
|
+
if (method === "find") {
|
|
95
|
+
return true;
|
|
96
|
+
} else if (["patch", "remove"].includes(method)) {
|
|
97
|
+
return context.id == null;
|
|
98
|
+
} else if (method === "create") {
|
|
99
|
+
const items = context.type === "before" ? context.data : context.result;
|
|
100
|
+
return Array.isArray(items);
|
|
101
|
+
} else if (["get", "update"].includes(method)) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
return false;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const isPaginated = (context) => {
|
|
108
|
+
if (context.params.paginate === false || context.method !== "find") {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
const paginate = getPaginate(context);
|
|
112
|
+
return !!paginate;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const pushSet = (obj, path, val, options) => {
|
|
116
|
+
options = options || {};
|
|
117
|
+
let arr = _get__default(obj, path);
|
|
118
|
+
if (!arr || !Array.isArray(arr)) {
|
|
119
|
+
arr = [val];
|
|
120
|
+
_set__default(obj, path, arr);
|
|
121
|
+
return arr;
|
|
122
|
+
} else {
|
|
123
|
+
if (options.unique && arr.some((x) => _isEqual__default(x, val))) {
|
|
124
|
+
return arr;
|
|
125
|
+
}
|
|
126
|
+
arr.push(val);
|
|
127
|
+
return arr;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
function markHookForSkip(hookName, type, context) {
|
|
132
|
+
context = context || {};
|
|
133
|
+
const params = context.params || {};
|
|
134
|
+
const types = Array.isArray(type) ? type : [type];
|
|
135
|
+
types.forEach((t) => {
|
|
136
|
+
const combinedName = t === "all" ? hookName : `${type}:${hookName}`;
|
|
137
|
+
pushSet(params, ["skipHooks"], combinedName, { unique: true });
|
|
138
|
+
});
|
|
139
|
+
context.params = params;
|
|
140
|
+
return context;
|
|
141
|
+
}
|
|
142
|
+
|
|
30
143
|
function mergeArrays(targetArr, sourceArr, handle, prependKey, actionOnEmptyIntersect) {
|
|
31
144
|
if (!sourceArr && !targetArr) {
|
|
32
145
|
return;
|
|
@@ -66,11 +179,6 @@ function mergeArrays(targetArr, sourceArr, handle, prependKey, actionOnEmptyInte
|
|
|
66
179
|
return void 0;
|
|
67
180
|
}
|
|
68
181
|
|
|
69
|
-
const hasOwnProperty = (obj, ...keys) => {
|
|
70
|
-
return keys.some((x) => Object.prototype.hasOwnProperty.call(obj, x));
|
|
71
|
-
};
|
|
72
|
-
const isPlainObject$1 = (value) => value && [void 0, Object].includes(value.constructor);
|
|
73
|
-
|
|
74
182
|
function handleArray(target, source, key, options) {
|
|
75
183
|
const targetVal = _get__default(target, key);
|
|
76
184
|
const sourceVal = _get__default(source, key);
|
|
@@ -284,15 +392,6 @@ function makeDefaultOptions$1(options) {
|
|
|
284
392
|
}
|
|
285
393
|
return options;
|
|
286
394
|
}
|
|
287
|
-
function moveProperty(from, to, ...keys) {
|
|
288
|
-
keys.forEach((key) => {
|
|
289
|
-
if (!hasOwnProperty(from, key)) {
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
to[key] = from[key];
|
|
293
|
-
delete from[key];
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
395
|
function getParentProp(target, path) {
|
|
297
396
|
if (path.length <= 1) {
|
|
298
397
|
return target;
|
|
@@ -362,59 +461,10 @@ function areQueriesOverlapping(target, source) {
|
|
|
362
461
|
return false;
|
|
363
462
|
}
|
|
364
463
|
|
|
365
|
-
function filterQuery(query, _options) {
|
|
366
|
-
query = query || {};
|
|
367
|
-
_options = _options || {};
|
|
368
|
-
const { service, ...options } = _options;
|
|
369
|
-
if (service) {
|
|
370
|
-
const operators = options.operators ? options.operators : service.options?.operators;
|
|
371
|
-
const filters = options.filters ? options.filters : service.options?.filters;
|
|
372
|
-
const optionsForFilterQuery = {};
|
|
373
|
-
if (operators) {
|
|
374
|
-
optionsForFilterQuery.operators = operators;
|
|
375
|
-
}
|
|
376
|
-
if (filters) {
|
|
377
|
-
optionsForFilterQuery.filters = filters;
|
|
378
|
-
}
|
|
379
|
-
if (service && "filterQuery" in service && typeof service.filterQuery === "function") {
|
|
380
|
-
return service.filterQuery({ query }, optionsForFilterQuery);
|
|
381
|
-
} else {
|
|
382
|
-
return adapterCommons.filterQuery(query, optionsForFilterQuery);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
return adapterCommons.filterQuery(query, options);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
464
|
function mergeQuery(target, source, _options) {
|
|
389
465
|
const options = makeDefaultOptions$1(_options);
|
|
390
|
-
const {
|
|
391
|
-
|
|
392
|
-
filters: options.filters,
|
|
393
|
-
service: options.service
|
|
394
|
-
});
|
|
395
|
-
moveProperty(targetFilters, targetQuery, "$or", "$and");
|
|
396
|
-
if ("$limit" in target) {
|
|
397
|
-
targetFilters.$limit = target.$limit;
|
|
398
|
-
}
|
|
399
|
-
let {
|
|
400
|
-
// eslint-disable-next-line prefer-const
|
|
401
|
-
filters: sourceFilters,
|
|
402
|
-
query: sourceQuery
|
|
403
|
-
} = filterQuery(source, {
|
|
404
|
-
operators: options.operators,
|
|
405
|
-
filters: options.filters,
|
|
406
|
-
service: options.service
|
|
407
|
-
});
|
|
408
|
-
moveProperty(sourceFilters, sourceQuery, "$or", "$and");
|
|
409
|
-
if (source.$limit) {
|
|
410
|
-
sourceFilters.$limit = source.$limit;
|
|
411
|
-
}
|
|
412
|
-
if (target && !hasOwnProperty(target, "$limit") && hasOwnProperty(targetFilters, "$limit")) {
|
|
413
|
-
delete targetFilters.$limit;
|
|
414
|
-
}
|
|
415
|
-
if (source && !hasOwnProperty(source, "$limit") && hasOwnProperty(sourceFilters, "$limit")) {
|
|
416
|
-
delete sourceFilters.$limit;
|
|
417
|
-
}
|
|
466
|
+
const { query: targetQuery, ...targetFilters } = filterQuery(target);
|
|
467
|
+
let { query: sourceQuery, ...sourceFilters } = filterQuery(source);
|
|
418
468
|
handleArray(targetFilters, sourceFilters, ["$select"], options);
|
|
419
469
|
delete sourceFilters["$select"];
|
|
420
470
|
_merge__default(targetFilters, sourceFilters);
|
|
@@ -454,92 +504,40 @@ function mergeQuery(target, source, _options) {
|
|
|
454
504
|
};
|
|
455
505
|
}
|
|
456
506
|
|
|
457
|
-
const
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
if (
|
|
461
|
-
|
|
462
|
-
} else if (from === "data") {
|
|
463
|
-
itemOrItems = context.data;
|
|
464
|
-
} else if (from === "result") {
|
|
465
|
-
itemOrItems = context.result;
|
|
466
|
-
}
|
|
467
|
-
if ((from === "automatic" || from === "result") && context.type === "after") {
|
|
468
|
-
itemOrItems = itemOrItems && context.method === "find" ? itemOrItems.data || itemOrItems : itemOrItems;
|
|
469
|
-
}
|
|
470
|
-
const isArray = Array.isArray(itemOrItems);
|
|
471
|
-
return {
|
|
472
|
-
items: isArray ? itemOrItems : itemOrItems != null ? [itemOrItems] : [],
|
|
473
|
-
isArray
|
|
474
|
-
};
|
|
475
|
-
};
|
|
476
|
-
|
|
477
|
-
const getPaginate = (context) => {
|
|
478
|
-
if (hasOwnProperty(context.params, "paginate")) {
|
|
479
|
-
return context.params.paginate || void 0;
|
|
480
|
-
}
|
|
481
|
-
if (context.params.paginate === false) {
|
|
482
|
-
return void 0;
|
|
507
|
+
const setQueryKeySafely = (params, key, value, operator = "$eq", options) => {
|
|
508
|
+
var _a;
|
|
509
|
+
const { mutate = false } = options || {};
|
|
510
|
+
if (!mutate) {
|
|
511
|
+
params = structuredClone(params);
|
|
483
512
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
...options,
|
|
487
|
-
...context.params.adapter
|
|
488
|
-
};
|
|
489
|
-
return options.paginate || void 0;
|
|
490
|
-
};
|
|
491
|
-
|
|
492
|
-
const isMulti = (context) => {
|
|
493
|
-
const { method } = context;
|
|
494
|
-
if (method === "find") {
|
|
495
|
-
return true;
|
|
496
|
-
} else if (["patch", "remove"].includes(method)) {
|
|
497
|
-
return context.id == null;
|
|
498
|
-
} else if (method === "create") {
|
|
499
|
-
const items = context.type === "before" ? context.data : context.result;
|
|
500
|
-
return Array.isArray(items);
|
|
501
|
-
} else if (["get", "update"].includes(method)) {
|
|
502
|
-
return false;
|
|
513
|
+
if (!params.query) {
|
|
514
|
+
params.query = {};
|
|
503
515
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
516
|
+
if (!(key in params.query)) {
|
|
517
|
+
if (operator === "$eq") {
|
|
518
|
+
params.query[key] = value;
|
|
519
|
+
} else {
|
|
520
|
+
params.query[key] = {
|
|
521
|
+
[operator]: value
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
return params;
|
|
510
525
|
}
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
};
|
|
514
|
-
|
|
515
|
-
const pushSet = (obj, path, val, options) => {
|
|
516
|
-
options = options || {};
|
|
517
|
-
let arr = _get__default(obj, path);
|
|
518
|
-
if (!arr || !Array.isArray(arr)) {
|
|
519
|
-
arr = [val];
|
|
520
|
-
_set__default(obj, path, arr);
|
|
521
|
-
return arr;
|
|
526
|
+
if (isPlainObject$1(params.query[key]) && !(operator in params.query[key])) {
|
|
527
|
+
params.query[key][operator] = value;
|
|
522
528
|
} else {
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
529
|
+
(_a = params.query).$and ?? (_a.$and = []);
|
|
530
|
+
params.query.$and.push(
|
|
531
|
+
operator === "$eq" ? { [key]: value } : {
|
|
532
|
+
[key]: {
|
|
533
|
+
[operator]: value
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
);
|
|
528
537
|
}
|
|
538
|
+
return params;
|
|
529
539
|
};
|
|
530
540
|
|
|
531
|
-
function markHookForSkip(hookName, type, context) {
|
|
532
|
-
context = context || {};
|
|
533
|
-
const params = context.params || {};
|
|
534
|
-
const types = Array.isArray(type) ? type : [type];
|
|
535
|
-
types.forEach((t) => {
|
|
536
|
-
const combinedName = t === "all" ? hookName : `${type}:${hookName}`;
|
|
537
|
-
pushSet(params, ["skipHooks"], combinedName, { unique: true });
|
|
538
|
-
});
|
|
539
|
-
context.params = params;
|
|
540
|
-
return context;
|
|
541
|
-
}
|
|
542
|
-
|
|
543
541
|
const setResultEmpty = (context) => {
|
|
544
542
|
if (context.result) {
|
|
545
543
|
return context;
|
|
@@ -583,6 +581,13 @@ const shouldSkip = (hookName, context, options) => {
|
|
|
583
581
|
return false;
|
|
584
582
|
};
|
|
585
583
|
|
|
584
|
+
const toJSON = (context) => {
|
|
585
|
+
if (context.toJSON) {
|
|
586
|
+
return context.toJSON();
|
|
587
|
+
}
|
|
588
|
+
return context;
|
|
589
|
+
};
|
|
590
|
+
|
|
586
591
|
const isPlainObject = (value) => commons._.isObject(value) && value.constructor === {}.constructor;
|
|
587
592
|
const validateQueryProperty = (query, operators = []) => {
|
|
588
593
|
if (!isPlainObject(query)) {
|
|
@@ -602,47 +607,6 @@ const validateQueryProperty = (query, operators = []) => {
|
|
|
602
607
|
};
|
|
603
608
|
};
|
|
604
609
|
|
|
605
|
-
const toJSON = (context) => {
|
|
606
|
-
if (context.toJSON) {
|
|
607
|
-
return context.toJSON();
|
|
608
|
-
}
|
|
609
|
-
return context;
|
|
610
|
-
};
|
|
611
|
-
|
|
612
|
-
const setQueryKeySafely = (params, key, value, operator = "$eq", options) => {
|
|
613
|
-
var _a;
|
|
614
|
-
const { mutate = false } = options || {};
|
|
615
|
-
if (!mutate) {
|
|
616
|
-
params = structuredClone(params);
|
|
617
|
-
}
|
|
618
|
-
if (!params.query) {
|
|
619
|
-
params.query = {};
|
|
620
|
-
}
|
|
621
|
-
if (!(key in params.query)) {
|
|
622
|
-
if (operator === "$eq") {
|
|
623
|
-
params.query[key] = value;
|
|
624
|
-
} else {
|
|
625
|
-
params.query[key] = {
|
|
626
|
-
[operator]: value
|
|
627
|
-
};
|
|
628
|
-
}
|
|
629
|
-
return params;
|
|
630
|
-
}
|
|
631
|
-
if (isPlainObject$1(params.query[key]) && !(operator in params.query[key])) {
|
|
632
|
-
params.query[key][operator] = value;
|
|
633
|
-
} else {
|
|
634
|
-
(_a = params.query).$and ?? (_a.$and = []);
|
|
635
|
-
params.query.$and.push(
|
|
636
|
-
operator === "$eq" ? { [key]: value } : {
|
|
637
|
-
[key]: {
|
|
638
|
-
[operator]: value
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
);
|
|
642
|
-
}
|
|
643
|
-
return params;
|
|
644
|
-
};
|
|
645
|
-
|
|
646
610
|
function checkMulti() {
|
|
647
611
|
return (context) => {
|
|
648
612
|
if (shouldSkip("checkMulti", context)) {
|
|
@@ -1008,6 +972,7 @@ exports.DebouncedStore = DebouncedStore;
|
|
|
1008
972
|
exports.checkMulti = checkMulti;
|
|
1009
973
|
exports.createRelated = createRelated;
|
|
1010
974
|
exports.debounceMixin = debounceMixin;
|
|
975
|
+
exports.defineHooks = defineHooks;
|
|
1011
976
|
exports.filterArray = filterArray;
|
|
1012
977
|
exports.filterObject = filterObject;
|
|
1013
978
|
exports.filterQuery = filterQuery;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as _feathersjs_feathers from '@feathersjs/feathers';
|
|
2
|
-
import { HookContext, Application, Id, Query, Params } from '@feathersjs/feathers';
|
|
2
|
+
import { HookContext, Application, Id, HookOptions, Query, Params } from '@feathersjs/feathers';
|
|
3
3
|
import { HookContext as HookContext$1, Application as Application$1 } from '@feathersjs/feathers/lib';
|
|
4
4
|
import { PropertyPath, DebouncedFunc } from 'lodash';
|
|
5
|
-
import {
|
|
5
|
+
import { PaginationOptions, FilterQueryOptions } from '@feathersjs/adapter-commons';
|
|
6
6
|
import { HookType } from 'feathers-hooks-common';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -125,35 +125,29 @@ declare class DebouncedStore {
|
|
|
125
125
|
|
|
126
126
|
declare function debounceMixin(options?: Partial<InitDebounceMixinOptions>): (app: Application$1) => void;
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
type
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
declare function mergeArrays<T>(targetArr: T[] | undefined, sourceArr: T[] | undefined, handle: Handle, prependKey?: Path, actionOnEmptyIntersect?: ActionOnEmptyIntersect): T[] | undefined;
|
|
148
|
-
|
|
128
|
+
declare function defineHooks<A extends Application = Application, S = {
|
|
129
|
+
find: any;
|
|
130
|
+
get: any;
|
|
131
|
+
create: any;
|
|
132
|
+
update: any;
|
|
133
|
+
patch: any;
|
|
134
|
+
remove: any;
|
|
135
|
+
}, Options = HookOptions<A, S>>(hooks: Options): Options;
|
|
136
|
+
|
|
137
|
+
type FilterQueryResult<Q extends Query> = {
|
|
138
|
+
$select: Q["$select"] extends any ? Q["$select"] : never;
|
|
139
|
+
$limit: Q["$limit"] extends any ? Q["$limit"] : never;
|
|
140
|
+
$skip: Q["$skip"] extends any ? Q["$skip"] : never;
|
|
141
|
+
$sort: Q["$sort"] extends any ? Q["$sort"] : never;
|
|
142
|
+
query: Omit<Q, "$select" | "$limit" | "$skip" | "$sort">;
|
|
143
|
+
};
|
|
149
144
|
/**
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* @param
|
|
153
|
-
* @
|
|
154
|
-
* @returns Query
|
|
145
|
+
* Extracts $select, $limit, $skip, $sort from a query and returns the rest as a query object.
|
|
146
|
+
*
|
|
147
|
+
* @param providedQuery
|
|
148
|
+
* @returns
|
|
155
149
|
*/
|
|
156
|
-
declare function
|
|
150
|
+
declare function filterQuery<Q extends Query>(providedQuery?: Q): FilterQueryResult<Q>;
|
|
157
151
|
|
|
158
152
|
/**
|
|
159
153
|
* util to get paginate options from context
|
|
@@ -184,6 +178,29 @@ declare const isPaginated: <H extends HookContext<_feathersjs_feathers.Applicati
|
|
|
184
178
|
*/
|
|
185
179
|
declare function markHookForSkip<H extends HookContext = HookContext>(hookName: string, type: "all" | MaybeArray<HookType>, context?: H): H;
|
|
186
180
|
|
|
181
|
+
type Handle = "target" | "source" | "combine" | "intersect" | "intersectOrFull";
|
|
182
|
+
type FirstLast = "first" | "last";
|
|
183
|
+
type ActionOnEmptyIntersect = (target: unknown, source: unknown, prependKey: Path) => void;
|
|
184
|
+
interface MergeQueryOptions {
|
|
185
|
+
defaultHandle: Handle;
|
|
186
|
+
actionOnEmptyIntersect: ActionOnEmptyIntersect;
|
|
187
|
+
useLogicalConjunction: boolean;
|
|
188
|
+
handle?: {
|
|
189
|
+
[key: string]: Handle;
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
declare function mergeArrays<T>(targetArr: T[] | undefined, sourceArr: T[] | undefined, handle: Handle, prependKey?: Path, actionOnEmptyIntersect?: ActionOnEmptyIntersect): T[] | undefined;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Merges two queries into one.
|
|
197
|
+
* @param target Query to be merged into
|
|
198
|
+
* @param source Query to be merged from
|
|
199
|
+
* @param _options
|
|
200
|
+
* @returns Query
|
|
201
|
+
*/
|
|
202
|
+
declare function mergeQuery(target: Query, source: Query, _options?: Partial<MergeQueryOptions>): Query;
|
|
203
|
+
|
|
187
204
|
interface PushSetOptions {
|
|
188
205
|
unique?: boolean;
|
|
189
206
|
}
|
|
@@ -192,6 +209,11 @@ interface PushSetOptions {
|
|
|
192
209
|
*/
|
|
193
210
|
declare const pushSet: (obj: Record<string, unknown>, path: string | Path, val: unknown, options?: PushSetOptions) => unknown[];
|
|
194
211
|
|
|
212
|
+
type SetQueryKeySafelyOptions = {
|
|
213
|
+
mutate?: boolean;
|
|
214
|
+
};
|
|
215
|
+
declare const setQueryKeySafely: <P extends Params<_feathersjs_feathers.Query> = Params<_feathersjs_feathers.Query>>(params: P, key: string, value: any, operator?: string, options?: SetQueryKeySafelyOptions) => P;
|
|
216
|
+
|
|
195
217
|
/**
|
|
196
218
|
* util to set `context.result` to an empty array or object, depending on the hook type
|
|
197
219
|
*/
|
|
@@ -205,21 +227,16 @@ type ShouldSkipOptions = {
|
|
|
205
227
|
*/
|
|
206
228
|
declare const shouldSkip: <H extends HookContext<_feathersjs_feathers.Application<any, any>, any> = HookContext<_feathersjs_feathers.Application<any, any>, any>>(hookName: string, context: H, options?: ShouldSkipOptions) => boolean;
|
|
207
229
|
|
|
230
|
+
declare const toJSON: (context: HookContext) => HookContext<_feathersjs_feathers.Application<any, any>, any>;
|
|
231
|
+
|
|
208
232
|
/**
|
|
209
233
|
* util to validate a query for operators
|
|
210
234
|
*/
|
|
211
235
|
declare const validateQueryProperty: (query: any, operators?: string[]) => Query;
|
|
212
236
|
|
|
213
|
-
declare const
|
|
214
|
-
|
|
215
|
-
type SetQueryKeySafelyOptions = {
|
|
216
|
-
mutate?: boolean;
|
|
217
|
-
};
|
|
218
|
-
declare const setQueryKeySafely: <P extends Params<_feathersjs_feathers.Query> = Params<_feathersjs_feathers.Query>>(params: P, key: string, value: any, operator?: string, options?: SetQueryKeySafelyOptions) => P;
|
|
219
|
-
|
|
220
|
-
declare const filterArray: <T extends string[]>(...keys: T) => { [key in T[number]]: (value: any, options: FilterQueryOptions$1) => any; };
|
|
237
|
+
declare const filterArray: <T extends string[]>(...keys: T) => { [key in T[number]]: (value: any, options: FilterQueryOptions) => any; };
|
|
221
238
|
|
|
222
|
-
declare const filterObject: <T extends string[]>(...keys: T) => { [key in T[number]]: (value: any, options: FilterQueryOptions
|
|
239
|
+
declare const filterObject: <T extends string[]>(...keys: T) => { [key in T[number]]: (value: any, options: FilterQueryOptions) => any; };
|
|
223
240
|
|
|
224
241
|
type Single<T> = T extends Array<infer U> ? U : T;
|
|
225
242
|
type AsArray<T> = T extends any[] ? T : [T];
|
|
@@ -267,4 +284,4 @@ type InferRemoveResultFromPath<App extends Application, Path extends string, IdO
|
|
|
267
284
|
type InferDataFromPath<App extends Application, Path extends string, Method extends "create" | "update" | "patch"> = Method extends "create" ? InferCreateDataFromPath<App, Path> : Method extends "update" ? InferUpdateDataFromPath<App, Path> : Method extends "patch" ? InferPatchDataFromPath<App, Path> : never;
|
|
268
285
|
type InferResultFromPath<App extends Application, Path extends string, Method extends "get" | "find" | "create" | "update" | "patch" | "remove"> = Method extends "get" ? InferGetResultFromPath<App, Path> : Method extends "find" ? InferFindResultFromPath<App, Path> : Method extends "create" ? InferCreateResultFromPath<App, Path> : Method extends "update" ? InferUpdateResultFromPath<App, Path> : Method extends "patch" ? InferPatchResultFromPath<App, Path> : Method extends "remove" ? InferRemoveResultFromPath<App, Path> : never;
|
|
269
286
|
|
|
270
|
-
export { type ActionOnEmptyIntersect, type CreateRelatedOptions, type DebouncedFunctionApp, type DebouncedService, DebouncedStore, type DebouncedStoreOptions, type
|
|
287
|
+
export { type ActionOnEmptyIntersect, type CreateRelatedOptions, type DebouncedFunctionApp, type DebouncedService, DebouncedStore, type DebouncedStoreOptions, type FirstLast, type GetItemsIsArrayFrom, type GetItemsIsArrayOptions, type GetItemsIsArrayResult, type GetService, type Handle, type HookForEachOptions, type HookRunPerItemOptions, type HookSetDataOptions, type InferCreateData, type InferCreateDataFromPath, type InferCreateDataSingle, type InferCreateDataSingleFromPath, type InferCreateResult, type InferCreateResultFromPath, type InferCreateResultSingle, type InferCreateResultSingleFromPath, type InferDataFromPath, type InferFindResult, type InferFindResultFromPath, type InferGetResult, type InferGetResultFromPath, type InferPatchData, type InferPatchDataFromPath, type InferPatchResult, type InferPatchResultFromPath, type InferRemoveResult, type InferRemoveResultFromPath, type InferResultFromPath, type InferUpdateData, type InferUpdateDataFromPath, type InferUpdateResult, type InferUpdateResultFromPath, type InitDebounceMixinOptions, type MergeQueryOptions, type OnDeleteAction, type OnDeleteOptions, type Predicate, type PredicateWithContext, type PushSetOptions, type RemoveRelatedOptions, type SetQueryKeySafelyOptions, type ShouldSkipOptions, checkMulti, createRelated, debounceMixin, defineHooks, filterArray, filterObject, filterQuery, forEach, getItemsIsArray, getPaginate, isMulti, isPaginated, makeDefaultOptions, markHookForSkip, mergeArrays, mergeQuery, onDelete, parseFields, pushSet, removeRelated, runPerItem, setData, setQueryKeySafely, setResultEmpty, shouldSkip, toJSON, validateQueryProperty };
|