@webiny/api-headless-cms 0.0.0-unstable.f9f12f52a0 → 0.0.0-unstable.fdd9228b5d

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 (74) hide show
  1. package/crud/contentEntry/entryDataFactories/createPublishEntryData.d.ts +3 -3
  2. package/crud/contentEntry/entryDataFactories/createPublishEntryData.js.map +1 -1
  3. package/crud/contentEntry/entryDataFactories/createUnpublishEntryData.d.ts +3 -3
  4. package/crud/contentEntry/entryDataFactories/createUnpublishEntryData.js.map +1 -1
  5. package/crud/contentEntry/useCases/GetEntriesByIds/GetEntriesByIds.d.ts +5 -3
  6. package/crud/contentEntry/useCases/GetEntriesByIds/GetEntriesByIds.js +6 -2
  7. package/crud/contentEntry/useCases/GetEntriesByIds/GetEntriesByIds.js.map +1 -1
  8. package/crud/contentEntry/useCases/GetEntriesByIds/index.d.ts +2 -0
  9. package/crud/contentEntry/useCases/GetEntriesByIds/index.js +1 -1
  10. package/crud/contentEntry/useCases/GetEntriesByIds/index.js.map +1 -1
  11. package/crud/contentEntry/useCases/GetLatestEntriesByIds/GetLatestEntriesByIds.d.ts +5 -3
  12. package/crud/contentEntry/useCases/GetLatestEntriesByIds/GetLatestEntriesByIds.js +6 -2
  13. package/crud/contentEntry/useCases/GetLatestEntriesByIds/GetLatestEntriesByIds.js.map +1 -1
  14. package/crud/contentEntry/useCases/GetLatestEntriesByIds/index.d.ts +2 -0
  15. package/crud/contentEntry/useCases/GetLatestEntriesByIds/index.js +1 -1
  16. package/crud/contentEntry/useCases/GetLatestEntriesByIds/index.js.map +1 -1
  17. package/crud/contentEntry/useCases/GetLatestRevisionByEntryId/GetLatestRevisionByEntryId.d.ts +5 -3
  18. package/crud/contentEntry/useCases/GetLatestRevisionByEntryId/GetLatestRevisionByEntryId.js +7 -2
  19. package/crud/contentEntry/useCases/GetLatestRevisionByEntryId/GetLatestRevisionByEntryId.js.map +1 -1
  20. package/crud/contentEntry/useCases/GetLatestRevisionByEntryId/index.d.ts +2 -0
  21. package/crud/contentEntry/useCases/GetLatestRevisionByEntryId/index.js +1 -1
  22. package/crud/contentEntry/useCases/GetLatestRevisionByEntryId/index.js.map +1 -1
  23. package/crud/contentEntry/useCases/GetPreviousRevisionByEntryId/GetPreviousRevisionByEntryId.d.ts +5 -3
  24. package/crud/contentEntry/useCases/GetPreviousRevisionByEntryId/GetPreviousRevisionByEntryId.js +7 -2
  25. package/crud/contentEntry/useCases/GetPreviousRevisionByEntryId/GetPreviousRevisionByEntryId.js.map +1 -1
  26. package/crud/contentEntry/useCases/GetPreviousRevisionByEntryId/index.d.ts +2 -0
  27. package/crud/contentEntry/useCases/GetPreviousRevisionByEntryId/index.js +1 -1
  28. package/crud/contentEntry/useCases/GetPreviousRevisionByEntryId/index.js.map +1 -1
  29. package/crud/contentEntry/useCases/GetPublishedEntriesByIds/GetPublishedEntriesByIds.d.ts +5 -3
  30. package/crud/contentEntry/useCases/GetPublishedEntriesByIds/GetPublishedEntriesByIds.js +6 -2
  31. package/crud/contentEntry/useCases/GetPublishedEntriesByIds/GetPublishedEntriesByIds.js.map +1 -1
  32. package/crud/contentEntry/useCases/GetPublishedEntriesByIds/index.d.ts +2 -0
  33. package/crud/contentEntry/useCases/GetPublishedEntriesByIds/index.js +1 -1
  34. package/crud/contentEntry/useCases/GetPublishedEntriesByIds/index.js.map +1 -1
  35. package/crud/contentEntry/useCases/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryId.d.ts +5 -3
  36. package/crud/contentEntry/useCases/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryId.js +7 -2
  37. package/crud/contentEntry/useCases/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryId.js.map +1 -1
  38. package/crud/contentEntry/useCases/GetPublishedRevisionByEntryId/index.d.ts +2 -0
  39. package/crud/contentEntry/useCases/GetPublishedRevisionByEntryId/index.js +1 -1
  40. package/crud/contentEntry/useCases/GetPublishedRevisionByEntryId/index.js.map +1 -1
  41. package/crud/contentEntry/useCases/GetRevisionById/GetRevisionById.d.ts +5 -3
  42. package/crud/contentEntry/useCases/GetRevisionById/GetRevisionById.js +7 -2
  43. package/crud/contentEntry/useCases/GetRevisionById/GetRevisionById.js.map +1 -1
  44. package/crud/contentEntry/useCases/GetRevisionById/index.d.ts +2 -0
  45. package/crud/contentEntry/useCases/GetRevisionById/index.js +1 -1
  46. package/crud/contentEntry/useCases/GetRevisionById/index.js.map +1 -1
  47. package/crud/contentEntry/useCases/GetRevisionsByEntryId/GetRevisionsByEntryId.d.ts +5 -3
  48. package/crud/contentEntry/useCases/GetRevisionsByEntryId/GetRevisionsByEntryId.js +6 -2
  49. package/crud/contentEntry/useCases/GetRevisionsByEntryId/GetRevisionsByEntryId.js.map +1 -1
  50. package/crud/contentEntry/useCases/GetRevisionsByEntryId/index.d.ts +2 -0
  51. package/crud/contentEntry/useCases/GetRevisionsByEntryId/index.js +1 -1
  52. package/crud/contentEntry/useCases/GetRevisionsByEntryId/index.js.map +1 -1
  53. package/crud/contentEntry/useCases/ListEntries/ListEntriesOperation.d.ts +10 -3
  54. package/crud/contentEntry/useCases/ListEntries/ListEntriesOperation.js +9 -2
  55. package/crud/contentEntry/useCases/ListEntries/ListEntriesOperation.js.map +1 -1
  56. package/crud/contentEntry/useCases/ListEntries/index.d.ts +2 -0
  57. package/crud/contentEntry/useCases/ListEntries/index.js +1 -1
  58. package/crud/contentEntry/useCases/ListEntries/index.js.map +1 -1
  59. package/crud/contentEntry/useCases/RestoreEntryFromBin/RestoreEntryFromBinOperation.d.ts +5 -3
  60. package/crud/contentEntry/useCases/RestoreEntryFromBin/RestoreEntryFromBinOperation.js +4 -2
  61. package/crud/contentEntry/useCases/RestoreEntryFromBin/RestoreEntryFromBinOperation.js.map +1 -1
  62. package/crud/contentEntry/useCases/RestoreEntryFromBin/index.d.ts +2 -0
  63. package/crud/contentEntry/useCases/RestoreEntryFromBin/index.js +1 -1
  64. package/crud/contentEntry/useCases/RestoreEntryFromBin/index.js.map +1 -1
  65. package/crud/contentEntry.crud.js +15 -3
  66. package/crud/contentEntry.crud.js.map +1 -1
  67. package/graphqlFields/searchableJson.js +5 -0
  68. package/graphqlFields/searchableJson.js.map +1 -1
  69. package/package.json +21 -21
  70. package/types/context.d.ts +2 -2
  71. package/types/context.js.map +1 -1
  72. package/utils/entryStorage.d.ts +8 -1
  73. package/utils/entryStorage.js +37 -4
  74. package/utils/entryStorage.js.map +1 -1
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.getStoragePluginFactory = exports.entryToStorageTransform = exports.entryFromStorageTransform = exports.entryFieldFromStorageTransform = void 0;
7
+ exports.getStoragePluginFactory = exports.entryToStorageTransform = exports.entryFromStorageTransform = exports.entryFieldFromStorageTransform = exports.createTransformEntryCallable = void 0;
8
8
  var _error = _interopRequireDefault(require("@webiny/error"));
