@webiny/api-headless-cms 5.40.1 → 5.40.2-beta.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.
Files changed (39) hide show
  1. package/crud/contentEntry/referenceFieldsMapping.js +8 -8
  2. package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
  3. package/crud/contentModel/validation.d.ts +21 -21
  4. package/crud/contentModel/validation.js +1 -1
  5. package/crud/contentModel/validation.js.map +1 -1
  6. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +22 -54
  7. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -1
  8. package/graphql/schema/createManageResolvers.js +21 -48
  9. package/graphql/schema/createManageResolvers.js.map +1 -1
  10. package/graphql/schema/createPreviewResolvers.js +4 -2
  11. package/graphql/schema/createPreviewResolvers.js.map +1 -1
  12. package/graphql/schema/createReadResolvers.js +4 -2
  13. package/graphql/schema/createReadResolvers.js.map +1 -1
  14. package/graphql/schema/resolvers/manage/normalizeGraphQlInput.d.ts +7 -0
  15. package/graphql/schema/resolvers/manage/normalizeGraphQlInput.js +59 -0
  16. package/graphql/schema/resolvers/manage/normalizeGraphQlInput.js.map +1 -0
  17. package/graphqlFields/dynamicZone/dynamicZoneField.js +43 -15
  18. package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -1
  19. package/graphqlFields/dynamicZone/index.d.ts +0 -1
  20. package/graphqlFields/dynamicZone/index.js +0 -7
  21. package/graphqlFields/dynamicZone/index.js.map +1 -1
  22. package/index.d.ts +2 -1
  23. package/index.js +13 -2
  24. package/index.js.map +1 -1
  25. package/package.json +20 -20
  26. package/types/modelAst.d.ts +1 -1
  27. package/types/modelAst.js.map +1 -1
  28. package/types/modelField.d.ts +3 -2
  29. package/types/modelField.js.map +1 -1
  30. package/types/plugins.d.ts +2 -1
  31. package/types/plugins.js.map +1 -1
  32. package/types/types.d.ts +6 -0
  33. package/types/types.js.map +1 -1
  34. package/utils/contentEntryTraverser/ContentEntryTraverser.d.ts +1 -1
  35. package/utils/contentEntryTraverser/ContentEntryTraverser.js +28 -15
  36. package/utils/contentEntryTraverser/ContentEntryTraverser.js.map +1 -1
  37. package/graphqlFields/dynamicZone/dynamicZoneStorage.d.ts +0 -3
  38. package/graphqlFields/dynamicZone/dynamicZoneStorage.js +0 -111
  39. package/graphqlFields/dynamicZone/dynamicZoneStorage.js.map +0 -1
@@ -53,15 +53,14 @@ const buildReferenceFieldPaths = params => {
53
53
  return collection;
54
54
  }
55
55
  values.forEach((value, index) => {
56
- const valueTemplate = Object.keys(value)[0];
57
- const template = templates.find(tpl => tpl.gqlTypeName === valueTemplate);
56
+ const template = templates.find(tpl => tpl.id === value["_templateId"]);
58
57
  if (!template) {
59
58
  return;
60
59
  }
61
60
  const result = buildReferenceFieldPaths({
62
61
  fields: template.fields,
63
- input: value[valueTemplate],
64
- parentPaths: parentPaths.concat([field.fieldId, String(index), template.gqlTypeName])
62
+ input: value,
63
+ parentPaths: parentPaths.concat([field.fieldId, String(index)])
65
64
  });
66
65
  collection.push(...result);
67
66
  });
