feathers-utils 3.0.1 → 3.0.3

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 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)) {
@@ -814,7 +821,8 @@ function setData(from, to, _options) {
814
821
  return context;
815
822
  }
816
823
  const { items } = getItemsIsArray(context);
817
- if (!_has__default(context, from)) {
824
+ const contextJson = toJSON(context);
825
+ if (!_has__default(contextJson, from)) {
818
826
  if (!context.params?.provider || options.allowUndefined === true) {
819
827
  return context;
820
828
  }
@@ -823,7 +831,7 @@ function setData(from, to, _options) {
823
831
  }
824
832
  throw new errors.Forbidden(`Expected field ${from.toString()} not available`);
825
833
  }
826
- const val = _get__default(context, from);
834
+ const val = _get__default(contextJson, from);
827
835
  items.forEach((item) => {
828
836
  let overwrite;
829
837
  if (typeof options.overwrite === "function") {
@@ -973,4 +981,5 @@ exports.runPerItem = runPerItem;
973
981
  exports.setData = setData;
974
982
  exports.setResultEmpty = setResultEmpty;
975
983
  exports.shouldSkip = shouldSkip;
984
+ exports.toJSON = toJSON;
976
985
  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)) {
@@ -800,7 +807,8 @@ function setData(from, to, _options) {
800
807
  return context;
801
808
  }
802
809
  const { items } = getItemsIsArray(context);
803
- if (!_has(context, from)) {
810
+ const contextJson = toJSON(context);
811
+ if (!_has(contextJson, from)) {
804
812
  if (!context.params?.provider || options.allowUndefined === true) {
805
813
  return context;
806
814
  }
@@ -809,7 +817,7 @@ function setData(from, to, _options) {
809
817
  }
810
818
  throw new Forbidden(`Expected field ${from.toString()} not available`);
811
819
  }
812
- const val = _get(context, from);
820
+ const val = _get(contextJson, from);
813
821
  items.forEach((item) => {
814
822
  let overwrite;
815
823
  if (typeof options.overwrite === "function") {
@@ -935,4 +943,4 @@ const filterObject = (...keys) => {
935
943
  return result;
936
944
  };
937
945
 
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 };
946
+ 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feathers-utils",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "description": "Some utils for projects using '@feathersjs/feathers'",
5
5
  "author": "fratzinger",
6
6
  "repository": {
@@ -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;
@@ -38,7 +39,9 @@ export function setData<H extends HookContext = HookContext>(
38
39
 
39
40
  const { items } = getItemsIsArray(context);
40
41
 
41
- if (!_has(context, from)) {
42
+ const contextJson = toJSON(context);
43
+
44
+ if (!_has(contextJson, from)) {
42
45
  if (!context.params?.provider || options.allowUndefined === true) {
43
46
  return context;
44
47
  }
@@ -53,7 +56,7 @@ export function setData<H extends HookContext = HookContext>(
53
56
  throw new Forbidden(`Expected field ${from.toString()} not available`);
54
57
  }
55
58
 
56
- const val = _get(context, from);
59
+ const val = _get(contextJson, from);
57
60
 
58
61
  items.forEach((item: Record<string, unknown>) => {
59
62
  let overwrite: boolean;
@@ -9,3 +9,4 @@ export * from "./pushSet";
9
9
  export * from "./setResultEmpty";
10
10
  export * from "./shouldSkip";
11
11
  export * from "./validateQueryProperty";
12
+ export * from "./toJSON";
@@ -0,0 +1,8 @@
1
+ import type { HookContext } from "@feathersjs/feathers";
2
+
3
+ export const toJSON = (context: HookContext) => {
4
+ if (context.toJSON) {
5
+ return context.toJSON();
6
+ }
7
+ return context;
8
+ };