9
9
  var _StorageTransformPlugin = require("../plugins/StorageTransformPlugin");
10
10
  var _getBaseFieldType = require("./getBaseFieldType");
@@ -32,15 +32,30 @@ const getStoragePluginFactory = context => {
32
32
  return plugins[fieldType] || defaultStoragePlugin;
33
33
  };
34
34
  };
35
+ exports.getStoragePluginFactory = getStoragePluginFactory;
36
+ const doNotTouchProperty = Symbol("__DO_NOT_TOUCH_AS_WE_USE_IT_TO_SKIP_UNNECESSARY_OPERATIONS");
35
37
 
36
38
  /**
37
39
  * This should be used when transforming the whole entry.
38
40
  */
39
- exports.getStoragePluginFactory = getStoragePluginFactory;
40
41
  const entryStorageTransform = async (context, model, operation, entry) => {
42
+ /**
43
+ * We use this property to skip unnecessary operations.
44
+ */
45
+ // @ts-expect-error
46
+ if (entry[doNotTouchProperty] === operation) {
47
+ return entry;
48
+ }
41
49
  const getStoragePlugin = getStoragePluginFactory(context);
42
50
  const transformedValues = {};
43
51
  for (const field of model.fields) {
52
+ /**
53
+ * We can safely skip fields that are not present in the entry values.
54
+ */
55
+ if (entry.values.hasOwnProperty(field.fieldId) === false) {
56
+ continue;
57
+ }
58
+ const value = entry.values[field.fieldId];
44
59
  const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
45
60
  const plugin = getStoragePlugin(baseType);
46
61
  // TODO: remove this once plugins are converted into classes
@@ -51,14 +66,23 @@ const entryStorageTransform = async (context, model, operation, entry) => {
51
66
  plugins: context.plugins,
52
67
  model,
53
68
  field,
54
- value: entry.values[field.fieldId],
69
+ value,
55
70
  getStoragePlugin
56
71
  });
57
72
  }
