feathers-utils 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +9 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs +9 -2
- package/package.json +1 -1
- package/src/hooks/setData.ts +2 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/toJSON.ts +8 -0
package/dist/index.cjs
CHANGED
|
@@ -601,6 +601,13 @@ const validateQueryProperty = (query, operators = []) => {
|
|
|
601
601
|
};
|
|
602
602
|
};
|
|
603
603
|
|
|
604
|
+
const toJSON = (context) => {
|
|
605
|
+
if (context.toJSON) {
|
|
606
|
+
return context.toJSON();
|
|
607
|
+
}
|
|
608
|
+
return context;
|
|
609
|
+
};
|
|
610
|
+
|
|
604
611
|
function checkMulti() {
|
|
605
612
|
return (context) => {
|
|
606
613
|
if (shouldSkip("checkMulti", context)) {
|
|
@@ -823,7 +830,7 @@ function setData(from, to, _options) {
|
|
|
823
830
|
}
|
|
824
831
|
throw new errors.Forbidden(`Expected field ${from.toString()} not available`);
|
|
825
832
|
}
|
|
826
|
-
const val = _get__default(context, from);
|
|
833
|
+
const val = _get__default(toJSON(context), from);
|
|
827
834
|
items.forEach((item) => {
|
|
828
835
|
let overwrite;
|
|
829
836
|
if (typeof options.overwrite === "function") {
|
|
@@ -973,4 +980,5 @@ exports.runPerItem = runPerItem;
|
|
|
973
980
|
exports.setData = setData;
|
|
974
981
|
exports.setResultEmpty = setResultEmpty;
|
|
975
982
|
exports.shouldSkip = shouldSkip;
|
|
983
|
+
exports.toJSON = toJSON;
|
|
976
984
|
exports.validateQueryProperty = validateQueryProperty;
|
package/dist/index.d.ts
CHANGED
|
@@ -209,6 +209,8 @@ declare const shouldSkip: <H extends HookContext<_feathersjs_feathers.Applicatio
|
|
|
209
209
|
*/
|
|
210
210
|
declare const validateQueryProperty: (query: any, operators?: string[]) => Query;
|
|
211
211
|
|
|
212
|
+
declare const toJSON: (context: HookContext) => HookContext<_feathersjs_feathers.Application<any, any>, any>;
|
|
213
|
+
|
|
212
214
|
declare const filterArray: <T extends string[]>(...keys: T) => { [key in T[number]]: (value: any, options: FilterQueryOptions$1) => any; };
|
|
213
215
|
|
|
214
216
|
declare const filterObject: <T extends string[]>(...keys: T) => { [key in T[number]]: (value: any, options: FilterQueryOptions$1) => any; };
|
|
@@ -259,4 +261,4 @@ type InferRemoveResultFromPath<App extends Application, Path extends string, IdO
|
|
|
259
261
|
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;
|
|
260
262
|
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;
|
|
261
263
|
|
|
262
|
-
export { ActionOnEmptyIntersect, CreateRelatedOptions, DebouncedFunctionApp, DebouncedService, DebouncedStore, DebouncedStoreOptions, FilterQueryOptions, FirstLast, GetItemsIsArrayOptions, GetItemsIsArrayResult, GetService, Handle, HookForEachOptions, HookRunPerItemOptions, HookSetDataOptions, InferCreateData, InferCreateDataFromPath, InferCreateDataSingle, InferCreateDataSingleFromPath, InferCreateResult, InferCreateResultFromPath, InferCreateResultSingle, InferCreateResultSingleFromPath, InferDataFromPath, InferFindResult, InferFindResultFromPath, InferGetResult, InferGetResultFromPath, InferPatchData, InferPatchDataFromPath, InferPatchResult, InferPatchResultFromPath, InferRemoveResult, InferRemoveResultFromPath, InferResultFromPath, InferUpdateData, InferUpdateDataFromPath, InferUpdateResult, InferUpdateResultFromPath, InitDebounceMixinOptions, MergeQueryOptions, OnDeleteAction, OnDeleteOptions, Predicate, PredicateWithContext, PushSetOptions, RemoveRelatedOptions, ShouldSkipOptions, checkMulti, createRelated, debounceMixin, filterArray, filterObject, filterQuery, forEach, getItemsIsArray, getPaginate, isMulti, isPaginated, makeDefaultOptions, markHookForSkip, mergeArrays, mergeQuery, onDelete, parseFields, pushSet, removeRelated, runPerItem, setData, setResultEmpty, shouldSkip, validateQueryProperty };
|
|
264
|
+
export { ActionOnEmptyIntersect, CreateRelatedOptions, DebouncedFunctionApp, DebouncedService, DebouncedStore, DebouncedStoreOptions, FilterQueryOptions, FirstLast, GetItemsIsArrayOptions, GetItemsIsArrayResult, GetService, Handle, HookForEachOptions, HookRunPerItemOptions, HookSetDataOptions, InferCreateData, InferCreateDataFromPath, InferCreateDataSingle, InferCreateDataSingleFromPath, InferCreateResult, InferCreateResultFromPath, InferCreateResultSingle, InferCreateResultSingleFromPath, InferDataFromPath, InferFindResult, InferFindResultFromPath, InferGetResult, InferGetResultFromPath, InferPatchData, InferPatchDataFromPath, InferPatchResult, InferPatchResultFromPath, InferRemoveResult, InferRemoveResultFromPath, InferResultFromPath, InferUpdateData, InferUpdateDataFromPath, InferUpdateResult, InferUpdateResultFromPath, InitDebounceMixinOptions, MergeQueryOptions, OnDeleteAction, OnDeleteOptions, Predicate, PredicateWithContext, PushSetOptions, RemoveRelatedOptions, ShouldSkipOptions, checkMulti, createRelated, debounceMixin, filterArray, filterObject, filterQuery, forEach, getItemsIsArray, getPaginate, isMulti, isPaginated, makeDefaultOptions, markHookForSkip, mergeArrays, mergeQuery, onDelete, parseFields, pushSet, removeRelated, runPerItem, setData, setResultEmpty, shouldSkip, toJSON, validateQueryProperty };
|
package/dist/index.mjs
CHANGED
|
@@ -587,6 +587,13 @@ const validateQueryProperty = (query, operators = []) => {
|
|
|
587
587
|
};
|
|
588
588
|
};
|
|
589
589
|
|
|
590
|
+
const toJSON = (context) => {
|
|
591
|
+
if (context.toJSON) {
|
|
592
|
+
return context.toJSON();
|
|
593
|
+
}
|
|
594
|
+
return context;
|
|
595
|
+
};
|
|
596
|
+
|
|
590
597
|
function checkMulti() {
|
|
591
598
|
return (context) => {
|
|
592
599
|
if (shouldSkip("checkMulti", context)) {
|
|
@@ -809,7 +816,7 @@ function setData(from, to, _options) {
|
|
|
809
816
|
}
|
|
810
817
|
throw new Forbidden(`Expected field ${from.toString()} not available`);
|
|
811
818
|
}
|
|
812
|
-
const val = _get(context, from);
|
|
819
|
+
const val = _get(toJSON(context), from);
|
|
813
820
|
items.forEach((item) => {
|
|
814
821
|
let overwrite;
|
|
815
822
|
if (typeof options.overwrite === "function") {
|
|
@@ -935,4 +942,4 @@ const filterObject = (...keys) => {
|
|
|
935
942
|
return result;
|
|
936
943
|
};
|
|
937
944
|
|
|
938
|
-
export { DebouncedStore, checkMulti, createRelated, debounceMixin, filterArray, filterObject, filterQuery, forEach, getItemsIsArray, getPaginate, isMulti, isPaginated, makeDefaultOptions, markHookForSkip, mergeArrays, mergeQuery, onDelete, parseFields, pushSet, removeRelated, runPerItem, setData, setResultEmpty, shouldSkip, validateQueryProperty };
|
|
945
|
+
export { DebouncedStore, checkMulti, createRelated, debounceMixin, filterArray, filterObject, filterQuery, forEach, getItemsIsArray, getPaginate, isMulti, isPaginated, makeDefaultOptions, markHookForSkip, mergeArrays, mergeQuery, onDelete, parseFields, pushSet, removeRelated, runPerItem, setData, setResultEmpty, shouldSkip, toJSON, validateQueryProperty };
|
package/package.json
CHANGED
package/src/hooks/setData.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { getItemsIsArray, shouldSkip } from "../utils";
|
|
|
8
8
|
import type { HookContext } from "@feathersjs/feathers";
|
|
9
9
|
import type { PropertyPath } from "lodash";
|
|
10
10
|
import type { PredicateWithContext } from "../types";
|
|
11
|
+
import { toJSON } from "../utils/toJSON";
|
|
11
12
|
|
|
12
13
|
export interface HookSetDataOptions {
|
|
13
14
|
allowUndefined?: boolean;
|
|
@@ -53,7 +54,7 @@ export function setData<H extends HookContext = HookContext>(
|
|
|
53
54
|
throw new Forbidden(`Expected field ${from.toString()} not available`);
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
const val = _get(context, from);
|
|
57
|
+
const val = _get(toJSON(context), from);
|
|
57
58
|
|
|
58
59
|
items.forEach((item: Record<string, unknown>) => {
|
|
59
60
|
let overwrite: boolean;
|
package/src/utils/index.ts
CHANGED