@@ -71,15 +70,16 @@ const buildReferenceFieldPaths = params => {
71
70
  if (!value) {
72
71
  return collection;
73
72
  }
74
- const valueTemplate = Object.keys(value)[0];
75
- const template = templates.find(tpl => tpl.gqlTypeName === valueTemplate);
73
+
74
+ // @ts-expect-error We're sure that a template value contains a _templateId property.
75
+ const template = templates.find(tpl => tpl.id === value["_templateId"]);
76
76
  if (!template) {
77
77
  return collection;
78
78
  }
79
79
  const result = buildReferenceFieldPaths({
80
80
  fields: template.fields,
81
- input: _dotProp.default.get(value, valueTemplate, {}),
82
- parentPaths: parentPaths.concat([field.fieldId, template.gqlTypeName])
81
+ input: value ?? {},
82
+ parentPaths: parentPaths.concat([field.fieldId])
83
83
  });
84
84
  collection.push(...result);
85
85
  return collection;
@@ -1 +1 @@
1
- {"version":3,"names":["_dotProp","_interopRequireDefault","require","_error","_utils","_getBaseFieldType","buildReferenceFieldPaths","params","fields","parentPaths","initialParentPaths","input","isMultipleValues","Array","isArray","filter","field","includes","getBaseFieldType","reduce","collection","baseType","parentPathsValue","length","join","multipleValues","inputValue","dotProp","get","fieldId","key","path","push","templates","settings","values","forEach","value","index","valueTemplate","Object","keys","template","find","tpl","gqlTypeName","result","concat","String","objFieldPath","objFieldInputValue","results","getReferenceFieldValue","ref","id","modelId","entryId","trim","referenceFieldsMapping","context","model","validateEntries","output","referenceFieldPaths","validateReferencedEntries","refValue","maybeEntryId","parseIdentifier","set","exports","referencesByModel","Map","has","size","models","security","withoutAuthorization","cms","listModels","entries","promises","map","getEntriesByIds","allEntries","Promise","all","then","res","flat","entriesByModel","acc","entry","ids","modelEntriesInDb","WebinyError"],"sources":["referenceFieldsMapping.ts"],"sourcesContent":["import dotProp from \"dot-prop\";\nimport WebinyError from \"@webiny/error\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\nimport { CmsContext, CmsDynamicZoneTemplate, CmsModel, CmsModelField } from \"~/types\";\n\ninterface CmsRefEntry {\n id: string;\n entryId: string;\n modelId: string;\n}\n\ntype RefValue = Pick<CmsRefEntry, \"id\" | \"modelId\"> & {\n entryId?: string;\n};\n\ninterface ReferenceObject {\n id: string;\n modelId: string;\n}\n\ninterface Params {\n context: CmsContext;\n model: CmsModel;\n input: Record<string, ReferenceObject | ReferenceObject[]>;\n validateEntries?: boolean;\n}\n\ninterface BuildReferenceFieldPaths {\n fields: CmsModelField[];\n parentPaths: string[];\n input: Record<string, any>;\n}\n\nconst buildReferenceFieldPaths = (params: BuildReferenceFieldPaths): string[] => {\n const { fields, parentPaths: initialParentPaths, input } = params;\n\n const parentPaths = [...initialParentPaths];\n\n const isMultipleValues = Array.isArray(input);\n\n return fields\n .filter(field => [\"object\", \"ref\", \"dynamicZone\"].includes(getBaseFieldType(field)))\n .reduce((collection, field) => {\n /**\n * First we check the ref field\n */\n const baseType = getBaseFieldType(field);\n if (baseType === \"ref\") {\n const parentPathsValue = parentPaths.length > 0 ? `${parentPaths.join(\".\")}.` : \"\";\n if (field.multipleValues) {\n const inputValue = dotProp.get(input, `${field.fieldId}`, []);\n if (!Array.isArray(inputValue)) {\n return collection;\n }\n\n for (const key in inputValue) {\n const path = `${parentPathsValue}${field.fieldId}.${key}`;\n collection.push(path);\n }\n return collection;\n }\n\n if (isMultipleValues) {\n for (const key in input) {\n const path = `${parentPathsValue}${key}.${field.fieldId}`;\n collection.push(path);\n }\n return collection;\n }\n\n collection.push(`${parentPathsValue}${field.fieldId}`);\n\n return collection;\n }\n\n if (baseType === \"dynamicZone\") {\n const templates: CmsDynamicZoneTemplate[] = field.settings?.templates || [];\n\n if (field.multipleValues) {\n const values = dotProp.get(input, field.fieldId, []);\n if (!Array.isArray(values)) {\n return collection;\n }\n\n values.forEach((value, index) => {\n const valueTemplate = Object.keys(value)[0];\n const template = templates.find(tpl => tpl.gqlTypeName === valueTemplate);\n if (!template) {\n return;\n }\n\n const result = buildReferenceFieldPaths({\n fields: template.fields,\n input: value[valueTemplate],\n parentPaths: parentPaths.concat([\n field.fieldId,\n String(index),\n template.gqlTypeName\n ])\n });\n\n collection.push(...result);\n });\n\n return collection;\n }\n\n const value = dotProp.get(input, field.fieldId, {});\n if (!value) {\n return collection;\n }\n\n const valueTemplate = Object.keys(value)[0];\n const template = templates.find(tpl => tpl.gqlTypeName === valueTemplate);\n\n if (!template) {\n return collection;\n }\n\n const result = buildReferenceFieldPaths({\n fields: template.fields,\n input: dotProp.get(value, valueTemplate, {}),\n parentPaths: parentPaths.concat([field.fieldId, template.gqlTypeName])\n });\n collection.push(...result);\n\n return collection;\n }\n\n /**\n * Then we move onto the object field\n */\n const parentPathsValue = parentPaths.length > 0 ? `${parentPaths.join(\".\")}.` : \"\";\n /**\n * This is if received input is array. We need to map key with fieldId at this point.\n */\n if (isMultipleValues) {\n for (const key in input) {\n const path = `${parentPathsValue}${key}.${field.fieldId}`;\n collection.push(path);\n }\n return collection;\n }\n\n const objFieldPath = `${field.fieldId}`;\n const objFieldInputValue = dotProp.get(input, objFieldPath, []);\n\n /**\n * If field is multiple values one, we need to go through the input and use the existing keys.\n */\n if (field.multipleValues) {\n if (Array.isArray(objFieldInputValue) === false) {\n return collection;\n }\n for (const key in objFieldInputValue) {\n const result = buildReferenceFieldPaths({\n fields: field.settings?.fields || [],\n input: objFieldInputValue[key],\n parentPaths: parentPaths.concat([field.fieldId, key])\n });\n collection.push(...result);\n }\n\n return collection;\n }\n\n /**\n * Single value reference field.\n */\n const results = buildReferenceFieldPaths({\n fields: field.settings?.fields || [],\n input: objFieldInputValue,\n parentPaths: parentPaths.concat([field.fieldId])\n });\n\n return collection.concat(results);\n }, [] as string[]);\n};\n\nconst getReferenceFieldValue = (ref: any): { id: string | null; modelId: string | null } => {\n if (!ref) {\n return {\n id: null,\n modelId: null\n };\n }\n return {\n id: (ref.id || ref.entryId || \"\").trim() || null,\n modelId: (ref.modelId || \"\").trim() || null\n };\n};\n\n/**\n * This function traverses the content entry input value, extracts all occurrences of the `ref` field,\n * optionally verifies that those referenced entries exist (by loading them), and normalizes the `ref` value to\n * always contain `{ id, modelId, entryId }`. `entryId` is important when data is being loaded via\n * the `read` and `preview` endpoint.\n */\nexport const referenceFieldsMapping = async (params: Params): Promise<Record<string, any>> => {\n const { context, model, input, validateEntries = false } = params;\n\n let output: Record<string, any> = {\n ...input\n };\n\n const referenceFieldPaths = buildReferenceFieldPaths({\n fields: model.fields,\n input,\n parentPaths: []\n });\n\n if (!referenceFieldPaths.length) {\n return output;\n }\n\n if (validateEntries) {\n await validateReferencedEntries({ output, context, referenceFieldPaths });\n }\n\n /**\n * Assign the entryId, id and model values to the output.\n */\n for (const path of referenceFieldPaths) {\n // It is safe to cast here, because `referenceFieldPaths` array is generated from the `input`.\n const refValue: RefValue | undefined = dotProp.get(input, path);\n if (!refValue) {\n continue;\n }\n\n /**\n * Over time, the structure of `RefInput` was changing, and we need to handle different cases for backwards\n * compatibility. The latest valid structure of a `ref` field value is { id, modelId }, but we also need\n * to make sure that the legacy structure { entryId, modelId } is supported.\n */\n const { id, modelId, entryId: maybeEntryId } = refValue;\n\n const { id: entryId } = parseIdentifier(maybeEntryId || id);\n\n output = dotProp.set(output, path, {\n // If `id` is not set, we're dealing with the legacy structure.\n id: id ?? maybeEntryId,\n entryId,\n modelId\n });\n }\n\n return output;\n};\n\ninterface ValidateReferencedEntriesParams {\n output: Record<string, any>;\n context: CmsContext;\n referenceFieldPaths: string[];\n}\n\nasync function validateReferencedEntries({\n output,\n context,\n referenceFieldPaths\n}: ValidateReferencedEntriesParams) {\n const referencesByModel = new Map<string, string[]>();\n\n /**\n * Group references by modelId.\n */\n for (const path of referenceFieldPaths) {\n const ref = dotProp.get(output, path) as ReferenceObject | any;\n\n const { id, modelId } = getReferenceFieldValue(ref);\n\n if (!id || !modelId) {\n continue;\n }\n\n if (!referencesByModel.has(modelId)) {\n referencesByModel.set(modelId, []);\n }\n\n referencesByModel.get(modelId)?.push(id);\n }\n\n if (!referencesByModel.size) {\n return;\n }\n\n /**\n * Load all models and use only those that are used in reference.\n */\n const models = await context.security.withoutAuthorization(async () => {\n return (await context.cms.listModels()).filter(model => {\n const entries = referencesByModel.get(model.modelId);\n if (!Array.isArray(entries) || entries.length === 0) {\n return false;\n }\n return true;\n });\n });\n\n if (!models.length) {\n return;\n }\n\n /**\n * Load all the entries by their IDs.\n */\n const promises = await context.security.withoutAuthorization(async () => {\n return models.map(model => {\n return context.cms.getEntriesByIds(model, referencesByModel.get(model.modelId) || []);\n });\n });\n\n const allEntries = await Promise.all(promises).then(res => res.flat());\n const entriesByModel = allEntries.reduce<Record<string, string[]>>((acc, entry) => {\n return { ...acc, [entry.modelId]: [...(acc[entry.modelId] || []), entry.id] };\n }, {});\n\n /**\n * Verify that all entries exist.\n */\n referencesByModel.forEach((ids, modelId) => {\n const modelEntriesInDb = entriesByModel[modelId];\n for (const id of ids) {\n if (!modelEntriesInDb || !modelEntriesInDb.includes(id)) {\n throw new WebinyError(\n `Missing referenced entry with id \"${id}\" in model \"${modelId}\".`,\n \"ENTRY_NOT_FOUND\",\n {\n id,\n model: modelId\n }\n );\n }\n }\n });\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AA+BA,MAAMI,wBAAwB,GAAIC,MAAgC,IAAe;EAC7E,MAAM;IAAEC,MAAM;IAAEC,WAAW,EAAEC,kBAAkB;IAAEC;EAAM,CAAC,GAAGJ,MAAM;EAEjE,MAAME,WAAW,GAAG,CAAC,GAAGC,kBAAkB,CAAC;EAE3C,MAAME,gBAAgB,GAAGC,KAAK,CAACC,OAAO,CAACH,KAAK,CAAC;EAE7C,OAAOH,MAAM,CACRO,MAAM,CAACC,KAAK,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,aAAa,CAAC,CAACC,QAAQ,CAAC,IAAAC,kCAAgB,EAACF,KAAK,CAAC,CAAC,CAAC,CACnFG,MAAM,CAAC,CAACC,UAAU,EAAEJ,KAAK,KAAK;IAC3B;AACZ;AACA;IACY,MAAMK,QAAQ,GAAG,IAAAH,kCAAgB,EAACF,KAAK,CAAC;IACxC,IAAIK,QAAQ,KAAK,KAAK,EAAE;MACpB,MAAMC,gBAAgB,GAAGb,WAAW,CAACc,MAAM,GAAG,CAAC,GAAI,GAAEd,WAAW,CAACe,IAAI,CAAC,GAAG,CAAE,GAAE,GAAG,EAAE;MAClF,IAAIR,KAAK,CAACS,cAAc,EAAE;QACtB,MAAMC,UAAU,GAAGC,gBAAO,CAACC,GAAG,CAACjB,KAAK,EAAG,GAAEK,KAAK,CAACa,OAAQ,EAAC,EAAE,EAAE,CAAC;QAC7D,IAAI,CAAChB,KAAK,CAACC,OAAO,CAACY,UAAU,CAAC,EAAE;UAC5B,OAAON,UAAU;QACrB;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ACA;EACIgB,iBAAiB,CAAClC,OAAO,CAAC,CAACwD,GAAG,EAAErC,OAAO,KAAK;IACxC,MAAMsC,gBAAgB,GAAGJ,cAAc,CAAClC,OAAO,CAAC;IAChD,KAAK,MAAMD,EAAE,IAAIsC,GAAG,EAAE;MAClB,IAAI,CAACC,gBAAgB,IAAI,CAACA,gBAAgB,CAAC5E,QAAQ,CAACqC,EAAE,CAAC,EAAE;QACrD,MAAM,IAAIwC,cAAW,CAChB,qCAAoCxC,EAAG,eAAcC,OAAQ,IAAG,EACjE,iBAAiB,EACjB;UACID,EAAE;UACFM,KAAK,EAAEL;QACX,CACJ,CAAC;MACL;IACJ;EACJ,CAAC,CAAC;AACN","ignoreList":[]}
1
+ {"version":3,"names":["_dotProp","_interopRequireDefault","require","_error","_utils","_getBaseFieldType","buildReferenceFieldPaths","params","fields","parentPaths","initialParentPaths","input","isMultipleValues","Array","isArray","filter","field","includes","getBaseFieldType","reduce","collection","baseType","parentPathsValue","length","join","multipleValues","inputValue","dotProp","get","fieldId","key","path","push","templates","settings","values","forEach","value","index","template","find","tpl","id","result","concat","String","objFieldPath","objFieldInputValue","results","getReferenceFieldValue","ref","modelId","entryId","trim","referenceFieldsMapping","context","model","validateEntries","output","referenceFieldPaths","validateReferencedEntries","refValue","maybeEntryId","parseIdentifier","set","exports","referencesByModel","Map","has","size","models","security","withoutAuthorization","cms","listModels","entries","promises","map","getEntriesByIds","allEntries","Promise","all","then","res","flat","entriesByModel","acc","entry","ids","modelEntriesInDb","WebinyError"],"sources":["referenceFieldsMapping.ts"],"sourcesContent":["import dotProp from \"dot-prop\";\nimport WebinyError from \"@webiny/error\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\nimport { CmsContext, CmsDynamicZoneTemplate, CmsModel, CmsModelField } from \"~/types\";\n\ninterface CmsRefEntry {\n id: string;\n entryId: string;\n modelId: string;\n}\n\ntype RefValue = Pick<CmsRefEntry, \"id\" | \"modelId\"> & {\n entryId?: string;\n};\n\ninterface ReferenceObject {\n id: string;\n modelId: string;\n}\n\ninterface Params {\n context: CmsContext;\n model: CmsModel;\n input: Record<string, ReferenceObject | ReferenceObject[]>;\n validateEntries?: boolean;\n}\n\ninterface BuildReferenceFieldPaths {\n fields: CmsModelField[];\n parentPaths: string[];\n input: Record<string, any>;\n}\n\nconst buildReferenceFieldPaths = (params: BuildReferenceFieldPaths): string[] => {\n const { fields, parentPaths: initialParentPaths, input } = params;\n\n const parentPaths = [...initialParentPaths];\n\n const isMultipleValues = Array.isArray(input);\n\n return fields\n .filter(field => [\"object\", \"ref\", \"dynamicZone\"].includes(getBaseFieldType(field)))\n .reduce((collection, field) => {\n /**\n * First we check the ref field\n */\n const baseType = getBaseFieldType(field);\n if (baseType === \"ref\") {\n const parentPathsValue = parentPaths.length > 0 ? `${parentPaths.join(\".\")}.` : \"\";\n if (field.multipleValues) {\n const inputValue = dotProp.get(input, `${field.fieldId}`, []);\n if (!Array.isArray(inputValue)) {\n return collection;\n }\n\n for (const key in inputValue) {\n const path = `${parentPathsValue}${field.fieldId}.${key}`;\n collection.push(path);\n }\n return collection;\n }\n\n if (isMultipleValues) {\n for (const key in input) {\n const path = `${parentPathsValue}${key}.${field.fieldId}`;\n collection.push(path);\n }\n return collection;\n }\n\n collection.push(`${parentPathsValue}${field.fieldId}`);\n\n return collection;\n }\n\n if (baseType === \"dynamicZone\") {\n const templates: CmsDynamicZoneTemplate[] = field.settings?.templates || [];\n\n if (field.multipleValues) {\n const values = dotProp.get(input, field.fieldId, []);\n if (!Array.isArray(values)) {\n return collection;\n }\n\n values.forEach((value, index) => {\n const template = templates.find(tpl => tpl.id === value[\"_templateId\"]);\n if (!template) {\n return;\n }\n\n const result = buildReferenceFieldPaths({\n fields: template.fields,\n input: value,\n parentPaths: parentPaths.concat([field.fieldId, String(index)])\n });\n\n collection.push(...result);\n });\n\n return collection;\n }\n\n const value = dotProp.get(input, field.fieldId, {});\n if (!value) {\n return collection;\n }\n\n // @ts-expect-error We're sure that a template value contains a _templateId property.\n const template = templates.find(tpl => tpl.id === value[\"_templateId\"]);\n\n if (!template) {\n return collection;\n }\n\n const result = buildReferenceFieldPaths({\n fields: template.fields,\n input: value ?? {},\n parentPaths: parentPaths.concat([field.fieldId])\n });\n collection.push(...result);\n\n return collection;\n }\n\n /**\n * Then we move onto the object field\n */\n const parentPathsValue = parentPaths.length > 0 ? `${parentPaths.join(\".\")}.` : \"\";\n /**\n * This is if received input is array. We need to map key with fieldId at this point.\n */\n if (isMultipleValues) {\n for (const key in input) {\n const path = `${parentPathsValue}${key}.${field.fieldId}`;\n collection.push(path);\n }\n return collection;\n }\n\n const objFieldPath = `${field.fieldId}`;\n const objFieldInputValue = dotProp.get(input, objFieldPath, []);\n\n /**\n * If field is multiple values one, we need to go through the input and use the existing keys.\n */\n if (field.multipleValues) {\n if (Array.isArray(objFieldInputValue) === false) {\n return collection;\n }\n for (const key in objFieldInputValue) {\n const result = buildReferenceFieldPaths({\n fields: field.settings?.fields || [],\n input: objFieldInputValue[key],\n parentPaths: parentPaths.concat([field.fieldId, key])\n });\n collection.push(...result);\n }\n\n return collection;\n }\n\n /**\n * Single value reference field.\n */\n const results = buildReferenceFieldPaths({\n fields: field.settings?.fields || [],\n input: objFieldInputValue,\n parentPaths: parentPaths.concat([field.fieldId])\n });\n\n return collection.concat(results);\n }, [] as string[]);\n};\n\nconst getReferenceFieldValue = (ref: any): { id: string | null; modelId: string | null } => {\n if (!ref) {\n return {\n id: null,\n modelId: null\n };\n }\n return {\n id: (ref.id || ref.entryId || \"\").trim() || null,\n modelId: (ref.modelId || \"\").trim() || null\n };\n};\n\n/**\n * This function traverses the content entry input value, extracts all occurrences of the `ref` field,\n * optionally verifies that those referenced entries exist (by loading them), and normalizes the `ref` value to\n * always contain `{ id, modelId, entryId }`. `entryId` is important when data is being loaded via\n * the `read` and `preview` endpoint.\n */\nexport const referenceFieldsMapping = async (params: Params): Promise<Record<string, any>> => {\n const { context, model, input, validateEntries = false } = params;\n\n let output: Record<string, any> = {\n ...input\n };\n\n const referenceFieldPaths = buildReferenceFieldPaths({\n fields: model.fields,\n input,\n parentPaths: []\n });\n\n if (!referenceFieldPaths.length) {\n return output;\n }\n\n if (validateEntries) {\n await validateReferencedEntries({ output, context, referenceFieldPaths });\n }\n\n /**\n * Assign the entryId, id and model values to the output.\n */\n for (const path of referenceFieldPaths) {\n // It is safe to cast here, because `referenceFieldPaths` array is generated from the `input`.\n const refValue: RefValue | undefined = dotProp.get(input, path);\n if (!refValue) {\n continue;\n }\n\n /**\n * Over time, the structure of `RefInput` was changing, and we need to handle different cases for backwards\n * compatibility. The latest valid structure of a `ref` field value is { id, modelId }, but we also need\n * to make sure that the legacy structure { entryId, modelId } is supported.\n */\n const { id, modelId, entryId: maybeEntryId } = refValue;\n\n const { id: entryId } = parseIdentifier(maybeEntryId || id);\n\n output = dotProp.set(output, path, {\n // If `id` is not set, we're dealing with the legacy structure.\n id: id ?? maybeEntryId,\n entryId,\n modelId\n });\n }\n\n return output;\n};\n\ninterface ValidateReferencedEntriesParams {\n output: Record<string, any>;\n context: CmsContext;\n referenceFieldPaths: string[];\n}\n\nasync function validateReferencedEntries({\n output,\n context,\n referenceFieldPaths\n}: ValidateReferencedEntriesParams) {\n const referencesByModel = new Map<string, string[]>();\n\n /**\n * Group references by modelId.\n */\n for (const path of referenceFieldPaths) {\n const ref = dotProp.get(output, path) as ReferenceObject | any;\n\n const { id, modelId } = getReferenceFieldValue(ref);\n\n if (!id || !modelId) {\n continue;\n }\n\n if (!referencesByModel.has(modelId)) {\n referencesByModel.set(modelId, []);\n }\n\n referencesByModel.get(modelId)?.push(id);\n }\n\n if (!referencesByModel.size) {\n return;\n }\n\n /**\n * Load all models and use only those that are used in reference.\n */\n const models = await context.security.withoutAuthorization(async () => {\n return (await context.cms.listModels()).filter(model => {\n const entries = referencesByModel.get(model.modelId);\n if (!Array.isArray(entries) || entries.length === 0) {\n return false;\n }\n return true;\n });\n });\n\n if (!models.length) {\n return;\n }\n\n /**\n * Load all the entries by their IDs.\n */\n const promises = await context.security.withoutAuthorization(async () => {\n return models.map(model => {\n return context.cms.getEntriesByIds(model, referencesByModel.get(model.modelId) || []);\n });\n });\n\n const allEntries = await Promise.all(promises).then(res => res.flat());\n const entriesByModel = allEntries.reduce<Record<string, string[]>>((acc, entry) => {\n return { ...acc, [entry.modelId]: [...(acc[entry.modelId] || []), entry.id] };\n }, {});\n\n /**\n * Verify that all entries exist.\n */\n referencesByModel.forEach((ids, modelId) => {\n const modelEntriesInDb = entriesByModel[modelId];\n for (const id of ids) {\n if (!modelEntriesInDb || !modelEntriesInDb.includes(id)) {\n throw new WebinyError(\n `Missing referenced entry with id \"${id}\" in model \"${modelId}\".`,\n \"ENTRY_NOT_FOUND\",\n {\n id,\n model: modelId\n }\n );\n }\n }\n });\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AA+BA,MAAMI,wBAAwB,GAAIC,MAAgC,IAAe;EAC7E,MAAM;IAAEC,MAAM;IAAEC,WAAW,EAAEC,kBAAkB;IAAEC;EAAM,CAAC,GAAGJ,MAAM;EAEjE,MAAME,WAAW,GAAG,CAAC,GAAGC,kBAAkB,CAAC;EAE3C,MAAME,gBAAgB,GAAGC,KAAK,CAACC,OAAO,CAACH,KAAK,CAAC;EAE7C,OAAOH,MAAM,CACRO,MAAM,CAACC,KAAK,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,aAAa,CAAC,CAACC,QAAQ,CAAC,IAAAC,kCAAgB,EAACF,KAAK,CAAC,CAAC,CAAC,CACnFG,MAAM,CAAC,CAACC,UAAU,EAAEJ,KAAK,KAAK;IAC3B;AACZ;AACA;IACY,MAAMK,QAAQ,GAAG,IAAAH,kCAAgB,EAACF,KAAK,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pC,OAAO,GAAG,CAAC,IAAImC,GAAG,CAACC,KAAK,CAACpC,OAAO,CAAC,IAAI,EAAE,CAAC,EAAEoC,KAAK,CAAC7C,EAAE;IAAE,CAAC;EACjF,CAAC,EAAE,CAAC,CAAC,CAAC;;EAEN;AACJ;AACA;EACIwB,iBAAiB,CAAC9B,OAAO,CAAC,CAACoD,GAAG,EAAErC,OAAO,KAAK;IACxC,MAAMsC,gBAAgB,GAAGJ,cAAc,CAAClC,OAAO,CAAC;IAChD,KAAK,MAAMT,EAAE,IAAI8C,GAAG,EAAE;MAClB,IAAI,CAACC,gBAAgB,IAAI,CAACA,gBAAgB,CAACxE,QAAQ,CAACyB,EAAE,CAAC,EAAE;QACrD,MAAM,IAAIgD,cAAW,CAChB,qCAAoChD,EAAG,eAAcS,OAAQ,IAAG,EACjE,iBAAiB,EACjB;UACIT,EAAE;UACFc,KAAK,EAAEL;QACX,CACJ,CAAC;MACL;IACJ;EACJ,CAAC,CAAC;AACN","ignoreList":[]}
@@ -49,13 +49,13 @@ export declare const createModelCreateValidation: () => zod.ZodObject<{
49
49
  }>>>;
50
50
  renderer: zod.ZodDefault<zod.ZodNullable<zod.ZodOptional<zod.ZodObject<{
51
51
  name: zod.ZodString;
52
- settings: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
52
+ settings: zod.ZodOptional<zod.ZodOptional<zod.ZodNullable<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>>>;
53
53
  }, "strip", zod.ZodTypeAny, {
54
54
  name: string;
55
- settings?: zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough"> | undefined;
55
+ settings?: zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough"> | null | undefined;
56
56
  }, {
57
57
  name: string;
58
- settings?: zod.objectInputType<{}, zod.ZodTypeAny, "passthrough"> | undefined;
58
+ settings?: zod.objectInputType<{}, zod.ZodTypeAny, "passthrough"> | null | undefined;
59
59
  }>>>>;
60
60
  validation: zod.ZodEffects<zod.ZodDefault<zod.ZodOptional<zod.ZodOptional<zod.ZodNullable<zod.ZodArray<zod.ZodObject<{
61
61
  name: zod.ZodString;
@@ -118,7 +118,7 @@ export declare const createModelCreateValidation: () => zod.ZodObject<{
118
118
  placeholderText: string | null;
119
119
  renderer: {
120
120
  name: string;
121
- settings?: zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough"> | undefined;
121
+ settings?: zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough"> | null | undefined;
122
122
  } | null;
123
123
  validation: {
124
124
  name: string;
@@ -167,7 +167,7 @@ export declare const createModelCreateValidation: () => zod.ZodObject<{
167
167
  } | undefined;
168
168
  renderer?: {
169
169
  name: string;
170
- settings?: zod.objectInputType<{}, zod.ZodTypeAny, "passthrough"> | undefined;
170
+ settings?: zod.objectInputType<{}, zod.ZodTypeAny, "passthrough"> | null | undefined;
171
171
  } | null | undefined;
172
172
  validation?: {
173
173
  name: string;
@@ -199,7 +199,7 @@ export declare const createModelCreateValidation: () => zod.ZodObject<{
199
199
  placeholderText: string | null;
200
200
  renderer: {
201
201
  name: string;
202
- settings?: zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough"> | undefined;
202
+ settings?: zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough"> | null | undefined;
203
203
  } | null;
204
204
  validation: {
205
205
  name: string;
@@ -269,7 +269,7 @@ export declare const createModelCreateValidation: () => zod.ZodObject<{
269
269
  } | undefined;
270
270
  renderer?: {
271
271
  name: string;
272
- settings?: zod.objectInputType<{}, zod.ZodTypeAny, "passthrough"> | undefined;
272
+ settings?: zod.objectInputType<{}, zod.ZodTypeAny, "passthrough"> | null | undefined;
273
273
  } | null | undefined;
274
274
  validation?: {
275
275
  name: string;
@@ -340,13 +340,13 @@ export declare const createModelImportValidation: () => zod.ZodObject<{
340
340
  }>>>;
341
341
  renderer: zod.ZodDefault<zod.ZodNullable<zod.ZodOptional<zod.ZodObject<{
342
342
  name: zod.ZodString;
343
- settings: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
343
+ settings: zod.ZodOptional<zod.ZodOptional<zod.ZodNullable<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>>>;
344
344
  }, "strip", zod.ZodTypeAny, {
345
345
  name: string;
346
- settings?: zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough"> | undefined;
346
+ settings?: zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough"> | null | undefined;
347
347
  }, {
348
348
  name: string;
349
- settings?: zod.objectInputType<{}, zod.ZodTypeAny, "passthrough"> | undefined;
349
+ settings?: zod.objectInputType<{}, zod.ZodTypeAny, "passthrough"> | null | undefined;
350
350
  }>>>>;
351
351
  validation: zod.ZodEffects<zod.ZodDefault<zod.ZodOptional<zod.ZodOptional<zod.ZodNullable<zod.ZodArray<zod.ZodObject<{
352
352
  name: zod.ZodString;
@@ -409,7 +409,7 @@ export declare const createModelImportValidation: () => zod.ZodObject<{
409
409
  placeholderText: string | null;
410
410
  renderer: {
411
411
  name: string;
412
- settings?: zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough"> | undefined;
412
+ settings?: zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough"> | null | undefined;
413
413
  } | null;
414
414
  validation: {
415
415
  name: string;
@@ -458,7 +458,7 @@ export declare const createModelImportValidation: () => zod.ZodObject<{
458
458
  } | undefined;
459
459
  renderer?: {
460
460
  name: string;
461
- settings?: zod.objectInputType<{}, zod.ZodTypeAny, "passthrough"> | undefined;
461
+ settings?: zod.objectInputType<{}, zod.ZodTypeAny, "passthrough"> | null | undefined;
462
462
  } | null | undefined;
463
463
  validation?: {
464
464
  name: string;
@@ -489,7 +489,7 @@ export declare const createModelImportValidation: () => zod.ZodObject<{
489
489
  placeholderText: string | null;
490
490
  renderer: {
491
491
  name: string;
492
- settings?: zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough"> | undefined;
492
+ settings?: zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough"> | null | undefined;
493
493
  } | null;
494
494
  validation: {
495
495
  name: string;
@@ -552,7 +552,7 @@ export declare const createModelImportValidation: () => zod.ZodObject<{
552
552
  } | undefined;
553
553
  renderer?: {
554
554
  name: string;
555
- settings?: zod.objectInputType<{}, zod.ZodTypeAny, "passthrough"> | undefined;
555
+ settings?: zod.objectInputType<{}, zod.ZodTypeAny, "passthrough"> | null | undefined;
556
556
  } | null | undefined;
557
557
  validation?: {
558
558
  name: string;
@@ -655,13 +655,13 @@ export declare const createModelUpdateValidation: () => zod.ZodObject<{
655
655
  }>>>;
656
656
  renderer: zod.ZodDefault<zod.ZodNullable<zod.ZodOptional<zod.ZodObject<{
657
657
  name: zod.ZodString;
658
- settings: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
658
+ settings: zod.ZodOptional<zod.ZodOptional<zod.ZodNullable<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>>>;
659
659
  }, "strip", zod.ZodTypeAny, {
660
660
  name: string;
661
- settings?: zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough"> | undefined;
661
+ settings?: zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough"> | null | undefined;
662
662
  }, {
663
663
  name: string;
664
- settings?: zod.objectInputType<{}, zod.ZodTypeAny, "passthrough"> | undefined;
664
+ settings?: zod.objectInputType<{}, zod.ZodTypeAny, "passthrough"> | null | undefined;
665
665
  }>>>>;
666
666
  validation: zod.ZodEffects<zod.ZodDefault<zod.ZodOptional<zod.ZodOptional<zod.ZodNullable<zod.ZodArray<zod.ZodObject<{
667
667
  name: zod.ZodString;
@@ -724,7 +724,7 @@ export declare const createModelUpdateValidation: () => zod.ZodObject<{
724
724
  placeholderText: string | null;
725
725
  renderer: {
726
726
  name: string;
727
- settings?: zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough"> | undefined;
727
+ settings?: zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough"> | null | undefined;
728
728
  } | null;
729
729
  validation: {
730
730
  name: string;
@@ -773,7 +773,7 @@ export declare const createModelUpdateValidation: () => zod.ZodObject<{
773
773
  } | undefined;
774
774
  renderer?: {
775
775
  name: string;
776
- settings?: zod.objectInputType<{}, zod.ZodTypeAny, "passthrough"> | undefined;
776
+ settings?: zod.objectInputType<{}, zod.ZodTypeAny, "passthrough"> | null | undefined;
777
777
  } | null | undefined;
778
778
  validation?: {
779
779
  name: string;
@@ -803,7 +803,7 @@ export declare const createModelUpdateValidation: () => zod.ZodObject<{
803
803
  placeholderText: string | null;
804
804
  renderer: {
805
805
  name: string;
806
- settings?: zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough"> | undefined;
806
+ settings?: zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough"> | null | undefined;
807
807
  } | null;
808
808
  validation: {
809
809
  name: string;
@@ -865,7 +865,7 @@ export declare const createModelUpdateValidation: () => zod.ZodObject<{
865
865
  } | undefined;
866
866
  renderer?: {
867
867
  name: string;
868
- settings?: zod.objectInputType<{}, zod.ZodTypeAny, "passthrough"> | undefined;
868
+ settings?: zod.objectInputType<{}, zod.ZodTypeAny, "passthrough"> | null | undefined;
869
869
  } | null | undefined;
870
870
  validation?: {
871
871
  name: string;
@@ -52,7 +52,7 @@ const fieldSchema = _zod.default.object({
52
52
  }).optional(),
53
53
  renderer: _zod.default.object({
54
54
  name: shortString,
55
- settings: _zod.default.object({}).passthrough().optional()
55
+ settings: _zod.default.object({}).passthrough().nullish().optional()
56
56
  }).optional().nullable().default(null),
57
57
  validation: _zod.default.array(_zod.default.object({
58
58
  name: shortString,
@@ -1 +1 @@
1
- {"version":3,"names":["_zod","_interopRequireDefault","require","_upperFirst","_camelCase","fieldSystemFields","str","zod","string","trim","shortString","max","optionalShortString","optional","optionalNullishShortString","nullish","fieldSchema","object","id","storageId","transform","fieldId","regex","message","superRefine","value","ctx","includes","addIssue","code","ZodIssueCode","custom","path","label","helpText","default","placeholderText","nullable","type","tags","array","multipleValues","boolean","predefinedValues","enabled","values","selected","renderer","name","settings","passthrough","validation","listValidation","apiNameRefinementValidation","match","upperFirst","camelCase","refinementSingularValidationMessage","refinementPluralValidationMessage","refinementModelIdValidation","camelCasedValue","toLowerCase","refinementModelIdValidationMessage","modelIdTransformation","createModelCreateValidation","modelId","singularApiName","min","refine","pluralApiName","description","group","icon","fields","layout","titleFieldId","descriptionFieldId","imageFieldId","defaultFields","exports","createModelImportValidation","createModelCreateFromValidation","locale","createModelUpdateValidation"],"sources":["validation.ts"],"sourcesContent":["import zod from \"zod\";\nimport upperFirst from \"lodash/upperFirst\";\nimport camelCase from \"lodash/camelCase\";\n\nconst fieldSystemFields: string[] = [\n \"id\",\n \"fieldId\",\n \"storageId\",\n \"label\",\n \"helpText\",\n \"placeholderText\",\n \"type\",\n \"multipleValues\",\n \"predefinedValues\",\n \"renderer\",\n \"validation\",\n \"listValidation\",\n \"settings\"\n];\n\nconst str = zod.string().trim();\nconst shortString = str.max(255);\nconst optionalShortString = shortString.optional();\nconst optionalNullishShortString = optionalShortString.nullish();\n\nconst fieldSchema = zod.object({\n id: shortString,\n storageId: zod\n .string()\n .optional()\n .transform(() => {\n return \"\";\n }),\n fieldId: shortString\n .max(100)\n .regex(/^!?[a-zA-Z]/, {\n message: `Provided value is not valid - must not start with a number.`\n })\n .regex(/^(^[a-zA-Z0-9]+)$/, {\n message: `Provided value is not valid - must be alphanumeric string.`\n })\n .superRefine((value, ctx) => {\n if (fieldSystemFields.includes(value)) {\n return ctx.addIssue({\n code: zod.ZodIssueCode.custom,\n message: `Provided ${value} is not valid - \"${value}\" is an auto-generated field.`,\n path: [\"fieldId\"]\n });\n }\n }),\n label: shortString,\n helpText: optionalShortString.optional().nullish().default(null),\n placeholderText: optionalShortString.optional().nullable().default(null),\n type: shortString,\n tags: zod.array(shortString).optional().default([]),\n multipleValues: zod\n .boolean()\n .optional()\n .nullish()\n .transform(value => {\n return !!value;\n })\n .default(false),\n predefinedValues: zod\n .object({\n enabled: zod.boolean(),\n values: zod\n .array(\n zod.object({\n value: shortString,\n label: shortString,\n selected: zod.boolean().optional().default(false)\n })\n )\n .default([])\n })\n .default({\n enabled: false,\n values: []\n })\n .optional(),\n renderer: zod\n .object({\n name: shortString,\n settings: zod.object({}).passthrough().optional()\n })\n .optional()\n .nullable()\n .default(null),\n validation: zod\n .array(\n zod.object({\n name: shortString,\n message: optionalShortString.default(\"Value is required.\"),\n settings: zod\n .object({})\n .passthrough()\n .optional()\n .nullish()\n .transform(value => {\n return value || {};\n })\n .default({})\n })\n )\n .nullish()\n .optional()\n .default([])\n .transform(value => value || []),\n listValidation: zod\n .array(\n zod.object({\n name: shortString,\n message: optionalShortString.default(\"Value is required.\"),\n settings: zod\n .object({})\n .passthrough()\n .optional()\n .nullish()\n .transform(value => {\n return value || {};\n })\n .default({})\n })\n )\n .nullish()\n .optional()\n .default([])\n .transform(value => value || []),\n settings: zod\n .object({})\n .passthrough()\n .optional()\n .nullish()\n .transform(value => {\n return value || {};\n })\n .default({})\n});\n\nconst apiNameRefinementValidation = (value: string): boolean => {\n if (value.match(/^[A-Z]/) === null) {\n return false;\n }\n return value === upperFirst(camelCase(value));\n};\nconst refinementSingularValidationMessage = (value?: string) => {\n return {\n message: `The Singular API Name value \"${\n value || \"undefined\"\n }\" is not valid. It must in Upper First + Camel Cased form. For example: \"ArticleCategory\" or \"CarMake\".`\n };\n};\nconst refinementPluralValidationMessage = (value?: string) => {\n return {\n message: `The Plural API Name value \"${\n value || \"undefined\"\n }\" is not valid. It must in Upper First + Camel Cased form. For example: \"ArticleCategories\" or \"CarMakes\".`\n };\n};\n\nconst refinementModelIdValidation = (value?: string) => {\n if (!value) {\n return true;\n } else if (value.match(/^[a-zA-Z]/) === null) {\n return false;\n }\n const camelCasedValue = camelCase(value).toLowerCase();\n return camelCasedValue === value.toLowerCase();\n};\nconst refinementModelIdValidationMessage = (value?: string) => {\n if (!value) {\n return {};\n } else if (value.match(/^[a-zA-Z]/) === null) {\n return {\n message: `The modelId \"${value}\" is not valid. It must start with a A-Z or a-z.`\n };\n }\n return {\n message: `The modelId \"${value}\" is not valid.`\n };\n};\n\nconst modelIdTransformation = (value?: string) => {\n if (!value) {\n return value;\n }\n const camelCasedValue = camelCase(value);\n if (camelCasedValue.toLowerCase() === value.toLowerCase()) {\n return value;\n }\n return camelCasedValue;\n};\n\nexport const createModelCreateValidation = () => {\n return zod.object({\n name: shortString,\n modelId: optionalShortString.transform(modelIdTransformation),\n singularApiName: shortString\n .min(1)\n .refine(apiNameRefinementValidation, refinementSingularValidationMessage),\n pluralApiName: shortString\n .min(1)\n .refine(apiNameRefinementValidation, refinementPluralValidationMessage),\n description: optionalNullishShortString,\n group: shortString,\n icon: optionalNullishShortString,\n fields: zod.array(fieldSchema).default([]),\n layout: zod.array(zod.array(shortString)).default([]),\n tags: zod.array(shortString).optional(),\n titleFieldId: optionalShortString.nullish(),\n descriptionFieldId: optionalShortString.nullish(),\n imageFieldId: optionalShortString.nullish(),\n defaultFields: zod.boolean().nullish()\n });\n};\n\nexport const createModelImportValidation = () => {\n return zod.object({\n name: shortString.min(1).refine(\n value => {\n return value.match(/[a-zA-Z]/) !== null;\n },\n value => {\n return {\n message: `The name \"${value}\" is not valid.`\n };\n }\n ),\n modelId: shortString\n .min(1)\n .refine(refinementModelIdValidation, refinementModelIdValidationMessage)\n .transform(modelIdTransformation),\n singularApiName: shortString\n .min(1)\n .refine(apiNameRefinementValidation, refinementSingularValidationMessage),\n pluralApiName: shortString\n .min(1)\n .refine(apiNameRefinementValidation, refinementPluralValidationMessage),\n description: optionalNullishShortString,\n group: shortString,\n icon: optionalNullishShortString,\n fields: zod.array(fieldSchema).min(1),\n layout: zod.array(zod.array(shortString)).min(1),\n tags: zod.array(shortString).optional(),\n titleFieldId: shortString.nullish(),\n descriptionFieldId: optionalShortString.nullish(),\n imageFieldId: optionalShortString.nullish()\n });\n};\n\nexport const createModelCreateFromValidation = () => {\n return zod.object({\n name: shortString,\n modelId: optionalShortString.transform(modelIdTransformation),\n singularApiName: shortString.refine(\n apiNameRefinementValidation,\n refinementSingularValidationMessage\n ),\n pluralApiName: shortString.refine(\n apiNameRefinementValidation,\n refinementPluralValidationMessage\n ),\n description: optionalNullishShortString,\n group: shortString,\n icon: optionalNullishShortString,\n locale: optionalShortString\n });\n};\n\nexport const createModelUpdateValidation = () => {\n return zod.object({\n name: optionalShortString,\n singularApiName: optionalShortString.refine(value => {\n if (!value) {\n return true;\n }\n return apiNameRefinementValidation(value);\n }, refinementSingularValidationMessage),\n pluralApiName: optionalShortString.refine(value => {\n if (!value) {\n return true;\n }\n return apiNameRefinementValidation(value);\n }, refinementPluralValidationMessage),\n description: optionalNullishShortString,\n group: optionalShortString,\n icon: optionalNullishShortString,\n fields: zod.array(fieldSchema),\n layout: zod.array(zod.array(shortString)),\n titleFieldId: optionalShortString.nullish(),\n descriptionFieldId: optionalShortString.nullish(),\n imageFieldId: optionalShortString.nullish(),\n tags: zod.array(shortString).optional()\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,UAAA,GAAAH,sBAAA,CAAAC,OAAA;AAEA,MAAMG,iBAA2B,GAAG,CAChC,IAAI,EACJ,SAAS,EAC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AAC;IAC7C,CAAC,EAAEgC,mCAAmC,CAAC;IACvCY,aAAa,EAAEzD,mBAAmB,CAACwD,MAAM,CAAC3C,KAAK,IAAI;MAC/C,IAAI,CAACA,KAAK,EAAE;QACR,OAAO,IAAI;MACf;MACA,OAAO4B,2BAA2B,CAAC5B,KAAK,CAAC;IAC7C,CAAC,EAAEiC,iCAAiC,CAAC;IACrCY,WAAW,EAAExD,0BAA0B;IACvCyD,KAAK,EAAE3D,mBAAmB;IAC1B4D,IAAI,EAAE1D,0BAA0B;IAChC2D,MAAM,EAAElE,YAAG,CAACiC,KAAK,CAACxB,WAAW,CAAC;IAC9B0D,MAAM,EAAEnE,YAAG,CAACiC,KAAK,CAACjC,YAAG,CAACiC,KAAK,CAAC9B,WAAW,CAAC,CAAC;IACzCiE,YAAY,EAAE/D,mBAAmB,CAACG,OAAO,CAAC,CAAC;IAC3C6D,kBAAkB,EAAEhE,mBAAmB,CAACG,OAAO,CAAC,CAAC;IACjD8D,YAAY,EAAEjE,mBAAmB,CAACG,OAAO,CAAC,CAAC;IAC3CwB,IAAI,EAAEhC,YAAG,CAACiC,KAAK,CAAC9B,WAAW,CAAC,CAACG,QAAQ,CAAC;EAC1C,CAAC,CAAC;AACN,CAAC;AAACkE,OAAA,CAAAI,2BAAA,GAAAA,2BAAA","ignoreList":[]}
1
+ {"version":3,"names":["_zod","_interopRequireDefault","require","_upperFirst","_camelCase","fieldSystemFields","str","zod","string","trim","shortString","max","optionalShortString","optional","optionalNullishShortString","nullish","fieldSchema","object","id","storageId","transform","fieldId","regex","message","superRefine","value","ctx","includes","addIssue","code","ZodIssueCode","custom","path","label","helpText","default","placeholderText","nullable","type","tags","array","multipleValues","boolean","predefinedValues","enabled","values","selected","renderer","name","settings","passthrough","validation","listValidation","apiNameRefinementValidation","match","upperFirst","camelCase","refinementSingularValidationMessage","refinementPluralValidationMessage","refinementModelIdValidation","camelCasedValue","toLowerCase","refinementModelIdValidationMessage","modelIdTransformation","createModelCreateValidation","modelId","singularApiName","min","refine","pluralApiName","description","group","icon","fields","layout","titleFieldId","descriptionFieldId","imageFieldId","defaultFields","exports","createModelImportValidation","createModelCreateFromValidation","locale","createModelUpdateValidation"],"sources":["validation.ts"],"sourcesContent":["import zod from \"zod\";\nimport upperFirst from \"lodash/upperFirst\";\nimport camelCase from \"lodash/camelCase\";\n\nconst fieldSystemFields: string[] = [\n \"id\",\n \"fieldId\",\n \"storageId\",\n \"label\",\n \"helpText\",\n \"placeholderText\",\n \"type\",\n \"multipleValues\",\n \"predefinedValues\",\n \"renderer\",\n \"validation\",\n \"listValidation\",\n \"settings\"\n];\n\nconst str = zod.string().trim();\nconst shortString = str.max(255);\nconst optionalShortString = shortString.optional();\nconst optionalNullishShortString = optionalShortString.nullish();\n\nconst fieldSchema = zod.object({\n id: shortString,\n storageId: zod\n .string()\n .optional()\n .transform(() => {\n return \"\";\n }),\n fieldId: shortString\n .max(100)\n .regex(/^!?[a-zA-Z]/, {\n message: `Provided value is not valid - must not start with a number.`\n })\n .regex(/^(^[a-zA-Z0-9]+)$/, {\n message: `Provided value is not valid - must be alphanumeric string.`\n })\n .superRefine((value, ctx) => {\n if (fieldSystemFields.includes(value)) {\n return ctx.addIssue({\n code: zod.ZodIssueCode.custom,\n message: `Provided ${value} is not valid - \"${value}\" is an auto-generated field.`,\n path: [\"fieldId\"]\n });\n }\n }),\n label: shortString,\n helpText: optionalShortString.optional().nullish().default(null),\n placeholderText: optionalShortString.optional().nullable().default(null),\n type: shortString,\n tags: zod.array(shortString).optional().default([]),\n multipleValues: zod\n .boolean()\n .optional()\n .nullish()\n .transform(value => {\n return !!value;\n })\n .default(false),\n predefinedValues: zod\n .object({\n enabled: zod.boolean(),\n values: zod\n .array(\n zod.object({\n value: shortString,\n label: shortString,\n selected: zod.boolean().optional().default(false)\n })\n )\n .default([])\n })\n .default({\n enabled: false,\n values: []\n })\n .optional(),\n renderer: zod\n .object({\n name: shortString,\n settings: zod.object({}).passthrough().nullish().optional()\n })\n .optional()\n .nullable()\n .default(null),\n validation: zod\n .array(\n zod.object({\n name: shortString,\n message: optionalShortString.default(\"Value is required.\"),\n settings: zod\n .object({})\n .passthrough()\n .optional()\n .nullish()\n .transform(value => {\n return value || {};\n })\n .default({})\n })\n )\n .nullish()\n .optional()\n .default([])\n .transform(value => value || []),\n listValidation: zod\n .array(\n zod.object({\n name: shortString,\n message: optionalShortString.default(\"Value is required.\"),\n settings: zod\n .object({})\n .passthrough()\n .optional()\n .nullish()\n .transform(value => {\n return value || {};\n })\n .default({})\n })\n )\n .nullish()\n .optional()\n .default([])\n .transform(value => value || []),\n settings: zod\n .object({})\n .passthrough()\n .optional()\n .nullish()\n .transform(value => {\n return value || {};\n })\n .default({})\n});\n\nconst apiNameRefinementValidation = (value: string): boolean => {\n if (value.match(/^[A-Z]/) === null) {\n return false;\n }\n return value === upperFirst(camelCase(value));\n};\nconst refinementSingularValidationMessage = (value?: string) => {\n return {\n message: `The Singular API Name value \"${\n value || \"undefined\"\n }\" is not valid. It must in Upper First + Camel Cased form. For example: \"ArticleCategory\" or \"CarMake\".`\n };\n};\nconst refinementPluralValidationMessage = (value?: string) => {\n return {\n message: `The Plural API Name value \"${\n value || \"undefined\"\n }\" is not valid. It must in Upper First + Camel Cased form. For example: \"ArticleCategories\" or \"CarMakes\".`\n };\n};\n\nconst refinementModelIdValidation = (value?: string) => {\n if (!value) {\n return true;\n } else if (value.match(/^[a-zA-Z]/) === null) {\n return false;\n }\n const camelCasedValue = camelCase(value).toLowerCase();\n return camelCasedValue === value.toLowerCase();\n};\nconst refinementModelIdValidationMessage = (value?: string) => {\n if (!value) {\n return {};\n } else if (value.match(/^[a-zA-Z]/) === null) {\n return {\n message: `The modelId \"${value}\" is not valid. It must start with a A-Z or a-z.`\n };\n }\n return {\n message: `The modelId \"${value}\" is not valid.`\n };\n};\n\nconst modelIdTransformation = (value?: string) => {\n if (!value) {\n return value;\n }\n const camelCasedValue = camelCase(value);\n if (camelCasedValue.toLowerCase() === value.toLowerCase()) {\n return value;\n }\n return camelCasedValue;\n};\n\nexport const createModelCreateValidation = () => {\n return zod.object({\n name: shortString,\n modelId: optionalShortString.transform(modelIdTransformation),\n singularApiName: shortString\n .min(1)\n .refine(apiNameRefinementValidation, refinementSingularValidationMessage),\n pluralApiName: shortString\n .min(1)\n .refine(apiNameRefinementValidation, refinementPluralValidationMessage),\n description: optionalNullishShortString,\n group: shortString,\n icon: optionalNullishShortString,\n fields: zod.array(fieldSchema).default([]),\n layout: zod.array(zod.array(shortString)).default([]),\n tags: zod.array(shortString).optional(),\n titleFieldId: optionalShortString.nullish(),\n descriptionFieldId: optionalShortString.nullish(),\n imageFieldId: optionalShortString.nullish(),\n defaultFields: zod.boolean().nullish()\n });\n};\n\nexport const createModelImportValidation = () => {\n return zod.object({\n name: shortString.min(1).refine(\n value => {\n return value.match(/[a-zA-Z]/) !== null;\n },\n value => {\n return {\n message: `The name \"${value}\" is not valid.`\n };\n }\n ),\n modelId: shortString\n .min(1)\n .refine(refinementModelIdValidation, refinementModelIdValidationMessage)\n .transform(modelIdTransformation),\n singularApiName: shortString\n .min(1)\n .refine(apiNameRefinementValidation, refinementSingularValidationMessage),\n pluralApiName: shortString\n .min(1)\n .refine(apiNameRefinementValidation, refinementPluralValidationMessage),\n description: optionalNullishShortString,\n group: shortString,\n icon: optionalNullishShortString,\n fields: zod.array(fieldSchema).min(1),\n layout: zod.array(zod.array(shortString)).min(1),\n tags: zod.array(shortString).optional(),\n titleFieldId: shortString.nullish(),\n descriptionFieldId: optionalShortString.nullish(),\n imageFieldId: optionalShortString.nullish()\n });\n};\n\nexport const createModelCreateFromValidation = () => {\n return zod.object({\n name: shortString,\n modelId: optionalShortString.transform(modelIdTransformation),\n singularApiName: shortString.refine(\n apiNameRefinementValidation,\n refinementSingularValidationMessage\n ),\n pluralApiName: shortString.refine(\n apiNameRefinementValidation,\n refinementPluralValidationMessage\n ),\n description: optionalNullishShortString,\n group: shortString,\n icon: optionalNullishShortString,\n locale: optionalShortString\n });\n};\n\nexport const createModelUpdateValidation = () => {\n return zod.object({\n name: optionalShortString,\n singularApiName: optionalShortString.refine(value => {\n if (!value) {\n return true;\n }\n return apiNameRefinementValidation(value);\n }, refinementSingularValidationMessage),\n pluralApiName: optionalShortString.refine(value => {\n if (!value) {\n return true;\n }\n return apiNameRefinementValidation(value);\n }, refinementPluralValidationMessage),\n description: optionalNullishShortString,\n group: optionalShortString,\n icon: optionalNullishShortString,\n fields: zod.array(fieldSchema),\n layout: zod.array(zod.array(shortString)),\n titleFieldId: optionalShortString.nullish(),\n descriptionFieldId: optionalShortString.nullish(),\n imageFieldId: optionalShortString.nullish(),\n tags: zod.array(shortString).optional()\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,UAAA,GAAAH,sBAAA,CAAAC,OAAA;AAEA,MAAMG,iBAA2B,GAAG,CAChC,IAAI,EACJ,SAAS,EACT,WAAW,EACX,OAAO,EACP,UAAU,EACV,iBAAiB,EACjB,MAAM,EACN,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,YAAY,EACZ,gBAAgB,EAChB,UAAU,CACb;AAED,MAAMC,GAAG,GAAGC,YAAG,CAACC,MAAM,CAAC,CAAC,CAACC,IAAI,CAAC,CAAC;AAC/B,MAAMC,WAAW,GAAGJ,GAAG,CAACK,GAAG,CAAC,GAAG,CAAC;AAChC,MAAMC,mBAAmB,GAAGF,WAAW,CAACG,QAAQ,CAAC,CAAC;AAClD,MAAMC,0BAA0B,GAAGF,mBAAmB,CAACG,OAAO,CAAC,CAAC;AAEhE,MAAMC,WAAW,GAAGT,YAAG,CAACU,MAAM,CAAC;EAC3BC,EAAE,EAAER,WAAW;EACfS,SAAS,EAAEZ,YAAG,CACTC,MAAM,CAAC,CAAC,CACRK,QAAQ,CAAC,CAAC,CACVO,SAAS,CAAC,MAAM;IACb,OAAO,EAAE;E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,CAACG,OAAO,CAAC,CAAC;IACjD8D,YAAY,EAAEjE,mBAAmB,CAACG,OAAO,CAAC,CAAC;IAC3CwB,IAAI,EAAEhC,YAAG,CAACiC,KAAK,CAAC9B,WAAW,CAAC,CAACG,QAAQ,CAAC;EAC1C,CAAC,CAAC;AACN,CAAC;AAACkE,OAAA,CAAAI,2BAAA,GAAAA,2BAAA","ignoreList":[]}
@@ -26,22 +26,25 @@ class CmsModelDynamicZoneFieldConverterPlugin extends _CmsModelFieldConverterPlu
26
26
  return {};
27
27
  }
28
28
  if (field.multipleValues) {
29
- const arrayValue = Array.isArray(value) ? value : [];
30
- return {
31
- [field.storageId]: arrayValue.map(item => {
32
- return this.processToStorage({
33
- templates,
34
- converterCollection,
35
- value: item
36
- });
37
- })
38
- };
29
+ if (Array.isArray(value)) {
30
+ return {
31
+ [field.storageId]: value.map(item => {
32
+ return this.processToStorage({
33
+ templates,
34
+ converterCollection,
35
+ value: item
36
+ });
37
+ })
38
+ };
39
+ }
40
+
41
+ // If a multi-value dynamic zone receives anything other than an array, ignore the value.
42
+ return {};
39
43
  }
44
+
45
+ // If a single-value dynamic zone receives an array, ignore the value.
40
46
  if (Array.isArray(value)) {
41
- throw new _error.default(`Dynamic zone field "${field.fieldId}" is expecting a non-array value.`, "DYNAMIC_ZONE_EXPECTING_NON_ARRAY_VALUE", {
42
- field,
43
- value
44
- });
47
+ return {};
45
48
  }
46
49
  const processedValue = this.processToStorage({
47
50
  templates,
@@ -57,53 +60,18 @@ class CmsModelDynamicZoneFieldConverterPlugin extends _CmsModelFieldConverterPlu
57
60
  templates,
58
61
  converterCollection
59
62
  } = params;
60
- let {
63
+ const {
61
64
  value
62
65
  } = params;
63
66
  if (value === null || value === undefined) {
64
67
  return undefined;
65
68
  }
66
- /**
67
- * There are two ways converter needs to work:
68
- * 1. when there is a _templateId
69
- * 2. when there is a key which identifies which template is the data for
70
- */
71
-
72
- /**
73
- * When we have a template key, everything is simple.
74
- */
75
69
  const templateId = value._templateId;
76
- let graphQlName = undefined;
77
- let template = undefined;
78
- if (templateId) {
79
- template = templates.find(t => {
80
- return templateId === t.id;
81
- });
82
- }
83
- /**
84
- * When we do not have a templateId, then the template identifier is the key of the value object.
85
- * But at that point, values under that key become the value we are working with later on.
86
- */
87
- //
88
- else {
89
- const keys = Object.keys(value);
90
- if (keys.length === 0) {
91
- return undefined;
92
- } else if (keys.length > 1) {
93
- throw new _error.default("There cannot be more than one dynamic zone template in a single dynamic zone field.", "DYNAMIC_ZONE_TOO_MANY_TEMPLATES", {
94
- templates: keys
95
- });
96
- }
97
- graphQlName = keys[0];
98
- template = templates.find(t => t.gqlTypeName === graphQlName);
99
- }
70
+ const template = templates.find(t => {
71
+ return templateId === t.id;
72
+ });
100
73
  if (!template) {
101
- throw new _error.default("Unknown template - converting to storage.", "UNKNOWN_TEMPLATE", {
102
- templateId,
103
- graphQlName
104
- });
105
- } else if (graphQlName) {
106
- value = value[graphQlName];
74
+ return undefined;
107
75
  }
108
76
  return template.fields.reduce((values, field) => {
109
77
  const converter = converterCollection.getConverter(field.type);
@@ -1 +1 @@
1
- {"version":3,"names":["_error","_interopRequireDefault","require","_CmsModelFieldConverterPlugin","CmsModelDynamicZoneFieldConverterPlugin","CmsModelFieldConverterPlugin","name","getFieldType","getTemplates","field","settings","templates","convertToStorage","params","value","converterCollection","length","multipleValues","arrayValue","Array","isArray","storageId","map","item","processToStorage","WebinyError","fieldId","processedValue","undefined","templateId","_templateId","graphQlName","template","find","t","id","keys","Object","gqlTypeName","fields","reduce","values","converter","getConverter","type","converted","assign","convertFromStorage","processFromStorage","exports"],"sources":["CmsModelDynamicZoneFieldConverterPlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport {\n CmsModelFieldConverterPlugin,\n ConvertParams\n} from \"~/plugins/CmsModelFieldConverterPlugin\";\nimport { CmsDynamicZoneTemplate, CmsEntryValues, CmsModelDynamicZoneField } from \"~/types\";\nimport { ConverterCollection } from \"~/utils/converters/ConverterCollection\";\n\ninterface DynamicZoneValue {\n [key: string]: any;\n}\n\ninterface ProcessValue {\n templates: CmsDynamicZoneTemplate[];\n value: DynamicZoneValue | null;\n converterCollection: ConverterCollection;\n}\n\nexport class CmsModelDynamicZoneFieldConverterPlugin extends CmsModelFieldConverterPlugin {\n public override name = \"cms.field.converter.dynamicZone\";\n\n public override getFieldType(): string {\n return \"dynamicZone\";\n }\n\n private getTemplates(field: CmsModelDynamicZoneField): CmsDynamicZoneTemplate[] {\n return field.settings?.templates || [];\n }\n\n public override convertToStorage(\n params: ConvertParams<CmsModelDynamicZoneField>\n ): CmsEntryValues {\n const { field, value, converterCollection } = params;\n\n const templates = this.getTemplates(field);\n\n if (templates.length === 0) {\n return {};\n }\n\n if (field.multipleValues) {\n const arrayValue = Array.isArray(value) ? value : [];\n\n return {\n [field.storageId]: arrayValue.map(item => {\n return this.processToStorage({\n templates,\n converterCollection,\n value: item\n });\n })\n };\n }\n if (Array.isArray(value)) {\n throw new WebinyError(\n `Dynamic zone field \"${field.fieldId}\" is expecting a non-array value.`,\n \"DYNAMIC_ZONE_EXPECTING_NON_ARRAY_VALUE\",\n {\n field,\n value\n }\n );\n }\n\n const processedValue = this.processToStorage({\n templates,\n converterCollection,\n value\n });\n return {\n [field.storageId]: processedValue\n };\n }\n\n private processToStorage(params: ProcessValue) {\n const { templates, converterCollection } = params;\n let { value } = params;\n if (value === null || value === undefined) {\n return undefined;\n }\n /**\n * There are two ways converter needs to work:\n * 1. when there is a _templateId\n * 2. when there is a key which identifies which template is the data for\n */\n\n /**\n * When we have a template key, everything is simple.\n */\n const templateId = value._templateId;\n let graphQlName: string | undefined = undefined;\n let template: CmsDynamicZoneTemplate | undefined = undefined;\n if (templateId) {\n template = templates.find(t => {\n return templateId === t.id;\n });\n }\n /**\n * When we do not have a templateId, then the template identifier is the key of the value object.\n * But at that point, values under that key become the value we are working with later on.\n */\n //\n else {\n const keys = Object.keys(value);\n if (keys.length === 0) {\n return undefined;\n } else if (keys.length > 1) {\n throw new WebinyError(\n \"There cannot be more than one dynamic zone template in a single dynamic zone field.\",\n \"DYNAMIC_ZONE_TOO_MANY_TEMPLATES\",\n {\n templates: keys\n }\n );\n }\n graphQlName = keys[0] as string;\n template = templates.find(t => t.gqlTypeName === graphQlName);\n }\n\n if (!template) {\n throw new WebinyError(\"Unknown template - converting to storage.\", \"UNKNOWN_TEMPLATE\", {\n templateId,\n graphQlName\n });\n } else if (graphQlName) {\n value = value[graphQlName];\n }\n\n return template.fields.reduce<Record<string, any>>(\n (values, field) => {\n const converter = converterCollection.getConverter(field.type);\n const converted = converter.convertToStorage({\n field,\n value: value ? value[field.fieldId] : undefined\n });\n Object.assign(values, converted);\n return values;\n },\n {\n _templateId: template.id\n }\n );\n }\n\n public override convertFromStorage(\n params: ConvertParams<CmsModelDynamicZoneField>\n ): CmsEntryValues {\n const { field, value, converterCollection } = params;\n\n const templates = this.getTemplates(field);\n\n if (templates.length === 0) {\n return {};\n }\n\n if (field.multipleValues) {\n const arrayValue = Array.isArray(value) ? value : [];\n\n return {\n [field.fieldId]: arrayValue.map(item => {\n return this.processFromStorage({\n templates,\n converterCollection,\n value: item\n });\n })\n };\n }\n if (Array.isArray(value)) {\n throw new WebinyError(\n `Dynamic zone field \"${field.fieldId}\" is expecting a non-array value.`,\n \"DYNAMIC_ZONE_EXPECTING_NON_ARRAY_VALUE\",\n {\n field,\n value\n }\n );\n }\n\n const processedValue = this.processFromStorage({\n templates,\n converterCollection,\n value\n });\n return {\n [field.fieldId]: processedValue\n };\n }\n\n private processFromStorage(params: ProcessValue) {\n const { templates, value, converterCollection } = params;\n if (value === null || value === undefined) {\n return undefined;\n }\n\n const { _templateId } = value;\n\n const template = templates.find(t => t.id === _templateId);\n if (!template) {\n throw new WebinyError(\n \"Unknown template - converting from storage.\",\n \"UNKNOWN_TEMPLATE\",\n {\n templateId: _templateId\n }\n );\n }\n\n return template.fields.reduce<Record<string, any>>(\n (values, field) => {\n const converter = converterCollection.getConverter(field.type);\n const converted = converter.convertFromStorage({\n field,\n value: value[field.storageId]\n });\n Object.assign(values, converted);\n return values;\n },\n {\n _templateId: template.id\n }\n );\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,6BAAA,GAAAD,OAAA;AAiBO,MAAME,uCAAuC,SAASC,0DAA4B,CAAC;EACtEC,IAAI,GAAG,iCAAiC;EAExCC,YAAYA,CAAA,EAAW;IACnC,OAAO,aAAa;EACxB;EAEQC,YAAYA,CAACC,KAA+B,EAA4B;IAC5E,OAAOA,KAAK,CAACC,QAAQ,EAAEC,SAAS,IAAI,EAAE;EAC1C;EAEgBC,gBAAgBA,CAC5BC,MAA+C,EACjC;IACd,MAAM;MAAEJ,KAAK;MAAEK,KAAK;MAAEC;IAAoB,CAAC,GAAGF,MAAM;IAEpD,MAAMF,SAAS,GAAG,IAAI,CAACH,YAAY,CAACC,KAAK,CAAC;IAE1C,IAAIE,SAAS,CAACK,MAAM,KAAK,CAAC,EAAE;MACxB,OAAO,CAAC,CAAC;IACb;IAEA,IAAIP,KAAK,CAACQ,cAAc,EAAE;MACtB,MAAMC,UAAU,GAAGC,KAAK,CAACC,OAAO,CAACN,KAAK,CAAC,GAAGA,KAAK,GAAG,EAAE;MAEpD,OAAO;QACH,CAACL,KAAK,CAACY,SAAS,GAAGH,UAAU,CAACI,GAAG,CAACC,IAAI,IAAI;UACtC,OAAO,IAAI,CAACC,gBAAgB,CAAC;YACzBb,SAAS;YACTI,mBAAmB;YACnBD,KAAK,EAAES;UACX,CAAC,CAAC;QACN,CAAC;MACL,CAAC;IACL;IACA,IAAIJ,KAAK,CAACC,OAAO,CAACN,KAAK,CAAC,EAAE;MACtB,MAAM,IAAIW,cAAW,CAChB,uBAAsBhB,KAAK,CAACiB,OAAQ,mCAAkC,EACvE,wCAAwC,EACxC;QACIjB,KAAK;QACLK;MACJ,CACJ,CAAC;IACL;IAEA,MAAMa,cAAc,GAAG,IAAI,CAACH,g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C,EACD;MACIX,WAAW,EAAEE,QAAQ,CAACG;IAC1B,CACJ,CAAC;EACL;AACJ;AAACc,OAAA,CAAA7C,uCAAA,GAAAA,uCAAA","ignoreList":[]}
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_CmsModelFieldConverterPlugin","CmsModelDynamicZoneFieldConverterPlugin","CmsModelFieldConverterPlugin","name","getFieldType","getTemplates","field","settings","templates","convertToStorage","params","value","converterCollection","length","multipleValues","Array","isArray","storageId","map","item","processToStorage","processedValue","undefined","templateId","_templateId","template","find","t","id","fields","reduce","values","converter","getConverter","type","converted","fieldId","Object","assign","convertFromStorage","arrayValue","processFromStorage","WebinyError","exports"],"sources":["CmsModelDynamicZoneFieldConverterPlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport {\n CmsModelFieldConverterPlugin,\n ConvertParams\n} from \"~/plugins/CmsModelFieldConverterPlugin\";\nimport { CmsDynamicZoneTemplate, CmsEntryValues, CmsModelDynamicZoneField } from \"~/types\";\nimport { ConverterCollection } from \"~/utils/converters/ConverterCollection\";\n\ninterface DynamicZoneValue {\n [key: string]: any;\n}\n\ninterface ProcessValue {\n templates: CmsDynamicZoneTemplate[];\n value: DynamicZoneValue | null;\n converterCollection: ConverterCollection;\n}\n\nexport class CmsModelDynamicZoneFieldConverterPlugin extends CmsModelFieldConverterPlugin {\n public override name = \"cms.field.converter.dynamicZone\";\n\n public override getFieldType(): string {\n return \"dynamicZone\";\n }\n\n private getTemplates(field: CmsModelDynamicZoneField): CmsDynamicZoneTemplate[] {\n return field.settings?.templates || [];\n }\n\n public override convertToStorage(\n params: ConvertParams<CmsModelDynamicZoneField>\n ): CmsEntryValues {\n const { field, value, converterCollection } = params;\n\n const templates = this.getTemplates(field);\n\n if (templates.length === 0) {\n return {};\n }\n\n if (field.multipleValues) {\n if (Array.isArray(value)) {\n return {\n [field.storageId]: value.map(item => {\n return this.processToStorage({\n templates,\n converterCollection,\n value: item\n });\n })\n };\n }\n\n // If a multi-value dynamic zone receives anything other than an array, ignore the value.\n return {};\n }\n\n // If a single-value dynamic zone receives an array, ignore the value.\n if (Array.isArray(value)) {\n return {};\n }\n\n const processedValue = this.processToStorage({\n templates,\n converterCollection,\n value\n });\n\n return {\n [field.storageId]: processedValue\n };\n }\n\n private processToStorage(params: ProcessValue) {\n const { templates, converterCollection } = params;\n const { value } = params;\n if (value === null || value === undefined) {\n return undefined;\n }\n\n const templateId = value._templateId;\n const template = templates.find(t => {\n return templateId === t.id;\n });\n\n if (!template) {\n return undefined;\n }\n\n return template.fields.reduce<Record<string, any>>(\n (values, field) => {\n const converter = converterCollection.getConverter(field.type);\n const converted = converter.convertToStorage({\n field,\n value: value ? value[field.fieldId] : undefined\n });\n Object.assign(values, converted);\n return values;\n },\n {\n _templateId: template.id\n }\n );\n }\n\n public override convertFromStorage(\n params: ConvertParams<CmsModelDynamicZoneField>\n ): CmsEntryValues {\n const { field, value, converterCollection } = params;\n\n const templates = this.getTemplates(field);\n\n if (templates.length === 0) {\n return {};\n }\n\n if (field.multipleValues) {\n const arrayValue = Array.isArray(value) ? value : [];\n\n return {\n [field.fieldId]: arrayValue.map(item => {\n return this.processFromStorage({\n templates,\n converterCollection,\n value: item\n });\n })\n };\n }\n\n if (Array.isArray(value)) {\n throw new WebinyError(\n `Dynamic zone field \"${field.fieldId}\" is expecting a non-array value.`,\n \"DYNAMIC_ZONE_EXPECTING_NON_ARRAY_VALUE\",\n {\n field,\n value\n }\n );\n }\n\n const processedValue = this.processFromStorage({\n templates,\n converterCollection,\n value\n });\n\n return {\n [field.fieldId]: processedValue\n };\n }\n\n private processFromStorage(params: ProcessValue) {\n const { templates, value, converterCollection } = params;\n if (value === null || value === undefined) {\n return undefined;\n }\n\n const { _templateId } = value;\n\n const template = templates.find(t => t.id === _templateId);\n if (!template) {\n throw new WebinyError(\n \"Unknown template - converting from storage.\",\n \"UNKNOWN_TEMPLATE\",\n {\n templateId: _templateId\n }\n );\n }\n\n return template.fields.reduce<Record<string, any>>(\n (values, field) => {\n const converter = converterCollection.getConverter(field.type);\n const converted = converter.convertFromStorage({\n field,\n value: value[field.storageId]\n });\n Object.assign(values, converted);\n return values;\n },\n {\n _templateId: template.id\n }\n );\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,6BAAA,GAAAD,OAAA;AAiBO,MAAME,uCAAuC,SAASC,0DAA4B,CAAC;EACtEC,IAAI,GAAG,iCAAiC;EAExCC,YAAYA,CAAA,EAAW;IACnC,OAAO,aAAa;EACxB;EAEQC,YAAYA,CAACC,KAA+B,EAA4B;IAC5E,OAAOA,KAAK,CAACC,QAAQ,EAAEC,SAAS,IAAI,EAAE;EAC1C;EAEgBC,gBAAgBA,CAC5BC,MAA+C,EACjC;IACd,MAAM;MAAEJ,KAAK;MAAEK,KAAK;MAAEC;IAAoB,CAAC,GAAGF,MAAM;IAEpD,MAAMF,SAAS,GAAG,IAAI,CAACH,YAAY,CAACC,KAAK,CAAC;IAE1C,IAAIE,SAAS,CAACK,MAAM,KAAK,CAAC,EAAE;MACxB,OAAO,CAAC,CAAC;IACb;IAEA,IAAIP,KAAK,CAACQ,cAAc,EAAE;MACtB,IAAIC,KAAK,CAACC,OAAO,CAACL,KAAK,CAAC,EAAE;QACtB,OAAO;UACH,CAACL,KAAK,CAACW,SAAS,GAAGN,KAAK,CAACO,GAAG,CAACC,IAAI,IAAI;YACjC,OAAO,IAAI,CAACC,gBAAgB,CAAC;cACzBZ,SAAS;cACTI,mBAAmB;cACnBD,KAAK,EAAEQ;YACX,CAAC,CAAC;UACN,CAAC;QACL,CAAC;MACL;;MAEA;MACA,OAAO,CAAC,CAAC;IACb;;IAEA;IACA,IAAIJ,KAAK,CAACC,OAAO,CAACL,KAAK,CAAC,EAAE;MACtB,OAAO,CAAC,CAAC;IACb;IAEA,MAAMU,cAAc,GAAG,IAAI,CAACD,gBAAgB,CAAC;MACzCZ,SAAS;MACTI,mBAAmB;MACnBD;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