58
- return {
73
+ const result = {
59
74
  ...entry,
60
75
  values: transformedValues
61
76
  };
77
+ /**
78
+ * We need to assign the variable so that we can skip unnecessary operations next time.
79
+ */
80
+ Object.defineProperty(result, doNotTouchProperty, {
81
+ enumerable: false,
82
+ value: operation,
83
+ configurable: true
84
+ });
85
+ return result;
62
86
  };
63
87
 
64
88
  /**
@@ -103,5 +127,14 @@ const entryFieldFromStorageTransform = async params => {
103
127
  });
104
128
  };
105
129
  exports.entryFieldFromStorageTransform = entryFieldFromStorageTransform;
130
+ const createTransformEntryCallable = params => {
131
+ const {
132
+ context
133
+ } = params;
134
+ return async (model, entry) => {
135
+ return entryFromStorageTransform(context, model, entry);
136
+ };
137
+ };
138
+ exports.createTransformEntryCallable = createTransformEntryCallable;
106
139
 
107
140
  //# sourceMappingURL=entryStorage.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_error","_interopRequireDefault","require","_StorageTransformPlugin","_getBaseFieldType","getStoragePluginFactory","context","defaultStoragePlugin","plugins","byType","StorageTransformPlugin","type","reverse","reduce","collection","plugin","fieldType","exports","entryStorageTransform","model","operation","entry","getStoragePlugin","transformedValues","field","fields","baseType","getBaseFieldType","WebinyError","name","fieldId","value","values","entryToStorageTransform","entryFromStorageTransform","entryFieldFromStorageTransform","params","fromStorage"],"sources":["entryStorage.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { StorageTransformPlugin } from \"~/plugins/StorageTransformPlugin\";\nimport type { CmsContext, CmsEntry, CmsModel, CmsModelField } from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\n\nexport interface GetStoragePluginFactory {\n (context: Pick<CmsContext, \"plugins\">): (fieldType: string) => StorageTransformPlugin<any>;\n}\n\nexport const getStoragePluginFactory: GetStoragePluginFactory = context => {\n let defaultStoragePlugin: StorageTransformPlugin;\n\n const plugins = context.plugins\n .byType<StorageTransformPlugin>(StorageTransformPlugin.type)\n // we reverse plugins because we want to get latest added only\n .reverse()\n .reduce((collection, plugin) => {\n /**\n * Check if it's a default plugin and set it - always override the previous one.\n */\n if (plugin.fieldType === \"*\") {\n defaultStoragePlugin = plugin;\n return collection;\n }\n\n /**\n * We will just set the plugin for given type.\n * The last one will override existing one - so users can override our default ones.\n */\n collection[plugin.fieldType] = plugin;\n\n return collection;\n }, {} as Record<string, StorageTransformPlugin>);\n\n return (fieldType: string) => {\n return plugins[fieldType] || defaultStoragePlugin;\n };\n};\n\n/**\n * This should be used when transforming the whole entry.\n */\nconst entryStorageTransform = async (\n context: Pick<CmsContext, \"plugins\">,\n model: CmsModel,\n operation: \"toStorage\" | \"fromStorage\",\n entry: CmsEntry\n): Promise<CmsEntry> => {\n const getStoragePlugin = getStoragePluginFactory(context);\n\n const transformedValues: Record<string, any> = {};\n for (const field of model.fields) {\n const baseType = getBaseFieldType(field);\n const plugin = getStoragePlugin(baseType);\n // TODO: remove this once plugins are converted into classes\n if (typeof plugin[operation] !== \"function\") {\n throw new WebinyError(\n `Missing \"${operation}\" function in storage plugin \"${plugin.name}\" for field type \"${baseType}\"`\n );\n }\n\n transformedValues[field.fieldId] = await plugin[operation]({\n plugins: context.plugins,\n model,\n field,\n value: entry.values[field.fieldId],\n getStoragePlugin\n });\n }\n\n return { ...entry, values: transformedValues };\n};\n\n/**\n * A function that is used in crud to transform entry into the storage type.\n */\nexport const entryToStorageTransform = async (\n context: Pick<CmsContext, \"plugins\">,\n model: CmsModel,\n entry: CmsEntry\n): Promise<CmsEntry> => {\n return entryStorageTransform(context, model, \"toStorage\", entry);\n};\n\n/**\n * A function that is used to transform the whole entry from storage into its native form.\n */\nexport const entryFromStorageTransform = async (\n context: Pick<CmsContext, \"plugins\">,\n model: CmsModel,\n entry: CmsEntry\n): Promise<CmsEntry> => {\n return entryStorageTransform(context, model, \"fromStorage\", entry);\n};\n\ninterface EntryFieldFromStorageTransformParams {\n context: Pick<CmsContext, \"plugins\">;\n model: CmsModel;\n field: CmsModelField;\n value: any;\n}\n/*\n * A function that is used to transform a single field from storage\n */\nexport const entryFieldFromStorageTransform = async <T = any>(\n params: EntryFieldFromStorageTransformParams\n): Promise<T> => {\n const { context, model, field, value } = params;\n const getStoragePlugin = getStoragePluginFactory(context);\n\n const baseType = getBaseFieldType(field);\n const plugin = getStoragePlugin(baseType);\n\n // TODO: remove this once plugins are converted into classes\n if (typeof plugin.fromStorage !== \"function\") {\n throw new WebinyError(\n `Missing \"fromStorage\" function in storage plugin \"${plugin.name}\" for field type \"${baseType}\"`\n );\n }\n\n return plugin.fromStorage({\n plugins: context.plugins,\n model,\n field,\n value,\n getStoragePlugin\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,uBAAA,GAAAD,OAAA;AAEA,IAAAE,iBAAA,GAAAF,OAAA;AAMO,MAAMG,uBAAgD,GAAGC,OAAO,IAAI;EACvE,IAAIC,oBAA4C;EAEhD,MAAMC,OAAO,GAAGF,OAAO,CAACE,OAAO,CAC1BC,MAAM,CAAyBC,8CAAsB,CAACC,IAAI;EAC3D;EAAA,CACCC,OAAO,CAAC,CAAC,CACTC,MAAM,CAAC,CAACC,UAAU,EAAEC,MAAM,KAAK;IAC5B;AACZ;AACA;IACY,IAAIA,MAAM,CAACC,SAAS,KAAK,GAAG,EAAE;MAC1BT,oBAAoB,GAAGQ,MAAM;MAC7B,OAAOD,UAAU;IACrB;;IAEA;AACZ;AACA;AACA;IACYA,UA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ACpB,OAAOH,qBAAqB,CAACZ,OAAO,EAAEa,KAAK,EAAE,WAAW,EAAEE,KAAK,CAAC;AACpE,CAAC;;AAED;AACA;AACA;AAFAJ,OAAA,CAAAgB,uBAAA,GAAAA,uBAAA;AAGO,MAAMC,yBAAyB,GAAG,MAAAA,CACrC5B,OAAoC,EACpCa,KAAe,EACfE,KAAe,KACK;EACpB,OAAOH,qBAAqB,CAACZ,OAAO,EAAEa,KAAK,EAAE,aAAa,EAAEE,KAAK,CAAC;AACtE,CAAC;AAACJ,OAAA,CAAAiB,yBAAA,GAAAA,yBAAA;AAQF;AACA;AACA;AACO,MAAMC,8BAA8B,GAAG,MAC1CC,MAA4C,IAC/B;EACb,MAAM;IAAE9B,OAAO;IAAEa,KAAK;IAAEK,KAAK;IAAEO;EAAM,CAAC,GAAGK,MAAM;EAC/C,MAAMd,gBAAgB,GAAGjB,uBAAuB,CAACC,OAAO,CAAC;EAEzD,MAAMoB,QAAQ,GAAG,IAAAC,kCAAgB,EAACH,KAAK,CAAC;EACxC,MAAMT,MAAM,GAAGO,gBAAgB,CAACI,QAAQ,CAAC;;EAEzC;EACA,IAAI,OAAOX,MAAM,CAACsB,WAAW,KAAK,UAAU,EAAE;IAC1C,MAAM,IAAIT,cAAW,CACjB,qDAAqDb,MAAM,CAACc,IAAI,qBAAqBH,QAAQ,GACjG,CAAC;EACL;EAEA,OAAOX,MAAM,CAACsB,WAAW,CAAC;IACtB7B,OAAO,EAAEF,OAAO,CAACE,OAAO;IACxBW,KAAK;IACLK,KAAK;IACLO,KAAK;IACLT;EACJ,CAAC,CAAC;AACN,CAAC;AAACL,OAAA,CAAAkB,8BAAA,GAAAA,8BAAA","ignoreList":[]}
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_StorageTransformPlugin","_getBaseFieldType","getStoragePluginFactory","context","defaultStoragePlugin","plugins","byType","StorageTransformPlugin","type","reverse","reduce","collection","plugin","fieldType","exports","doNotTouchProperty","Symbol","entryStorageTransform","model","operation","entry","getStoragePlugin","transformedValues","field","fields","values","hasOwnProperty","fieldId","value","baseType","getBaseFieldType","WebinyError","name","result","Object","defineProperty","enumerable","configurable","entryToStorageTransform","entryFromStorageTransform","entryFieldFromStorageTransform","params","fromStorage","createTransformEntryCallable"],"sources":["entryStorage.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { StorageTransformPlugin } from \"~/plugins/StorageTransformPlugin\";\nimport type { CmsContext, CmsEntry, CmsEntryValues, CmsModel, CmsModelField } from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\n\nexport interface GetStoragePluginFactory {\n (context: Pick<CmsContext, \"plugins\">): (fieldType: string) => StorageTransformPlugin<any>;\n}\n\nexport const getStoragePluginFactory: GetStoragePluginFactory = context => {\n let defaultStoragePlugin: StorageTransformPlugin;\n\n const plugins = context.plugins\n .byType<StorageTransformPlugin>(StorageTransformPlugin.type)\n // we reverse plugins because we want to get latest added only\n .reverse()\n .reduce((collection, plugin) => {\n /**\n * Check if it's a default plugin and set it - always override the previous one.\n */\n if (plugin.fieldType === \"*\") {\n defaultStoragePlugin = plugin;\n return collection;\n }\n\n /**\n * We will just set the plugin for given type.\n * The last one will override existing one - so users can override our default ones.\n */\n collection[plugin.fieldType] = plugin;\n\n return collection;\n }, {} as Record<string, StorageTransformPlugin>);\n\n return (fieldType: string) => {\n return plugins[fieldType] || defaultStoragePlugin;\n };\n};\n\nconst doNotTouchProperty = Symbol(\"__DO_NOT_TOUCH_AS_WE_USE_IT_TO_SKIP_UNNECESSARY_OPERATIONS\");\n\n/**\n * This should be used when transforming the whole entry.\n */\nconst entryStorageTransform = async (\n context: Pick<CmsContext, \"plugins\">,\n model: CmsModel,\n operation: \"toStorage\" | \"fromStorage\",\n entry: CmsEntry\n): Promise<CmsEntry> => {\n /**\n * We use this property to skip unnecessary operations.\n */\n // @ts-expect-error\n if (entry[doNotTouchProperty] === operation) {\n return entry;\n }\n\n const getStoragePlugin = getStoragePluginFactory(context);\n\n const transformedValues: Record<string, any> = {};\n for (const field of model.fields) {\n /**\n * We can safely skip fields that are not present in the entry values.\n */\n if (entry.values.hasOwnProperty(field.fieldId) === false) {\n continue;\n }\n const value = entry.values[field.fieldId];\n\n const baseType = getBaseFieldType(field);\n const plugin = getStoragePlugin(baseType);\n // TODO: remove this once plugins are converted into classes\n if (typeof plugin[operation] !== \"function\") {\n throw new WebinyError(\n `Missing \"${operation}\" function in storage plugin \"${plugin.name}\" for field type \"${baseType}\"`\n );\n }\n\n transformedValues[field.fieldId] = await plugin[operation]({\n plugins: context.plugins,\n model,\n field,\n value,\n getStoragePlugin\n });\n }\n\n const result = {\n ...entry,\n values: transformedValues\n };\n /**\n * We need to assign the variable so that we can skip unnecessary operations next time.\n */\n Object.defineProperty(result, doNotTouchProperty, {\n enumerable: false,\n value: operation,\n configurable: true\n });\n\n return result;\n};\n\n/**\n * A function that is used in crud to transform entry into the storage type.\n */\nexport const entryToStorageTransform = async (\n context: Pick<CmsContext, \"plugins\">,\n model: CmsModel,\n entry: CmsEntry\n): Promise<CmsEntry> => {\n return entryStorageTransform(context, model, \"toStorage\", entry);\n};\n\n/**\n * A function that is used to transform the whole entry from storage into its native form.\n */\nexport const entryFromStorageTransform = async (\n context: Pick<CmsContext, \"plugins\">,\n model: CmsModel,\n entry: CmsEntry\n): Promise<CmsEntry> => {\n return entryStorageTransform(context, model, \"fromStorage\", entry);\n};\n\ninterface EntryFieldFromStorageTransformParams {\n context: Pick<CmsContext, \"plugins\">;\n model: CmsModel;\n field: CmsModelField;\n value: any;\n}\n/*\n * A function that is used to transform a single field from storage\n */\nexport const entryFieldFromStorageTransform = async <T = any>(\n params: EntryFieldFromStorageTransformParams\n): Promise<T> => {\n const { context, model, field, value } = params;\n const getStoragePlugin = getStoragePluginFactory(context);\n\n const baseType = getBaseFieldType(field);\n const plugin = getStoragePlugin(baseType);\n\n // TODO: remove this once plugins are converted into classes\n if (typeof plugin.fromStorage !== \"function\") {\n throw new WebinyError(\n `Missing \"fromStorage\" function in storage plugin \"${plugin.name}\" for field type \"${baseType}\"`\n );\n }\n\n return plugin.fromStorage({\n plugins: context.plugins,\n model,\n field,\n value,\n getStoragePlugin\n });\n};\n\nexport interface ICreateTransformEntryCallable {\n context: Pick<CmsContext, \"plugins\">;\n}\n\nexport interface ITransformEntryCallable<T extends CmsEntryValues = CmsEntryValues> {\n (model: CmsModel, entry: CmsEntry): Promise<CmsEntry<T>>;\n}\n\nexport const createTransformEntryCallable = (\n params: ICreateTransformEntryCallable\n): ITransformEntryCallable => {\n const { context } = params;\n\n return async (model, entry) => {\n return entryFromStorageTransform(context, model, entry);\n };\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,uBAAA,GAAAD,OAAA;AAEA,IAAAE,iBAAA,GAAAF,OAAA;AAMO,MAAMG,uBAAgD,GAAGC,OAAO,IAAI;EACvE,IAAIC,oBAA4C;EAEhD,MAAMC,OAAO,GAAGF,OAAO,CAACE,OAAO,CAC1BC,MAAM,CAAyBC,8CAAsB,CAACC,IAAI;EAC3D;EAAA,CACCC,OAAO,CAAC,CAAC,CACTC,MAAM,CAAC,CAACC,UAAU,EAAEC,MAAM,KAAK;IAC5B;AACZ;AACA;IACY,IAAIA,MAAM,CAACC,SAAS,KAAK,GAAG,EAAE;MAC1BT,oBAAoB,GAAGQ,MAAM;MAC7B,OAAOD,UAAU;IACrB;;IAEA;AACZ;AACA;AACA;IACYA,UAAU,CAACC,MAAM,CAACC,SAAS,CAAC,GAAGD,MAAM;IAErC,OAAOD,UAAU;EACrB,CAAC,EAAE,CAAC,CAA2C,CAAC;EAEpD,OAAQE,SAAiB,IAAK;IAC1B,OAAOR,OAAO,CAACQ,SAAS,CAAC,IAAIT,oBAAoB;EACrD,CAAC;AACL,CAAC;AAACU,OAAA,CAAAZ,uBAAA,GAAAA,uBAAA;AAEF,MAAMa,kBAAkB,GAAGC,MAAM,CAAC,4DAA4D,CAAC;;AAE/F;AAC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