@webiny/api-headless-cms 6.4.11 → 6.4.12-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/crud/contentEntry/entryDataValidation.js +3 -4
- package/crud/contentEntry/entryDataValidation.js.map +1 -1
- package/crud/contentModel/validate/endingAllowed.js +1 -1
- package/crud/contentModel/validate/endingAllowed.js.map +1 -1
- package/crud/contentModel/validate/pluralApiName.js +1 -1
- package/crud/contentModel/validate/pluralApiName.js.map +1 -1
- package/crud/contentModel/validate/singularApiName.js +1 -1
- package/crud/contentModel/validate/singularApiName.js.map +1 -1
- package/crud/contentModel/validation.js +2 -2
- package/crud/contentModel/validation.js.map +1 -1
- package/domain/contentModel/validation/endingAllowed.js +1 -1
- package/domain/contentModel/validation/endingAllowed.js.map +1 -1
- package/domain/contentModel/validation/pluralApiName.js +1 -1
- package/domain/contentModel/validation/pluralApiName.js.map +1 -1
- package/domain/contentModel/validation/singularApiName.js +1 -1
- package/domain/contentModel/validation/singularApiName.js.map +1 -1
- package/export/crud/exporting.js +2 -2
- package/export/crud/exporting.js.map +1 -1
- package/export/crud/imports/importGroups.js +1 -2
- package/export/crud/imports/importGroups.js.map +1 -1
- package/export/crud/imports/validateModels.js +1 -1
- package/export/crud/imports/validateModels.js.map +1 -1
- package/features/contentEntry/entryDataFactories/expiresAt.js +2 -2
- package/features/contentEntry/entryDataFactories/expiresAt.js.map +1 -1
- package/features/contentModel/CreateModel/CreateModelRepository.js +1 -2
- package/features/contentModel/CreateModel/CreateModelRepository.js.map +1 -1
- package/features/contentModel/CreateModelFrom/CreateModelFromRepository.js +1 -2
- package/features/contentModel/CreateModelFrom/CreateModelFromRepository.js.map +1 -1
- package/features/storage/fields/CompressedTextStorageTransform.js +1 -1
- package/features/storage/fields/CompressedTextStorageTransform.js.map +1 -1
- package/features/storage/fields/DateStorageTransform.js +3 -4
- package/features/storage/fields/DateStorageTransform.js.map +1 -1
- package/features/storage/fields/DynamicZoneStorageTransform.js +2 -2
- package/features/storage/fields/DynamicZoneStorageTransform.js.map +1 -1
- package/features/storage/fields/JsonStorageTransform.js +1 -1
- package/features/storage/fields/JsonStorageTransform.js.map +1 -1
- package/features/storage/fields/LongTextStorageTransform.js +1 -1
- package/features/storage/fields/LongTextStorageTransform.js.map +1 -1
- package/features/storage/fields/RichTextStorageTransform.js +1 -1
- package/features/storage/fields/RichTextStorageTransform.js.map +1 -1
- package/features/validation/validators/DateGteValidator.js +1 -1
- package/features/validation/validators/DateGteValidator.js.map +1 -1
- package/features/validation/validators/DateLteValidator.js +1 -1
- package/features/validation/validators/DateLteValidator.js.map +1 -1
- package/features/whereMapper/WhereMapper.js +2 -3
- package/features/whereMapper/WhereMapper.js.map +1 -1
- package/graphql/getSchema/generateCacheKey.js +1 -1
- package/graphql/getSchema/generateCacheKey.js.map +1 -1
- package/graphql/scalars/RevisionId.js +1 -1
- package/graphql/scalars/RevisionId.js.map +1 -1
- package/graphql/schema/createFieldResolvers.js +1 -1
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/package.json +27 -27
- package/plugins/CmsModelPlugin.js +9 -10
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/utils/caching/Cache.js +1 -1
- package/utils/caching/Cache.js.map +1 -1
- package/utils/date.js +1 -1
- package/utils/date.js.map +1 -1
- package/utils/entryStorage.js +1 -1
- package/utils/entryStorage.js.map +1 -1
- package/utils/renderFields.js +1 -1
- package/utils/renderFields.js.map +1 -1
|
@@ -29,8 +29,8 @@ const validateValue = async (params, fieldValidators, value)=>{
|
|
|
29
29
|
const validatePredefinedValue = (field, value)=>{
|
|
30
30
|
const { enabled = false, values: predefinedValues = [] } = field.predefinedValues || {};
|
|
31
31
|
if (!enabled) return null;
|
|
32
|
-
if (false === Array.isArray(predefinedValues) || 0 === predefinedValues.length) return "Missing predefined values to validate against.";
|
|
33
|
-
if ("" === value || null == value) return null;
|
|
32
|
+
else if (false === Array.isArray(predefinedValues) || 0 === predefinedValues.length) return "Missing predefined values to validate against.";
|
|
33
|
+
else if ("" === value || null == value) return null;
|
|
34
34
|
for (const predefinedValue of predefinedValues)if (predefinedValue.value == value) return null;
|
|
35
35
|
return "Value sent does not match any of the available predefined values.";
|
|
36
36
|
};
|
|
@@ -146,8 +146,7 @@ const executeFieldValidation = async (params)=>{
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
return validations;
|
|
149
|
-
}
|
|
150
|
-
if ("dynamicZone" === field.type) {
|
|
149
|
+
} else if ("dynamicZone" === field.type) {
|
|
151
150
|
const validations = [];
|
|
152
151
|
const error = await execValidation({
|
|
153
152
|
...params,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crud/contentEntry/entryDataValidation.js","sources":["../../../src/crud/contentEntry/entryDataValidation.ts"],"sourcesContent":["import type {\n CmsContext,\n CmsDynamicZoneTemplate,\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CmsModelField,\n CmsModelFieldValidation\n} from \"~/types/index.js\";\nimport camelCase from \"lodash/camelCase.js\";\nimport { EntryValidationError } from \"~/domain/contentEntry/errors.js\";\nimport {\n type CmsModelFieldValidator,\n CmsModelFieldValidatorRegistry\n} from \"~/features/validation/index.js\";\n\ntype PluginValidationCallable = (\n params: CmsModelFieldValidator.Params\n) => CmsModelFieldValidator.Response;\ntype PluginValidationList = Record<string, PluginValidationCallable[]>;\n\ninterface ExecuteValidationParams<TValues extends CmsEntryValues = CmsEntryValues> {\n validatorList: PluginValidationList;\n field: CmsModelField;\n model: CmsModel;\n values: TValues;\n context: CmsContext;\n entry?: CmsEntry<TValues>;\n}\n\ntype PossibleValue = boolean | number | string | null | undefined;\n\nconst validateValue = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: ExecuteValidationParams<TValues>,\n fieldValidators: CmsModelFieldValidation[],\n value: PossibleValue | PossibleValue[]\n): Promise<string | null> => {\n if (!fieldValidators) {\n return null;\n }\n const { validatorList, context, field, model, entry } = params;\n try {\n for (const fieldValidator of fieldValidators) {\n const name = fieldValidator.name;\n const validations = validatorList[name];\n if (!validations || validations.length === 0) {\n return `There are no \"${name}\" validators defined.`;\n }\n for (const validate of validations) {\n const result = await validate({\n value,\n context,\n validator: fieldValidator,\n field,\n model,\n entry\n });\n if (!result) {\n return fieldValidator.message;\n }\n }\n }\n } catch (ex) {\n return ex.message;\n }\n\n return null;\n};\n\nconst validatePredefinedValue = (field: CmsModelField, value: any | any[]): string | null => {\n const { enabled = false, values: predefinedValues = [] } = field.predefinedValues || {};\n if (!enabled) {\n return null;\n } else if (Array.isArray(predefinedValues) === false || predefinedValues.length === 0) {\n return \"Missing predefined values to validate against.\";\n } else if (value === \"\" || value === null || value === undefined) {\n return null;\n }\n for (const predefinedValue of predefinedValues) {\n /**\n * No strict compare because the value sent can be 12345 (number) and predefinedValue can be \"12345\" (string),\n * and we want it to match.\n */\n if (predefinedValue.value == value) {\n return null;\n }\n }\n return \"Value sent does not match any of the available predefined values.\";\n};\n\nconst getFieldValidation = (\n listValidation?: CmsModelFieldValidation[]\n): CmsModelFieldValidation[] => {\n if (!listValidation?.length) {\n return [];\n }\n return listValidation.filter(item => item.name !== \"dynamicZone\");\n};\n/**\n * When multiple values is selected we must run validations on the array containing the values\n * And then on each value in the array\n */\nconst runFieldMultipleValuesValidations = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: ExecuteValidationParams<TValues>\n): Promise<string | null> => {\n const { field, values: initialValues } = params;\n const values = initialValues[field.fieldId as keyof TValues] as\n | PossibleValue[]\n | null\n | undefined;\n const valuesError = await validateValue(\n params,\n getFieldValidation(field.listValidation),\n values\n );\n if (valuesError) {\n return valuesError;\n }\n if (values === null || values === undefined) {\n return null;\n }\n for (const value of values) {\n const valueError = await validateValue(params, getFieldValidation(field.validation), value);\n if (valueError) {\n return valueError;\n }\n const predefinedValueError = validatePredefinedValue(field, value);\n if (predefinedValueError) {\n return predefinedValueError;\n }\n }\n return null;\n};\n/**\n * Runs validation on given value.\n */\nconst runFieldValueValidations = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: ExecuteValidationParams<TValues>\n): Promise<string | null> => {\n const { values, field } = params;\n const value = values[field.fieldId as keyof TValues];\n const error = await validateValue(params, field.validation || [], value);\n if (error) {\n return error;\n }\n return validatePredefinedValue(field, value);\n};\n\nconst execValidation = async (params: ExecuteValidationParams): Promise<string | null> => {\n const { field } = params;\n if (field.list) {\n return await runFieldMultipleValuesValidations(params);\n }\n return await runFieldValueValidations(params);\n};\n\ninterface IValidateModelEntryDataParams<TValues extends CmsEntryValues = CmsEntryValues> {\n context: CmsContext;\n model: CmsModel;\n values: TValues;\n entry?: CmsEntry<TValues>;\n skipValidators?: string[];\n}\n\nexport const validateModelEntryData = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: IValidateModelEntryDataParams<TValues>\n) => {\n const { context, model, entry, values, skipValidators } = params;\n\n const isValidatorSkipped = (validator: CmsModelFieldValidator.Interface) => {\n if (!skipValidators) {\n return false;\n }\n return skipValidators.includes(camelCase(validator.name));\n };\n\n const skippedValidators = new Set<string>();\n\n const validatorList: PluginValidationList = {};\n const registry = context.container.resolve(CmsModelFieldValidatorRegistry);\n const validators = registry.getAll();\n for (const validator of validators) {\n const name = validator.name;\n if (!validatorList[name]) {\n validatorList[name] = [];\n }\n const isSkipped = isValidatorSkipped(validator);\n if (isSkipped) {\n skippedValidators.add(name);\n validatorList[name].push(async () => {\n return true;\n });\n continue;\n }\n validatorList[name].push(params => {\n return validator.validate(params);\n });\n }\n /**\n * No point in continuing if all validators are skipped.\n */\n const keys = Object.keys(validatorList);\n if (keys.length === skippedValidators.size) {\n return [];\n }\n\n return await validate<TValues>({\n validatorList,\n context,\n model,\n entry,\n parents: [],\n fields: model.fields,\n values: {\n ...entry?.values,\n ...values\n }\n });\n};\n\nexport const validateModelEntryDataOrThrow = async <\n TValues extends CmsEntryValues = CmsEntryValues\n>(\n params: IValidateModelEntryDataParams<TValues>\n) => {\n const invalidFields = await validateModelEntryData(params);\n if (invalidFields.length === 0) {\n return;\n }\n throw new EntryValidationError(\"Validation failed.\", invalidFields);\n};\n\n/**\n *\n */\ninterface FieldError {\n id: string;\n fieldId: string;\n storageId: string;\n error: any;\n parents: string[];\n}\n\ninterface ValidateFieldParams<TValues extends CmsEntryValues = CmsEntryValues> {\n validatorList: PluginValidationList;\n parents: string[];\n model: CmsModel;\n values: TValues;\n context: CmsContext;\n field: CmsModelField;\n entry?: CmsEntry<TValues>;\n}\n\nconst executeFieldValidation = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: ValidateFieldParams<TValues>\n): Promise<FieldError[]> => {\n // TODO put per-field validation into plugins.\n const { field } = params;\n /**\n * Object field.\n */\n if (field.type === \"object\") {\n const fields = field.settings?.fields;\n if (!Array.isArray(fields)) {\n return [];\n }\n const validations: FieldError[] = [];\n /**\n * We need to validate the object field as well.\n */\n const error = await execValidation({\n ...params,\n field\n });\n if (error) {\n validations.push({\n id: field.id,\n fieldId: field.fieldId,\n storageId: field.storageId,\n error,\n parents: params.parents\n });\n }\n const objectValue = params.values[field.fieldId as keyof TValues];\n if (!objectValue) {\n return validations;\n }\n const values = (Array.isArray(objectValue) ? objectValue : [objectValue]) as TValues[];\n for (const index in values) {\n const parents = field.list ? [field.fieldId, index] : [field.fieldId];\n const value = values[index] as TValues;\n for (const childField of fields) {\n const errors = await executeFieldValidation<typeof value>({\n ...params,\n parents: params.parents.concat(parents),\n field: childField,\n values: value\n });\n if (errors.length === 0) {\n continue;\n }\n validations.push(...errors);\n }\n }\n return validations;\n }\n /**\n * Dynamic Zone Field\n */\n //\n else if (field.type === \"dynamicZone\") {\n const validations: FieldError[] = [];\n\n const error = await execValidation({\n ...params,\n field\n });\n if (error) {\n validations.push({\n id: field.id,\n fieldId: field.fieldId,\n storageId: field.storageId,\n error,\n parents: params.parents\n });\n }\n\n const templates = (field.settings?.templates || []) as CmsDynamicZoneTemplate[];\n for (const template of templates) {\n const fields = template.fields;\n const fieldData = params.values[field.fieldId as keyof TValues];\n if (!fieldData) {\n continue;\n }\n const values: TValues[keyof TValues][] = Array.isArray(fieldData)\n ? fieldData\n : [fieldData];\n for (const index in values) {\n const templateValue = values[index]?.[template.gqlTypeName];\n if (!templateValue) {\n continue;\n }\n /**\n * Order of the parents must be\n * - fieldId\n * - index (if multiple values)\n * - gqlTypeName\n */\n const parents = [field.fieldId];\n if (field.list) {\n parents.push(index);\n }\n parents.push(template.gqlTypeName);\n for (const childField of fields) {\n const errors = await executeFieldValidation({\n ...params,\n parents: params.parents.concat(parents),\n field: childField,\n values: templateValue\n });\n if (errors.length === 0) {\n continue;\n }\n validations.push(...errors);\n }\n }\n }\n\n return validations;\n }\n const error = await execValidation({\n ...params\n });\n if (!error) {\n return [];\n }\n return [\n {\n id: field.id,\n fieldId: field.fieldId,\n storageId: field.storageId,\n error,\n parents: params.parents\n }\n ];\n};\n\ninterface ValidateFieldsParams<TValues extends CmsEntryValues = CmsEntryValues> {\n validatorList: PluginValidationList;\n parents: string[];\n model: CmsModel;\n values: TValues;\n fields: CmsModelField[];\n context: CmsContext;\n entry?: CmsEntry<TValues>;\n}\n\nconst validate = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: ValidateFieldsParams<TValues>\n): Promise<FieldError[]> => {\n const { fields } = params;\n const errors: FieldError[] = [];\n\n const results = await Promise.all(\n fields.map(async field => {\n return await executeFieldValidation<TValues>({\n ...params,\n field\n });\n })\n );\n\n for (const result of results) {\n if (result.length === 0) {\n continue;\n }\n errors.push(...result);\n }\n return errors;\n};\n"],"names":["validateValue","params","fieldValidators","value","validatorList","context","field","model","entry","fieldValidator","name","validations","validate","result","ex","validatePredefinedValue","enabled","predefinedValues","Array","predefinedValue","getFieldValidation","listValidation","item","runFieldMultipleValuesValidations","initialValues","values","valuesError","valueError","predefinedValueError","runFieldValueValidations","error","execValidation","validateModelEntryData","skipValidators","isValidatorSkipped","validator","camelCase","skippedValidators","Set","registry","CmsModelFieldValidatorRegistry","validators","isSkipped","keys","Object","validateModelEntryDataOrThrow","invalidFields","EntryValidationError","executeFieldValidation","fields","objectValue","index","parents","childField","errors","templates","template","fieldData","templateValue","results","Promise"],"mappings":";;;AAgCA,MAAMA,gBAAgB,OAClBC,QACAC,iBACAC;IAEA,IAAI,CAACD,iBACD,OAAO;IAEX,MAAM,EAAEE,aAAa,EAAEC,OAAO,EAAEC,KAAK,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAGP;IACxD,IAAI;QACA,KAAK,MAAMQ,kBAAkBP,gBAAiB;YAC1C,MAAMQ,OAAOD,eAAe,IAAI;YAChC,MAAME,cAAcP,aAAa,CAACM,KAAK;YACvC,IAAI,CAACC,eAAeA,AAAuB,MAAvBA,YAAY,MAAM,EAClC,OAAO,CAAC,cAAc,EAAED,KAAK,qBAAqB,CAAC;YAEvD,KAAK,MAAME,YAAYD,YAAa;gBAChC,MAAME,SAAS,MAAMD,SAAS;oBAC1BT;oBACAE;oBACA,WAAWI;oBACXH;oBACAC;oBACAC;gBACJ;gBACA,IAAI,CAACK,QACD,OAAOJ,eAAe,OAAO;YAErC;QACJ;IACJ,EAAE,OAAOK,IAAI;QACT,OAAOA,GAAG,OAAO;IACrB;IAEA,OAAO;AACX;AAEA,MAAMC,0BAA0B,CAACT,OAAsBH;IACnD,MAAM,EAAEa,UAAU,KAAK,EAAE,QAAQC,mBAAmB,EAAE,EAAE,GAAGX,MAAM,gBAAgB,IAAI,CAAC;IACtF,IAAI,CAACU,SACD,OAAO;IACJ,IAAIE,AAAoC,UAApCA,MAAM,OAAO,CAACD,qBAA+BA,AAA4B,MAA5BA,iBAAiB,MAAM,EAC3E,OAAO;IACJ,IAAId,AAAU,OAAVA,SAAkCA,QAAlBA,OACvB,OAAO;IAEX,KAAK,MAAMgB,mBAAmBF,iBAK1B,IAAIE,gBAAgB,KAAK,IAAIhB,OACzB,OAAO;IAGf,OAAO;AACX;AAEA,MAAMiB,qBAAqB,CACvBC;IAEA,IAAI,CAACA,gBAAgB,QACjB,OAAO,EAAE;IAEb,OAAOA,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AU8C,QACjB,IAAI9C,AAAkB,MAAlBA,OAAO,MAAM,EAGjByC,OAAO,IAAI,IAAIzC;IAEnB,OAAOyC;AACX"}
|
|
1
|
+
{"version":3,"file":"crud/contentEntry/entryDataValidation.js","sources":["../../../src/crud/contentEntry/entryDataValidation.ts"],"sourcesContent":["import type {\n CmsContext,\n CmsDynamicZoneTemplate,\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CmsModelField,\n CmsModelFieldValidation\n} from \"~/types/index.js\";\nimport camelCase from \"lodash/camelCase.js\";\nimport { EntryValidationError } from \"~/domain/contentEntry/errors.js\";\nimport {\n type CmsModelFieldValidator,\n CmsModelFieldValidatorRegistry\n} from \"~/features/validation/index.js\";\n\ntype PluginValidationCallable = (\n params: CmsModelFieldValidator.Params\n) => CmsModelFieldValidator.Response;\ntype PluginValidationList = Record<string, PluginValidationCallable[]>;\n\ninterface ExecuteValidationParams<TValues extends CmsEntryValues = CmsEntryValues> {\n validatorList: PluginValidationList;\n field: CmsModelField;\n model: CmsModel;\n values: TValues;\n context: CmsContext;\n entry?: CmsEntry<TValues>;\n}\n\ntype PossibleValue = boolean | number | string | null | undefined;\n\nconst validateValue = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: ExecuteValidationParams<TValues>,\n fieldValidators: CmsModelFieldValidation[],\n value: PossibleValue | PossibleValue[]\n): Promise<string | null> => {\n if (!fieldValidators) {\n return null;\n }\n const { validatorList, context, field, model, entry } = params;\n try {\n for (const fieldValidator of fieldValidators) {\n const name = fieldValidator.name;\n const validations = validatorList[name];\n if (!validations || validations.length === 0) {\n return `There are no \"${name}\" validators defined.`;\n }\n for (const validate of validations) {\n const result = await validate({\n value,\n context,\n validator: fieldValidator,\n field,\n model,\n entry\n });\n if (!result) {\n return fieldValidator.message;\n }\n }\n }\n } catch (ex) {\n return ex.message;\n }\n\n return null;\n};\n\nconst validatePredefinedValue = (field: CmsModelField, value: any | any[]): string | null => {\n const { enabled = false, values: predefinedValues = [] } = field.predefinedValues || {};\n if (!enabled) {\n return null;\n } else if (Array.isArray(predefinedValues) === false || predefinedValues.length === 0) {\n return \"Missing predefined values to validate against.\";\n } else if (value === \"\" || value === null || value === undefined) {\n return null;\n }\n for (const predefinedValue of predefinedValues) {\n /**\n * No strict compare because the value sent can be 12345 (number) and predefinedValue can be \"12345\" (string),\n * and we want it to match.\n */\n if (predefinedValue.value == value) {\n return null;\n }\n }\n return \"Value sent does not match any of the available predefined values.\";\n};\n\nconst getFieldValidation = (\n listValidation?: CmsModelFieldValidation[]\n): CmsModelFieldValidation[] => {\n if (!listValidation?.length) {\n return [];\n }\n return listValidation.filter(item => item.name !== \"dynamicZone\");\n};\n/**\n * When multiple values is selected we must run validations on the array containing the values\n * And then on each value in the array\n */\nconst runFieldMultipleValuesValidations = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: ExecuteValidationParams<TValues>\n): Promise<string | null> => {\n const { field, values: initialValues } = params;\n const values = initialValues[field.fieldId as keyof TValues] as\n | PossibleValue[]\n | null\n | undefined;\n const valuesError = await validateValue(\n params,\n getFieldValidation(field.listValidation),\n values\n );\n if (valuesError) {\n return valuesError;\n }\n if (values === null || values === undefined) {\n return null;\n }\n for (const value of values) {\n const valueError = await validateValue(params, getFieldValidation(field.validation), value);\n if (valueError) {\n return valueError;\n }\n const predefinedValueError = validatePredefinedValue(field, value);\n if (predefinedValueError) {\n return predefinedValueError;\n }\n }\n return null;\n};\n/**\n * Runs validation on given value.\n */\nconst runFieldValueValidations = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: ExecuteValidationParams<TValues>\n): Promise<string | null> => {\n const { values, field } = params;\n const value = values[field.fieldId as keyof TValues];\n const error = await validateValue(params, field.validation || [], value);\n if (error) {\n return error;\n }\n return validatePredefinedValue(field, value);\n};\n\nconst execValidation = async (params: ExecuteValidationParams): Promise<string | null> => {\n const { field } = params;\n if (field.list) {\n return await runFieldMultipleValuesValidations(params);\n }\n return await runFieldValueValidations(params);\n};\n\ninterface IValidateModelEntryDataParams<TValues extends CmsEntryValues = CmsEntryValues> {\n context: CmsContext;\n model: CmsModel;\n values: TValues;\n entry?: CmsEntry<TValues>;\n skipValidators?: string[];\n}\n\nexport const validateModelEntryData = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: IValidateModelEntryDataParams<TValues>\n) => {\n const { context, model, entry, values, skipValidators } = params;\n\n const isValidatorSkipped = (validator: CmsModelFieldValidator.Interface) => {\n if (!skipValidators) {\n return false;\n }\n return skipValidators.includes(camelCase(validator.name));\n };\n\n const skippedValidators = new Set<string>();\n\n const validatorList: PluginValidationList = {};\n const registry = context.container.resolve(CmsModelFieldValidatorRegistry);\n const validators = registry.getAll();\n for (const validator of validators) {\n const name = validator.name;\n if (!validatorList[name]) {\n validatorList[name] = [];\n }\n const isSkipped = isValidatorSkipped(validator);\n if (isSkipped) {\n skippedValidators.add(name);\n validatorList[name].push(async () => {\n return true;\n });\n continue;\n }\n validatorList[name].push(params => {\n return validator.validate(params);\n });\n }\n /**\n * No point in continuing if all validators are skipped.\n */\n const keys = Object.keys(validatorList);\n if (keys.length === skippedValidators.size) {\n return [];\n }\n\n return await validate<TValues>({\n validatorList,\n context,\n model,\n entry,\n parents: [],\n fields: model.fields,\n values: {\n ...entry?.values,\n ...values\n }\n });\n};\n\nexport const validateModelEntryDataOrThrow = async <\n TValues extends CmsEntryValues = CmsEntryValues\n>(\n params: IValidateModelEntryDataParams<TValues>\n) => {\n const invalidFields = await validateModelEntryData(params);\n if (invalidFields.length === 0) {\n return;\n }\n throw new EntryValidationError(\"Validation failed.\", invalidFields);\n};\n\n/**\n *\n */\ninterface FieldError {\n id: string;\n fieldId: string;\n storageId: string;\n error: any;\n parents: string[];\n}\n\ninterface ValidateFieldParams<TValues extends CmsEntryValues = CmsEntryValues> {\n validatorList: PluginValidationList;\n parents: string[];\n model: CmsModel;\n values: TValues;\n context: CmsContext;\n field: CmsModelField;\n entry?: CmsEntry<TValues>;\n}\n\nconst executeFieldValidation = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: ValidateFieldParams<TValues>\n): Promise<FieldError[]> => {\n // TODO put per-field validation into plugins.\n const { field } = params;\n /**\n * Object field.\n */\n if (field.type === \"object\") {\n const fields = field.settings?.fields;\n if (!Array.isArray(fields)) {\n return [];\n }\n const validations: FieldError[] = [];\n /**\n * We need to validate the object field as well.\n */\n const error = await execValidation({\n ...params,\n field\n });\n if (error) {\n validations.push({\n id: field.id,\n fieldId: field.fieldId,\n storageId: field.storageId,\n error,\n parents: params.parents\n });\n }\n const objectValue = params.values[field.fieldId as keyof TValues];\n if (!objectValue) {\n return validations;\n }\n const values = (Array.isArray(objectValue) ? objectValue : [objectValue]) as TValues[];\n for (const index in values) {\n const parents = field.list ? [field.fieldId, index] : [field.fieldId];\n const value = values[index] as TValues;\n for (const childField of fields) {\n const errors = await executeFieldValidation<typeof value>({\n ...params,\n parents: params.parents.concat(parents),\n field: childField,\n values: value\n });\n if (errors.length === 0) {\n continue;\n }\n validations.push(...errors);\n }\n }\n return validations;\n }\n /**\n * Dynamic Zone Field\n */\n //\n else if (field.type === \"dynamicZone\") {\n const validations: FieldError[] = [];\n\n const error = await execValidation({\n ...params,\n field\n });\n if (error) {\n validations.push({\n id: field.id,\n fieldId: field.fieldId,\n storageId: field.storageId,\n error,\n parents: params.parents\n });\n }\n\n const templates = (field.settings?.templates || []) as CmsDynamicZoneTemplate[];\n for (const template of templates) {\n const fields = template.fields;\n const fieldData = params.values[field.fieldId as keyof TValues];\n if (!fieldData) {\n continue;\n }\n const values: TValues[keyof TValues][] = Array.isArray(fieldData)\n ? fieldData\n : [fieldData];\n for (const index in values) {\n const templateValue = values[index]?.[template.gqlTypeName];\n if (!templateValue) {\n continue;\n }\n /**\n * Order of the parents must be\n * - fieldId\n * - index (if multiple values)\n * - gqlTypeName\n */\n const parents = [field.fieldId];\n if (field.list) {\n parents.push(index);\n }\n parents.push(template.gqlTypeName);\n for (const childField of fields) {\n const errors = await executeFieldValidation({\n ...params,\n parents: params.parents.concat(parents),\n field: childField,\n values: templateValue\n });\n if (errors.length === 0) {\n continue;\n }\n validations.push(...errors);\n }\n }\n }\n\n return validations;\n }\n const error = await execValidation({\n ...params\n });\n if (!error) {\n return [];\n }\n return [\n {\n id: field.id,\n fieldId: field.fieldId,\n storageId: field.storageId,\n error,\n parents: params.parents\n }\n ];\n};\n\ninterface ValidateFieldsParams<TValues extends CmsEntryValues = CmsEntryValues> {\n validatorList: PluginValidationList;\n parents: string[];\n model: CmsModel;\n values: TValues;\n fields: CmsModelField[];\n context: CmsContext;\n entry?: CmsEntry<TValues>;\n}\n\nconst validate = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: ValidateFieldsParams<TValues>\n): Promise<FieldError[]> => {\n const { fields } = params;\n const errors: FieldError[] = [];\n\n const results = await Promise.all(\n fields.map(async field => {\n return await executeFieldValidation<TValues>({\n ...params,\n field\n });\n })\n );\n\n for (const result of results) {\n if (result.length === 0) {\n continue;\n }\n errors.push(...result);\n }\n return errors;\n};\n"],"names":["validateValue","params","fieldValidators","value","validatorList","context","field","model","entry","fieldValidator","name","validations","validate","result","ex","validatePredefinedValue","enabled","predefinedValues","Array","predefinedValue","getFieldValidation","listValidation","item","runFieldMultipleValuesValidations","initialValues","values","valuesError","valueError","predefinedValueError","runFieldValueValidations","error","execValidation","validateModelEntryData","skipValidators","isValidatorSkipped","validator","camelCase","skippedValidators","Set","registry","CmsModelFieldValidatorRegistry","validators","isSkipped","keys","Object","validateModelEntryDataOrThrow","invalidFields","EntryValidationError","executeFieldValidation","fields","objectValue","index","parents","childField","errors","templates","template","fieldData","templateValue","results","Promise"],"mappings":";;;AAgCA,MAAMA,gBAAgB,OAClBC,QACAC,iBACAC;IAEA,IAAI,CAACD,iBACD,OAAO;IAEX,MAAM,EAAEE,aAAa,EAAEC,OAAO,EAAEC,KAAK,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAGP;IACxD,IAAI;QACA,KAAK,MAAMQ,kBAAkBP,gBAAiB;YAC1C,MAAMQ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BAQJ,MAAMN,UAAU;oBAAC9C,MAAM,OAAO;iBAAC;gBAC/B,IAAIA,MAAM,IAAI,EACV8C,QAAQ,IAAI,CAACD;gBAEjBC,QAAQ,IAAI,CAACI,SAAS,WAAW;gBACjC,KAAK,MAAMH,cAAcJ,OAAQ;oBAC7B,MAAMK,SAAS,MAAMN,uBAAuB;wBACxC,GAAG/C,MAAM;wBACT,SAASA,OAAO,OAAO,CAAC,MAAM,CAACmD;wBAC/B,OAAOC;wBACP,QAAQK;oBACZ;oBACA,IAAIJ,AAAkB,MAAlBA,OAAO,MAAM,EAGjB3C,YAAY,IAAI,IAAI2C;gBACxB;YACJ;QACJ;QAEA,OAAO3C;IACX;IACA,MAAMmB,QAAQ,MAAMC,eAAe;QAC/B,GAAG9B,MAAM;IACb;IACA,IAAI,CAAC6B,OACD,OAAO,EAAE;IAEb,OAAO;QACH;YACI,IAAIxB,MAAM,EAAE;YACZ,SAASA,MAAM,OAAO;YACtB,WAAWA,MAAM,SAAS;YAC1BwB;YACA,SAAS7B,OAAO,OAAO;QAC3B;KACH;AACL;AAYA,MAAMW,+BAAW,OACbX;IAEA,MAAM,EAAEgD,MAAM,EAAE,GAAGhD;IACnB,MAAMqD,SAAuB,EAAE;IAE/B,MAAMK,UAAU,MAAMC,QAAQ,GAAG,CAC7BX,OAAO,GAAG,CAAC,OAAM3C,QACN,MAAM0C,uBAAgC;YACzC,GAAG/C,MAAM;YACTK;QACJ;IAIR,KAAK,MAAMO,UAAU8C,QACjB,IAAI9C,AAAkB,MAAlBA,OAAO,MAAM,EAGjByC,OAAO,IAAI,IAAIzC;IAEnB,OAAOyC;AACX"}
|
|
@@ -6,7 +6,7 @@ const validateEndingAllowed = (params)=>{
|
|
|
6
6
|
input: model.singularApiName,
|
|
7
7
|
disallowedEnding: disallowedEnding
|
|
8
8
|
});
|
|
9
|
-
if (false === isModelEndingAllowed(model.pluralApiName)) throw new error(`Content model with pluralApiName "${model.pluralApiName}" is not allowed, as it ends in disallowed value.`, "MODEL_PLURAL_API_NAME_NOT_ENDING_ALLOWED", {
|
|
9
|
+
else if (false === isModelEndingAllowed(model.pluralApiName)) throw new error(`Content model with pluralApiName "${model.pluralApiName}" is not allowed, as it ends in disallowed value.`, "MODEL_PLURAL_API_NAME_NOT_ENDING_ALLOWED", {
|
|
10
10
|
input: model.pluralApiName,
|
|
11
11
|
disallowedEnding: disallowedEnding
|
|
12
12
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crud/contentModel/validate/endingAllowed.js","sources":["../../../../src/crud/contentModel/validate/endingAllowed.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { disallowedEnding, isModelEndingAllowed } from \"./isModelEndingAllowed.js\";\nimport type { CmsModel } from \"~/types/index.js\";\n\ninterface Params {\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validateEndingAllowed = (params: Params): void => {\n const { model } = params;\n if (isModelEndingAllowed(model.singularApiName) === false) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.singularApiName}\" is not allowed, as it ends in disallowed value.`,\n \"MODEL_SINGULAR_API_NAME_ENDING_NOT_ALLOWED\",\n {\n input: model.singularApiName,\n disallowedEnding\n }\n );\n } else if (isModelEndingAllowed(model.pluralApiName) === false) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.pluralApiName}\" is not allowed, as it ends in disallowed value.`,\n \"MODEL_PLURAL_API_NAME_NOT_ENDING_ALLOWED\",\n {\n input: model.pluralApiName,\n disallowedEnding: disallowedEnding\n }\n );\n }\n};\n"],"names":["validateEndingAllowed","params","model","isModelEndingAllowed","WebinyError","disallowedEnding"],"mappings":";;AAQO,MAAMA,wBAAwB,CAACC;IAClC,MAAM,EAAEC,KAAK,EAAE,GAAGD;IAClB,IAAIE,AAAgD,UAAhDA,qBAAqBD,MAAM,eAAe,GAC1C,MAAM,IAAIE,MACN,CAAC,oCAAoC,EAAEF,MAAM,eAAe,CAAC,iDAAiD,CAAC,EAC/G,8CACA;QACI,OAAOA,MAAM,eAAe;QAC5BG,kBAAgBA;IACpB;
|
|
1
|
+
{"version":3,"file":"crud/contentModel/validate/endingAllowed.js","sources":["../../../../src/crud/contentModel/validate/endingAllowed.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { disallowedEnding, isModelEndingAllowed } from \"./isModelEndingAllowed.js\";\nimport type { CmsModel } from \"~/types/index.js\";\n\ninterface Params {\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validateEndingAllowed = (params: Params): void => {\n const { model } = params;\n if (isModelEndingAllowed(model.singularApiName) === false) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.singularApiName}\" is not allowed, as it ends in disallowed value.`,\n \"MODEL_SINGULAR_API_NAME_ENDING_NOT_ALLOWED\",\n {\n input: model.singularApiName,\n disallowedEnding\n }\n );\n } else if (isModelEndingAllowed(model.pluralApiName) === false) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.pluralApiName}\" is not allowed, as it ends in disallowed value.`,\n \"MODEL_PLURAL_API_NAME_NOT_ENDING_ALLOWED\",\n {\n input: model.pluralApiName,\n disallowedEnding: disallowedEnding\n }\n );\n }\n};\n"],"names":["validateEndingAllowed","params","model","isModelEndingAllowed","WebinyError","disallowedEnding"],"mappings":";;AAQO,MAAMA,wBAAwB,CAACC;IAClC,MAAM,EAAEC,KAAK,EAAE,GAAGD;IAClB,IAAIE,AAAgD,UAAhDA,qBAAqBD,MAAM,eAAe,GAC1C,MAAM,IAAIE,MACN,CAAC,oCAAoC,EAAEF,MAAM,eAAe,CAAC,iDAAiD,CAAC,EAC/G,8CACA;QACI,OAAOA,MAAM,eAAe;QAC5BG,kBAAgBA;IACpB;SAED,IAAIF,AAA8C,UAA9CA,qBAAqBD,MAAM,aAAa,GAC/C,MAAM,IAAIE,MACN,CAAC,kCAAkC,EAAEF,MAAM,aAAa,CAAC,iDAAiD,CAAC,EAC3G,4CACA;QACI,OAAOA,MAAM,aAAa;QAC1B,kBAAkBG;IACtB;AAGZ"}
|
|
@@ -4,7 +4,7 @@ const validatePluralApiName = (params)=>{
|
|
|
4
4
|
if (existingModel.singularApiName === model.pluralApiName) throw new error(`Content model with singularApiName "${model.pluralApiName}" already exists.`, "MODEL_SINGULAR_API_NAME_EXISTS", {
|
|
5
5
|
input: model.pluralApiName
|
|
6
6
|
});
|
|
7
|
-
if (existingModel.pluralApiName === model.pluralApiName) throw new error(`Content model with pluralApiName "${model.pluralApiName}" already exists.`, "MODEL_PLURAL_API_NAME_EXISTS", {
|
|
7
|
+
else if (existingModel.pluralApiName === model.pluralApiName) throw new error(`Content model with pluralApiName "${model.pluralApiName}" already exists.`, "MODEL_PLURAL_API_NAME_EXISTS", {
|
|
8
8
|
input: model.pluralApiName
|
|
9
9
|
});
|
|
10
10
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crud/contentModel/validate/pluralApiName.js","sources":["../../../../src/crud/contentModel/validate/pluralApiName.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsModel } from \"~/types/index.js\";\n\ninterface Params {\n existingModel: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validatePluralApiName = (params: Params): void => {\n const { existingModel, model } = params;\n\n if (existingModel.singularApiName === model.pluralApiName) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.pluralApiName}\" already exists.`,\n \"MODEL_SINGULAR_API_NAME_EXISTS\",\n {\n input: model.pluralApiName\n }\n );\n } else if (existingModel.pluralApiName === model.pluralApiName) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.pluralApiName}\" already exists.`,\n \"MODEL_PLURAL_API_NAME_EXISTS\",\n {\n input: model.pluralApiName\n }\n );\n }\n};\n"],"names":["validatePluralApiName","params","existingModel","model","WebinyError"],"mappings":";AAQO,MAAMA,wBAAwB,CAACC;IAClC,MAAM,EAAEC,aAAa,EAAEC,KAAK,EAAE,GAAGF;IAEjC,IAAIC,cAAc,eAAe,KAAKC,MAAM,aAAa,EACrD,MAAM,IAAIC,MACN,CAAC,oCAAoC,EAAED,MAAM,aAAa,CAAC,iBAAiB,CAAC,EAC7E,kCACA;QACI,OAAOA,MAAM,aAAa;IAC9B;
|
|
1
|
+
{"version":3,"file":"crud/contentModel/validate/pluralApiName.js","sources":["../../../../src/crud/contentModel/validate/pluralApiName.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsModel } from \"~/types/index.js\";\n\ninterface Params {\n existingModel: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validatePluralApiName = (params: Params): void => {\n const { existingModel, model } = params;\n\n if (existingModel.singularApiName === model.pluralApiName) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.pluralApiName}\" already exists.`,\n \"MODEL_SINGULAR_API_NAME_EXISTS\",\n {\n input: model.pluralApiName\n }\n );\n } else if (existingModel.pluralApiName === model.pluralApiName) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.pluralApiName}\" already exists.`,\n \"MODEL_PLURAL_API_NAME_EXISTS\",\n {\n input: model.pluralApiName\n }\n );\n }\n};\n"],"names":["validatePluralApiName","params","existingModel","model","WebinyError"],"mappings":";AAQO,MAAMA,wBAAwB,CAACC;IAClC,MAAM,EAAEC,aAAa,EAAEC,KAAK,EAAE,GAAGF;IAEjC,IAAIC,cAAc,eAAe,KAAKC,MAAM,aAAa,EACrD,MAAM,IAAIC,MACN,CAAC,oCAAoC,EAAED,MAAM,aAAa,CAAC,iBAAiB,CAAC,EAC7E,kCACA;QACI,OAAOA,MAAM,aAAa;IAC9B;SAED,IAAID,cAAc,aAAa,KAAKC,MAAM,aAAa,EAC1D,MAAM,IAAIC,MACN,CAAC,kCAAkC,EAAED,MAAM,aAAa,CAAC,iBAAiB,CAAC,EAC3E,gCACA;QACI,OAAOA,MAAM,aAAa;IAC9B;AAGZ"}
|
|
@@ -4,7 +4,7 @@ const validateSingularApiName = (params)=>{
|
|
|
4
4
|
if (existingModel.singularApiName === model.singularApiName) throw new error(`Content model with singularApiName "${model.singularApiName}" already exists.`, "MODEL_SINGULAR_API_NAME_EXISTS", {
|
|
5
5
|
input: model.singularApiName
|
|
6
6
|
});
|
|
7
|
-
if (existingModel.pluralApiName === model.singularApiName) throw new error(`Content model with pluralApiName "${model.singularApiName}" already exists.`, "MODEL_PLURAL_API_NAME_EXISTS", {
|
|
7
|
+
else if (existingModel.pluralApiName === model.singularApiName) throw new error(`Content model with pluralApiName "${model.singularApiName}" already exists.`, "MODEL_PLURAL_API_NAME_EXISTS", {
|
|
8
8
|
input: model.singularApiName
|
|
9
9
|
});
|
|
10
10
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crud/contentModel/validate/singularApiName.js","sources":["../../../../src/crud/contentModel/validate/singularApiName.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsModel } from \"~/types/index.js\";\n\ninterface Params {\n existingModel: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validateSingularApiName = (params: Params): void => {\n const { existingModel, model } = params;\n\n if (existingModel.singularApiName === model.singularApiName) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.singularApiName}\" already exists.`,\n \"MODEL_SINGULAR_API_NAME_EXISTS\",\n {\n input: model.singularApiName\n }\n );\n } else if (existingModel.pluralApiName === model.singularApiName) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.singularApiName}\" already exists.`,\n \"MODEL_PLURAL_API_NAME_EXISTS\",\n {\n input: model.singularApiName\n }\n );\n }\n};\n"],"names":["validateSingularApiName","params","existingModel","model","WebinyError"],"mappings":";AAQO,MAAMA,0BAA0B,CAACC;IACpC,MAAM,EAAEC,aAAa,EAAEC,KAAK,EAAE,GAAGF;IAEjC,IAAIC,cAAc,eAAe,KAAKC,MAAM,eAAe,EACvD,MAAM,IAAIC,MACN,CAAC,oCAAoC,EAAED,MAAM,eAAe,CAAC,iBAAiB,CAAC,EAC/E,kCACA;QACI,OAAOA,MAAM,eAAe;IAChC;
|
|
1
|
+
{"version":3,"file":"crud/contentModel/validate/singularApiName.js","sources":["../../../../src/crud/contentModel/validate/singularApiName.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsModel } from \"~/types/index.js\";\n\ninterface Params {\n existingModel: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validateSingularApiName = (params: Params): void => {\n const { existingModel, model } = params;\n\n if (existingModel.singularApiName === model.singularApiName) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.singularApiName}\" already exists.`,\n \"MODEL_SINGULAR_API_NAME_EXISTS\",\n {\n input: model.singularApiName\n }\n );\n } else if (existingModel.pluralApiName === model.singularApiName) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.singularApiName}\" already exists.`,\n \"MODEL_PLURAL_API_NAME_EXISTS\",\n {\n input: model.singularApiName\n }\n );\n }\n};\n"],"names":["validateSingularApiName","params","existingModel","model","WebinyError"],"mappings":";AAQO,MAAMA,0BAA0B,CAACC;IACpC,MAAM,EAAEC,aAAa,EAAEC,KAAK,EAAE,GAAGF;IAEjC,IAAIC,cAAc,eAAe,KAAKC,MAAM,eAAe,EACvD,MAAM,IAAIC,MACN,CAAC,oCAAoC,EAAED,MAAM,eAAe,CAAC,iBAAiB,CAAC,EAC/E,kCACA;QACI,OAAOA,MAAM,eAAe;IAChC;SAED,IAAID,cAAc,aAAa,KAAKC,MAAM,eAAe,EAC5D,MAAM,IAAIC,MACN,CAAC,kCAAkC,EAAED,MAAM,eAAe,CAAC,iBAAiB,CAAC,EAC7E,gCACA;QACI,OAAOA,MAAM,eAAe;IAChC;AAGZ"}
|
|
@@ -114,13 +114,13 @@ const refinementPluralValidationMessage = (value)=>({
|
|
|
114
114
|
});
|
|
115
115
|
const refinementModelIdValidation = (value)=>{
|
|
116
116
|
if (!value) return true;
|
|
117
|
-
if (null === value.match(/^[a-zA-Z]/)) return false;
|
|
117
|
+
else if (null === value.match(/^[a-zA-Z]/)) return false;
|
|
118
118
|
const camelCasedValue = camelCase(value).toLowerCase();
|
|
119
119
|
return camelCasedValue === value.toLowerCase();
|
|
120
120
|
};
|
|
121
121
|
const refinementModelIdValidationMessage = (value)=>{
|
|
122
122
|
if (!value) return {};
|
|
123
|
-
if (null === value.match(/^[a-zA-Z]/)) return {
|
|
123
|
+
else if (null === value.match(/^[a-zA-Z]/)) return {
|
|
124
124
|
message: `The modelId "${value}" is not valid. It must start with a A-Z or a-z.`
|
|
125
125
|
};
|
|
126
126
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crud/contentModel/validation.js","sources":["../../../src/crud/contentModel/validation.ts"],"sourcesContent":["import zod from \"zod\";\nimport upperFirst from \"lodash/upperFirst.js\";\nimport camelCase from \"lodash/camelCase.js\";\n\nconst fieldSystemFields: string[] = [\n \"id\",\n \"entryId\",\n \"createdOn\",\n \"modifiedOn\",\n \"publishedOn\",\n \"savedOn\",\n \"deletedOn\",\n \"restoredOn\",\n \"firstPublishedOn\",\n \"lastPublishedOn\",\n \"createdBy\",\n \"modifiedBy\",\n \"savedBy\",\n \"deletedBy\",\n \"restoredBy\",\n \"firstPublishedBy\",\n \"lastPublishedBy\",\n \"revisionCreatedOn\",\n \"revisionModifiedOn\",\n \"revisionSavedOn\",\n \"revisionDeletedOn\",\n \"revisionRestoredOn\",\n \"revisionFirstPublishedOn\",\n \"revisionLastPublishedOn\",\n \"revisionCreatedBy\",\n \"revisionModifiedBy\",\n \"revisionSavedBy\",\n \"revisionDeletedBy\",\n \"revisionRestoredBy\",\n \"revisionFirstPublishedBy\",\n \"revisionLastPublishedBy\",\n \"meta\",\n \"wbyAco_location\"\n];\n\nconst str = zod.string().trim();\nconst shortString = str.max(255);\nconst longString = str.max(255);\nconst optionalShortString = shortString.optional();\nconst optionalLongString = longString.optional();\nconst optionalNullishShortString = optionalShortString.nullish().default(null);\nconst optionalNullishLongString = optionalLongString.nullish().default(null);\n\nconst icon = zod\n .looseObject({\n type: zod.string(),\n name: zod.string(),\n value: zod.string().optional()\n })\n .optional()\n .nullish()\n .default(null)\n .transform(value => {\n if (typeof value === \"string\") {\n return {\n type: \"icon\",\n name: value\n };\n }\n return value;\n });\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: `Field ID \"${value}\" is a reserved keyword, and is not allowed.`\n });\n }\n }),\n label: shortString,\n help: optionalNullishLongString,\n description: optionalNullishShortString,\n note: optionalNullishShortString,\n placeholder: optionalNullishShortString,\n type: shortString,\n tags: zod.array(shortString).optional().default([]),\n list: 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 .nullish()\n .optional()\n .transform(value => {\n return value || undefined;\n }),\n renderer: zod\n .object({\n name: shortString,\n settings: zod.looseObject({}).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 .looseObject({})\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 .looseObject({})\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 .looseObject({})\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 refineSingularApiName = (value: string, ctx: zod.RefinementCtx) => {\n if (!apiNameRefinementValidation(value)) {\n ctx.addIssue({\n code: zod.ZodIssueCode.custom,\n ...refinementSingularValidationMessage(value)\n });\n }\n};\n\nconst refinePluralApiName = (value: string, ctx: zod.RefinementCtx) => {\n if (!apiNameRefinementValidation(value)) {\n ctx.addIssue({\n code: zod.ZodIssueCode.custom,\n ...refinementPluralValidationMessage(value)\n });\n }\n};\n\nconst refineModelId = (value: string, ctx: zod.RefinementCtx) => {\n if (!refinementModelIdValidation(value)) {\n ctx.addIssue({\n code: zod.ZodIssueCode.custom,\n ...refinementModelIdValidationMessage(value)\n });\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.min(1).superRefine(refineSingularApiName),\n pluralApiName: shortString.min(1).superRefine(refinePluralApiName),\n description: optionalNullishShortString.transform(value => {\n return value || \"\";\n }),\n group: shortString,\n icon,\n fields: zod.array(fieldSchema).default([]),\n layout: zod.array(zod.array(zod.any())).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).superRefine((value, ctx) => {\n if (value.match(/[a-zA-Z]/) === null) {\n ctx.addIssue({\n code: zod.ZodIssueCode.custom,\n message: `The name \"${value}\" is not valid.`\n });\n }\n }),\n modelId: shortString.min(1).superRefine(refineModelId).transform(modelIdTransformation),\n singularApiName: shortString.min(1).superRefine(refineSingularApiName),\n pluralApiName: shortString.min(1).superRefine(refinePluralApiName),\n description: optionalNullishShortString,\n group: shortString,\n icon,\n fields: zod.array(fieldSchema).min(1),\n layout: zod.array(zod.array(zod.any())),\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.superRefine(refineSingularApiName),\n pluralApiName: shortString.superRefine(refinePluralApiName),\n description: optionalNullishShortString,\n group: shortString,\n icon\n });\n};\n\nexport const createModelUpdateValidation = () => {\n return zod.object({\n name: optionalShortString,\n singularApiName: optionalShortString.superRefine((value, ctx) => {\n if (value) {\n refineSingularApiName(value, ctx);\n }\n }),\n pluralApiName: optionalShortString.superRefine((value, ctx) => {\n if (value) {\n refinePluralApiName(value, ctx);\n }\n }),\n description: optionalNullishShortString,\n group: optionalShortString,\n icon,\n fields: zod.array(fieldSchema),\n layout: zod.array(zod.array(zod.any())),\n titleFieldId: optionalShortString.nullish(),\n descriptionFieldId: optionalShortString.nullish(),\n imageFieldId: optionalShortString.nullish(),\n tags: zod.array(shortString).optional()\n });\n};\n"],"names":["fieldSystemFields","str","zod","shortString","longString","optionalShortString","optionalLongString","optionalNullishShortString","optionalNullishLongString","icon","value","fieldSchema","ctx","undefined","apiNameRefinementValidation","upperFirst","camelCase","refinementSingularValidationMessage","refinementPluralValidationMessage","refinementModelIdValidation","camelCasedValue","refinementModelIdValidationMessage","refineSingularApiName","refinePluralApiName","refineModelId","modelIdTransformation","createModelCreateValidation","createModelImportValidation","createModelCreateFromValidation","createModelUpdateValidation"],"mappings":";;;AAIA,MAAMA,oBAA8B;IAChC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACH;AAED,MAAMC,MAAMC,IAAI,MAAM,GAAG,IAAI;AAC7B,MAAMC,cAAcF,IAAI,GAAG,CAAC;AAC5B,MAAMG,aAAaH,IAAI,GAAG,CAAC;AAC3B,MAAMI,sBAAsBF,YAAY,QAAQ;AAChD,MAAMG,qBAAqBF,WAAW,QAAQ;AAC9C,MAAMG,6BAA6BF,oBAAoB,OAAO,GAAG,OAAO,CAAC;AACzE,MAAMG,4BAA4BF,mBAAmB,O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K,CAACC,aAAa,QAAQ;QACrC,cAAcA,YAAY,OAAO;QACjC,oBAAoBE,oBAAoB,OAAO;QAC/C,cAAcA,oBAAoB,OAAO;IAC7C;AAGG,MAAMuB,kCAAkC,IACpC1B,IAAI,MAAM,CAAC;QACd,MAAMC;QACN,SAASE,oBAAoB,SAAS,CAACoB;QACvC,iBAAiBtB,YAAY,WAAW,CAACmB;QACzC,eAAenB,YAAY,WAAW,CAACoB;QACvC,aAAahB;QACb,OAAOJ;QACPM,MAAAA;IACJ;AAGG,MAAMoB,8BAA8B,IAChC3B,IAAI,MAAM,CAAC;QACd,MAAMG;QACN,iBAAiBA,oBAAoB,WAAW,CAAC,CAACK,OAAOE;YACrD,IAAIF,OACAY,sBAAsBZ,OAAOE;QAErC;QACA,eAAeP,oBAAoB,WAAW,CAAC,CAACK,OAAOE;YACnD,IAAIF,OACAa,oBAAoBb,OAAOE;QAEnC;QACA,aAAaL;QACb,OAAOF;QACPI,MAAAA;QACA,QAAQP,IAAI,KAAK,CAACS;QAClB,QAAQT,IAAI,KAAK,CAACA,IAAI,KAAK,CAACA,IAAI,GAAG;QACnC,cAAcG,oBAAoB,OAAO;QACzC,oBAAoBA,oBAAoB,OAAO;QAC/C,cAAcA,oBAAoB,OAAO;QACzC,MAAMH,IAAI,KAAK,CAACC,aAAa,QAAQ;IACzC"}
|
|
1
|
+
{"version":3,"file":"crud/contentModel/validation.js","sources":["../../../src/crud/contentModel/validation.ts"],"sourcesContent":["import zod from \"zod\";\nimport upperFirst from \"lodash/upperFirst.js\";\nimport camelCase from \"lodash/camelCase.js\";\n\nconst fieldSystemFields: string[] = [\n \"id\",\n \"entryId\",\n \"createdOn\",\n \"modifiedOn\",\n \"publishedOn\",\n \"savedOn\",\n \"deletedOn\",\n \"restoredOn\",\n \"firstPublishedOn\",\n \"lastPublishedOn\",\n \"createdBy\",\n \"modifiedBy\",\n \"savedBy\",\n \"deletedBy\",\n \"restoredBy\",\n \"firstPublishedBy\",\n \"lastPublishedBy\",\n \"revisionCreatedOn\",\n \"revisionModifiedOn\",\n \"revisionSavedOn\",\n \"revisionDeletedOn\",\n \"revisionRestoredOn\",\n \"revisionFirstPublishedOn\",\n \"revisionLastPublishedOn\",\n \"revisionCreatedBy\",\n \"revisionModifiedBy\",\n \"revisionSavedBy\",\n \"revisionDeletedBy\",\n \"revisionRestoredBy\",\n \"revisionFirstPublishedBy\",\n \"revisionLastPublishedBy\",\n \"meta\",\n \"wbyAco_location\"\n];\n\nconst str = zod.string().trim();\nconst shortString = str.max(255);\nconst longString = str.max(255);\nconst optionalShortString = shortString.optional();\nconst optionalLongString = longString.optional();\nconst optionalNullishShortString = optionalShortString.nullish().default(null);\nconst optionalNullishLongString = optionalLongString.nullish().default(null);\n\nconst icon = zod\n .looseObject({\n type: zod.string(),\n name: zod.string(),\n value: zod.string().optional()\n })\n .optional()\n .nullish()\n .default(null)\n .transform(value => {\n if (typeof value === \"string\") {\n return {\n type: \"icon\",\n name: value\n };\n }\n return value;\n });\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: `Field ID \"${value}\" is a reserved keyword, and is not allowed.`\n });\n }\n }),\n label: shortString,\n help: optionalNullishLongString,\n description: optionalNullishShortString,\n note: optionalNullishShortString,\n placeholder: optionalNullishShortString,\n type: shortString,\n tags: zod.array(shortString).optional().default([]),\n list: 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 .nullish()\n .optional()\n .transform(value => {\n return value || undefined;\n }),\n renderer: zod\n .object({\n name: shortString,\n settings: zod.looseObject({}).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 .looseObject({})\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 .looseObject({})\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 .looseObject({})\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 refineSingularApiName = (value: string, ctx: zod.RefinementCtx) => {\n if (!apiNameRefinementValidation(value)) {\n ctx.addIssue({\n code: zod.ZodIssueCode.custom,\n ...refinementSingularValidationMessage(value)\n });\n }\n};\n\nconst refinePluralApiName = (value: string, ctx: zod.RefinementCtx) => {\n if (!apiNameRefinementValidation(value)) {\n ctx.addIssue({\n code: zod.ZodIssueCode.custom,\n ...refinementPluralValidationMessage(value)\n });\n }\n};\n\nconst refineModelId = (value: string, ctx: zod.RefinementCtx) => {\n if (!refinementModelIdValidation(value)) {\n ctx.addIssue({\n code: zod.ZodIssueCode.custom,\n ...refinementModelIdValidationMessage(value)\n });\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.min(1).superRefine(refineSingularApiName),\n pluralApiName: shortString.min(1).superRefine(refinePluralApiName),\n description: optionalNullishShortString.transform(value => {\n return value || \"\";\n }),\n group: shortString,\n icon,\n fields: zod.array(fieldSchema).default([]),\n layout: zod.array(zod.array(zod.any())).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).superRefine((value, ctx) => {\n if (value.match(/[a-zA-Z]/) === null) {\n ctx.addIssue({\n code: zod.ZodIssueCode.custom,\n message: `The name \"${value}\" is not valid.`\n });\n }\n }),\n modelId: shortString.min(1).superRefine(refineModelId).transform(modelIdTransformation),\n singularApiName: shortString.min(1).superRefine(refineSingularApiName),\n pluralApiName: shortString.min(1).superRefine(refinePluralApiName),\n description: optionalNullishShortString,\n group: shortString,\n icon,\n fields: zod.array(fieldSchema).min(1),\n layout: zod.array(zod.array(zod.any())),\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.superRefine(refineSingularApiName),\n pluralApiName: shortString.superRefine(refinePluralApiName),\n description: optionalNullishShortString,\n group: shortString,\n icon\n });\n};\n\nexport const createModelUpdateValidation = () => {\n return zod.object({\n name: optionalShortString,\n singularApiName: optionalShortString.superRefine((value, ctx) => {\n if (value) {\n refineSingularApiName(value, ctx);\n }\n }),\n pluralApiName: optionalShortString.superRefine((value, ctx) => {\n if (value) {\n refinePluralApiName(value, ctx);\n }\n }),\n description: optionalNullishShortString,\n group: optionalShortString,\n icon,\n fields: zod.array(fieldSchema),\n layout: zod.array(zod.array(zod.any())),\n titleFieldId: optionalShortString.nullish(),\n descriptionFieldId: optionalShortString.nullish(),\n imageFieldId: optionalShortString.nullish(),\n tags: zod.array(shortString).optional()\n });\n};\n"],"names":["fieldSystemFields","str","zod","shortString","longString","optionalShortString","optionalLongString","optionalNullishShortString","optionalNullishLongString","icon","value","fieldSchema","ctx","undefined","apiNameRefinementValidation","upperFirst","camelCase","refinementSingularValidationMessage","refinementPluralValidationMessage","refinementModelIdValidation","camelCasedValue","refinementModelIdValidationMessage","refineSingularApiName","refinePluralApiName","refineModelId","modelIdTransformation","createModelCreateValidation","createModelImportValidation","createModelCreateFromValidation","createModelUpdateValidation"],"mappings":";;;AAIA,MAAMA,oBAA8B;IAChC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;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nding: disallowedEnding
|
|
8
8
|
});
|
|
9
|
-
if (false === isModelEndingAllowed(model.pluralApiName)) throw new error(`Content model with pluralApiName "${model.pluralApiName}" is not allowed, as it ends in disallowed value.`, "MODEL_PLURAL_API_NAME_NOT_ENDING_ALLOWED", {
|
|
9
|
+
else if (false === isModelEndingAllowed(model.pluralApiName)) throw new error(`Content model with pluralApiName "${model.pluralApiName}" is not allowed, as it ends in disallowed value.`, "MODEL_PLURAL_API_NAME_NOT_ENDING_ALLOWED", {
|
|
10
10
|
input: model.pluralApiName,
|
|
11
11
|
disallowedEnding: disallowedEnding
|
|
12
12
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domain/contentModel/validation/endingAllowed.js","sources":["../../../../src/domain/contentModel/validation/endingAllowed.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { disallowedEnding, isModelEndingAllowed } from \"./isModelEndingAllowed.js\";\nimport type { CmsModel } from \"~/types/index.js\";\n\ninterface Params {\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validateEndingAllowed = (params: Params): void => {\n const { model } = params;\n if (isModelEndingAllowed(model.singularApiName) === false) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.singularApiName}\" is not allowed, as it ends in disallowed value.`,\n \"MODEL_SINGULAR_API_NAME_ENDING_NOT_ALLOWED\",\n {\n input: model.singularApiName,\n disallowedEnding\n }\n );\n } else if (isModelEndingAllowed(model.pluralApiName) === false) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.pluralApiName}\" is not allowed, as it ends in disallowed value.`,\n \"MODEL_PLURAL_API_NAME_NOT_ENDING_ALLOWED\",\n {\n input: model.pluralApiName,\n disallowedEnding: disallowedEnding\n }\n );\n }\n};\n"],"names":["validateEndingAllowed","params","model","isModelEndingAllowed","WebinyError","disallowedEnding"],"mappings":";;AAQO,MAAMA,wBAAwB,CAACC;IAClC,MAAM,EAAEC,KAAK,EAAE,GAAGD;IAClB,IAAIE,AAAgD,UAAhDA,qBAAqBD,MAAM,eAAe,GAC1C,MAAM,IAAIE,MACN,CAAC,oCAAoC,EAAEF,MAAM,eAAe,CAAC,iDAAiD,CAAC,EAC/G,8CACA;QACI,OAAOA,MAAM,eAAe;QAC5BG,kBAAgBA;IACpB;
|
|
1
|
+
{"version":3,"file":"domain/contentModel/validation/endingAllowed.js","sources":["../../../../src/domain/contentModel/validation/endingAllowed.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { disallowedEnding, isModelEndingAllowed } from \"./isModelEndingAllowed.js\";\nimport type { CmsModel } from \"~/types/index.js\";\n\ninterface Params {\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validateEndingAllowed = (params: Params): void => {\n const { model } = params;\n if (isModelEndingAllowed(model.singularApiName) === false) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.singularApiName}\" is not allowed, as it ends in disallowed value.`,\n \"MODEL_SINGULAR_API_NAME_ENDING_NOT_ALLOWED\",\n {\n input: model.singularApiName,\n disallowedEnding\n }\n );\n } else if (isModelEndingAllowed(model.pluralApiName) === false) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.pluralApiName}\" is not allowed, as it ends in disallowed value.`,\n \"MODEL_PLURAL_API_NAME_NOT_ENDING_ALLOWED\",\n {\n input: model.pluralApiName,\n disallowedEnding: disallowedEnding\n }\n );\n }\n};\n"],"names":["validateEndingAllowed","params","model","isModelEndingAllowed","WebinyError","disallowedEnding"],"mappings":";;AAQO,MAAMA,wBAAwB,CAACC;IAClC,MAAM,EAAEC,KAAK,EAAE,GAAGD;IAClB,IAAIE,AAAgD,UAAhDA,qBAAqBD,MAAM,eAAe,GAC1C,MAAM,IAAIE,MACN,CAAC,oCAAoC,EAAEF,MAAM,eAAe,CAAC,iDAAiD,CAAC,EAC/G,8CACA;QACI,OAAOA,MAAM,eAAe;QAC5BG,kBAAgBA;IACpB;SAED,IAAIF,AAA8C,UAA9CA,qBAAqBD,MAAM,aAAa,GAC/C,MAAM,IAAIE,MACN,CAAC,kCAAkC,EAAEF,MAAM,aAAa,CAAC,iDAAiD,CAAC,EAC3G,4CACA;QACI,OAAOA,MAAM,aAAa;QAC1B,kBAAkBG;IACtB;AAGZ"}
|
|
@@ -4,7 +4,7 @@ const validatePluralApiName = (params)=>{
|
|
|
4
4
|
if (existingModel.singularApiName === model.pluralApiName) throw new error(`Content model with singularApiName "${model.pluralApiName}" already exists.`, "MODEL_SINGULAR_API_NAME_EXISTS", {
|
|
5
5
|
input: model.pluralApiName
|
|
6
6
|
});
|
|
7
|
-
if (existingModel.pluralApiName === model.pluralApiName) throw new error(`Content model with pluralApiName "${model.pluralApiName}" already exists.`, "MODEL_PLURAL_API_NAME_EXISTS", {
|
|
7
|
+
else if (existingModel.pluralApiName === model.pluralApiName) throw new error(`Content model with pluralApiName "${model.pluralApiName}" already exists.`, "MODEL_PLURAL_API_NAME_EXISTS", {
|
|
8
8
|
input: model.pluralApiName
|
|
9
9
|
});
|
|
10
10
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domain/contentModel/validation/pluralApiName.js","sources":["../../../../src/domain/contentModel/validation/pluralApiName.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsModel } from \"~/types/index.js\";\n\ninterface Params {\n existingModel: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validatePluralApiName = (params: Params): void => {\n const { existingModel, model } = params;\n\n if (existingModel.singularApiName === model.pluralApiName) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.pluralApiName}\" already exists.`,\n \"MODEL_SINGULAR_API_NAME_EXISTS\",\n {\n input: model.pluralApiName\n }\n );\n } else if (existingModel.pluralApiName === model.pluralApiName) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.pluralApiName}\" already exists.`,\n \"MODEL_PLURAL_API_NAME_EXISTS\",\n {\n input: model.pluralApiName\n }\n );\n }\n};\n"],"names":["validatePluralApiName","params","existingModel","model","WebinyError"],"mappings":";AAQO,MAAMA,wBAAwB,CAACC;IAClC,MAAM,EAAEC,aAAa,EAAEC,KAAK,EAAE,GAAGF;IAEjC,IAAIC,cAAc,eAAe,KAAKC,MAAM,aAAa,EACrD,MAAM,IAAIC,MACN,CAAC,oCAAoC,EAAED,MAAM,aAAa,CAAC,iBAAiB,CAAC,EAC7E,kCACA;QACI,OAAOA,MAAM,aAAa;IAC9B;
|
|
1
|
+
{"version":3,"file":"domain/contentModel/validation/pluralApiName.js","sources":["../../../../src/domain/contentModel/validation/pluralApiName.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsModel } from \"~/types/index.js\";\n\ninterface Params {\n existingModel: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validatePluralApiName = (params: Params): void => {\n const { existingModel, model } = params;\n\n if (existingModel.singularApiName === model.pluralApiName) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.pluralApiName}\" already exists.`,\n \"MODEL_SINGULAR_API_NAME_EXISTS\",\n {\n input: model.pluralApiName\n }\n );\n } else if (existingModel.pluralApiName === model.pluralApiName) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.pluralApiName}\" already exists.`,\n \"MODEL_PLURAL_API_NAME_EXISTS\",\n {\n input: model.pluralApiName\n }\n );\n }\n};\n"],"names":["validatePluralApiName","params","existingModel","model","WebinyError"],"mappings":";AAQO,MAAMA,wBAAwB,CAACC;IAClC,MAAM,EAAEC,aAAa,EAAEC,KAAK,EAAE,GAAGF;IAEjC,IAAIC,cAAc,eAAe,KAAKC,MAAM,aAAa,EACrD,MAAM,IAAIC,MACN,CAAC,oCAAoC,EAAED,MAAM,aAAa,CAAC,iBAAiB,CAAC,EAC7E,kCACA;QACI,OAAOA,MAAM,aAAa;IAC9B;SAED,IAAID,cAAc,aAAa,KAAKC,MAAM,aAAa,EAC1D,MAAM,IAAIC,MACN,CAAC,kCAAkC,EAAED,MAAM,aAAa,CAAC,iBAAiB,CAAC,EAC3E,gCACA;QACI,OAAOA,MAAM,aAAa;IAC9B;AAGZ"}
|
|
@@ -4,7 +4,7 @@ const validateSingularApiName = (params)=>{
|
|
|
4
4
|
if (existingModel.singularApiName === model.singularApiName) throw new error(`Content model with singularApiName "${model.singularApiName}" already exists.`, "MODEL_SINGULAR_API_NAME_EXISTS", {
|
|
5
5
|
input: model.singularApiName
|
|
6
6
|
});
|
|
7
|
-
if (existingModel.pluralApiName === model.singularApiName) throw new error(`Content model with pluralApiName "${model.singularApiName}" already exists.`, "MODEL_PLURAL_API_NAME_EXISTS", {
|
|
7
|
+
else if (existingModel.pluralApiName === model.singularApiName) throw new error(`Content model with pluralApiName "${model.singularApiName}" already exists.`, "MODEL_PLURAL_API_NAME_EXISTS", {
|
|
8
8
|
input: model.singularApiName
|
|
9
9
|
});
|
|
10
10
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domain/contentModel/validation/singularApiName.js","sources":["../../../../src/domain/contentModel/validation/singularApiName.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsModel } from \"~/types/index.js\";\n\ninterface Params {\n existingModel: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validateSingularApiName = (params: Params): void => {\n const { existingModel, model } = params;\n\n if (existingModel.singularApiName === model.singularApiName) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.singularApiName}\" already exists.`,\n \"MODEL_SINGULAR_API_NAME_EXISTS\",\n {\n input: model.singularApiName\n }\n );\n } else if (existingModel.pluralApiName === model.singularApiName) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.singularApiName}\" already exists.`,\n \"MODEL_PLURAL_API_NAME_EXISTS\",\n {\n input: model.singularApiName\n }\n );\n }\n};\n"],"names":["validateSingularApiName","params","existingModel","model","WebinyError"],"mappings":";AAQO,MAAMA,0BAA0B,CAACC;IACpC,MAAM,EAAEC,aAAa,EAAEC,KAAK,EAAE,GAAGF;IAEjC,IAAIC,cAAc,eAAe,KAAKC,MAAM,eAAe,EACvD,MAAM,IAAIC,MACN,CAAC,oCAAoC,EAAED,MAAM,eAAe,CAAC,iBAAiB,CAAC,EAC/E,kCACA;QACI,OAAOA,MAAM,eAAe;IAChC;
|
|
1
|
+
{"version":3,"file":"domain/contentModel/validation/singularApiName.js","sources":["../../../../src/domain/contentModel/validation/singularApiName.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsModel } from \"~/types/index.js\";\n\ninterface Params {\n existingModel: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validateSingularApiName = (params: Params): void => {\n const { existingModel, model } = params;\n\n if (existingModel.singularApiName === model.singularApiName) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.singularApiName}\" already exists.`,\n \"MODEL_SINGULAR_API_NAME_EXISTS\",\n {\n input: model.singularApiName\n }\n );\n } else if (existingModel.pluralApiName === model.singularApiName) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.singularApiName}\" already exists.`,\n \"MODEL_PLURAL_API_NAME_EXISTS\",\n {\n input: model.singularApiName\n }\n );\n }\n};\n"],"names":["validateSingularApiName","params","existingModel","model","WebinyError"],"mappings":";AAQO,MAAMA,0BAA0B,CAACC;IACpC,MAAM,EAAEC,aAAa,EAAEC,KAAK,EAAE,GAAGF;IAEjC,IAAIC,cAAc,eAAe,KAAKC,MAAM,eAAe,EACvD,MAAM,IAAIC,MACN,CAAC,oCAAoC,EAAED,MAAM,eAAe,CAAC,iBAAiB,CAAC,EAC/E,kCACA;QACI,OAAOA,MAAM,eAAe;IAChC;SAED,IAAID,cAAc,aAAa,KAAKC,MAAM,eAAe,EAC5D,MAAM,IAAIC,MACN,CAAC,kCAAkC,EAAED,MAAM,eAAe,CAAC,iBAAiB,CAAC,EAC7E,gCACA;QACI,OAAOA,MAAM,eAAe;IAChC;AAGZ"}
|
package/export/crud/exporting.js
CHANGED
|
@@ -4,8 +4,8 @@ const createExportStructureContext = (context)=>async (params)=>{
|
|
|
4
4
|
const groups = (await context.cms.listGroups()).map(sanitizeGroup);
|
|
5
5
|
const models = (await context.cms.listModels()).filter((model)=>{
|
|
6
6
|
if (model.isPrivate) return false;
|
|
7
|
-
if (!model.fields?.length) return false;
|
|
8
|
-
if (!modelIdList?.length) return true;
|
|
7
|
+
else if (!model.fields?.length) return false;
|
|
8
|
+
else if (!modelIdList?.length) return true;
|
|
9
9
|
return modelIdList.includes(model.modelId);
|
|
10
10
|
}).map((model)=>{
|
|
11
11
|
const group = groups.find((group)=>group.slug === model.group);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export/crud/exporting.js","sources":["../../../src/export/crud/exporting.ts"],"sourcesContent":["import type { HeadlessCmsExportStructure, SanitizedCmsModel } from \"~/export/types.js\";\nimport type { CmsContext } from \"~/types/index.js\";\nimport { sanitizeGroup, sanitizeModel } from \"./sanitize.js\";\n\nexport const createExportStructureContext = (context: CmsContext): HeadlessCmsExportStructure => {\n return async params => {\n const { models: modelIdList } = params;\n const groups = (await context.cms.listGroups()).map(sanitizeGroup);\n /**\n * We need all the models which:\n * * are accessible by current user\n * * are not private\n * * are included (if targets are provided)\n * * are part of one of the groups we already fetched\n */\n const models = (await context.cms.listModels())\n .filter(model => {\n if (model.isPrivate) {\n return false;\n } else if (!model.fields?.length) {\n return false;\n } else if (!modelIdList?.length) {\n return true;\n }\n return modelIdList.includes(model.modelId);\n })\n .map(model => {\n const group = groups.find(group => group.slug === model.group);\n if (!group) {\n return null;\n }\n return sanitizeModel(group, model);\n })\n .filter((model): model is SanitizedCmsModel => {\n return !!model;\n });\n\n return {\n groups: groups.filter(group => {\n return models.some(model => model.group === group.slug);\n }),\n models\n };\n };\n};\n"],"names":["createExportStructureContext","context","params","modelIdList","groups","sanitizeGroup","models","model","group","sanitizeModel"],"mappings":";AAIO,MAAMA,+BAA+B,CAACC,UAClC,OAAMC;QACT,MAAM,EAAE,QAAQC,WAAW,EAAE,GAAGD;QAChC,MAAME,SAAU,OAAMH,QAAQ,GAAG,CAAC,UAAU,EAAC,EAAG,GAAG,CAACI;QAQpD,MAAMC,SAAU,OAAML,QAAQ,GAAG,CAAC,UAAU,EAAC,EACxC,MAAM,CAACM,CAAAA;YACJ,IAAIA,MAAM,SAAS,EACf,OAAO;
|
|
1
|
+
{"version":3,"file":"export/crud/exporting.js","sources":["../../../src/export/crud/exporting.ts"],"sourcesContent":["import type { HeadlessCmsExportStructure, SanitizedCmsModel } from \"~/export/types.js\";\nimport type { CmsContext } from \"~/types/index.js\";\nimport { sanitizeGroup, sanitizeModel } from \"./sanitize.js\";\n\nexport const createExportStructureContext = (context: CmsContext): HeadlessCmsExportStructure => {\n return async params => {\n const { models: modelIdList } = params;\n const groups = (await context.cms.listGroups()).map(sanitizeGroup);\n /**\n * We need all the models which:\n * * are accessible by current user\n * * are not private\n * * are included (if targets are provided)\n * * are part of one of the groups we already fetched\n */\n const models = (await context.cms.listModels())\n .filter(model => {\n if (model.isPrivate) {\n return false;\n } else if (!model.fields?.length) {\n return false;\n } else if (!modelIdList?.length) {\n return true;\n }\n return modelIdList.includes(model.modelId);\n })\n .map(model => {\n const group = groups.find(group => group.slug === model.group);\n if (!group) {\n return null;\n }\n return sanitizeModel(group, model);\n })\n .filter((model): model is SanitizedCmsModel => {\n return !!model;\n });\n\n return {\n groups: groups.filter(group => {\n return models.some(model => model.group === group.slug);\n }),\n models\n };\n };\n};\n"],"names":["createExportStructureContext","context","params","modelIdList","groups","sanitizeGroup","models","model","group","sanitizeModel"],"mappings":";AAIO,MAAMA,+BAA+B,CAACC,UAClC,OAAMC;QACT,MAAM,EAAE,QAAQC,WAAW,EAAE,GAAGD;QAChC,MAAME,SAAU,OAAMH,QAAQ,GAAG,CAAC,UAAU,EAAC,EAAG,GAAG,CAACI;QAQpD,MAAMC,SAAU,OAAML,QAAQ,GAAG,CAAC,UAAU,EAAC,EACxC,MAAM,CAACM,CAAAA;YACJ,IAAIA,MAAM,SAAS,EACf,OAAO;iBACJ,IAAI,CAACA,MAAM,MAAM,EAAE,QACtB,OAAO;iBACJ,IAAI,CAACJ,aAAa,QACrB,OAAO;YAEX,OAAOA,YAAY,QAAQ,CAACI,MAAM,OAAO;QAC7C,GACC,GAAG,CAACA,CAAAA;YACD,MAAMC,QAAQJ,OAAO,IAAI,CAACI,CAAAA,QAASA,MAAM,IAAI,KAAKD,MAAM,KAAK;YAC7D,IAAI,CAACC,OACD,OAAO;YAEX,OAAOC,cAAcD,OAAOD;QAChC,GACC,MAAM,CAAC,CAACA,QACE,CAAC,CAACA;QAGjB,OAAO;YACH,QAAQH,OAAO,MAAM,CAACI,CAAAA,QACXF,OAAO,IAAI,CAACC,CAAAA,QAASA,MAAM,KAAK,KAAKC,MAAM,IAAI;YAE1DF;QACJ;IACJ"}
|
|
@@ -19,8 +19,7 @@ const importGroups = async (params)=>{
|
|
|
19
19
|
imported: true
|
|
20
20
|
});
|
|
21
21
|
continue;
|
|
22
|
-
}
|
|
23
|
-
if (group.action === CmsImportAction.UPDATE) {
|
|
22
|
+
} else if (group.action === CmsImportAction.UPDATE) {
|
|
24
23
|
try {
|
|
25
24
|
const result = await context.cms.updateGroup(group.group.id, {
|
|
26
25
|
...group.group,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export/crud/imports/importGroups.js","sources":["../../../../src/export/crud/imports/importGroups.ts"],"sourcesContent":["import type { CmsContext } from \"~/types/index.js\";\nimport type { CmsGroupImportResult, ValidCmsGroupResult } from \"~/export/types.js\";\nimport { CmsImportAction } from \"~/export/types.js\";\n\ninterface Params {\n context: CmsContext;\n groups: ValidCmsGroupResult[];\n}\n\nexport const importGroups = async (params: Params) => {\n const { context, groups } = params;\n\n const results: CmsGroupImportResult[] = [];\n for (const group of groups) {\n if (group.action === CmsImportAction.NONE || group.error) {\n results.push({\n action: group.action,\n group: group.group,\n imported: false,\n error: group.error || {\n message: \"No action to be ran on the group.\",\n code: \"NO_ACTION\"\n }\n });\n }\n /**\n * Cannot update if the group is created via plugin.\n */\n if (group.action === CmsImportAction.CODE) {\n results.push({\n action: group.action,\n group: group.group,\n imported: true\n });\n continue;\n }\n /**\n * Update the group.\n */\n //\n else if (group.action === CmsImportAction.UPDATE) {\n try {\n const result = await context.cms.updateGroup(group.group.id, {\n ...group.group,\n icon: group.group.icon ?? undefined,\n description: group.group.description || undefined\n });\n results.push({\n action: group.action,\n group: {\n ...result\n },\n imported: true\n });\n } catch (ex) {\n results.push({\n action: group.action,\n group: group.group,\n imported: false,\n error: {\n message: ex.message,\n code: ex.code || \"UPDATE_GROUP_ERROR\",\n data: {\n ...ex.data,\n group\n }\n }\n });\n }\n continue;\n }\n /**\n * Create the group\n */\n //\n try {\n const result = await context.cms.createGroup(group.group);\n results.push({\n action: group.action,\n group: {\n ...result\n },\n imported: true\n });\n } catch (ex) {\n results.push({\n action: group.action,\n group: group.group,\n imported: false,\n error: {\n message: ex.message,\n code: ex.code || \"CREATE_GROUP_ERROR\",\n data: {\n ...ex.data,\n group\n }\n }\n });\n }\n }\n\n return results;\n};\n"],"names":["importGroups","params","context","groups","results","group","CmsImportAction","result","undefined","ex"],"mappings":";AASO,MAAMA,eAAe,OAAOC;IAC/B,MAAM,EAAEC,OAAO,EAAEC,MAAM,EAAE,GAAGF;IAE5B,MAAMG,UAAkC,EAAE;IAC1C,KAAK,MAAMC,SAASF,OAAQ;QACxB,IAAIE,MAAM,MAAM,KAAKC,gBAAgB,IAAI,IAAID,MAAM,KAAK,EACpDD,QAAQ,IAAI,CAAC;YACT,QAAQC,MAAM,MAAM;YACpB,OAAOA,MAAM,KAAK;YAClB,UAAU;YACV,OAAOA,MAAM,KAAK,IAAI;gBAClB,SAAS;gBACT,MAAM;YACV;QACJ;QAKJ,IAAIA,MAAM,MAAM,KAAKC,gBAAgB,IAAI,EAAE;YACvCF,QAAQ,IAAI,CAAC;gBACT,QAAQC,MAAM,MAAM;gBACpB,OAAOA,MAAM,KAAK;gBAClB,UAAU;YACd;YACA;QACJ
|
|
1
|
+
{"version":3,"file":"export/crud/imports/importGroups.js","sources":["../../../../src/export/crud/imports/importGroups.ts"],"sourcesContent":["import type { CmsContext } from \"~/types/index.js\";\nimport type { CmsGroupImportResult, ValidCmsGroupResult } from \"~/export/types.js\";\nimport { CmsImportAction } from \"~/export/types.js\";\n\ninterface Params {\n context: CmsContext;\n groups: ValidCmsGroupResult[];\n}\n\nexport const importGroups = async (params: Params) => {\n const { context, groups } = params;\n\n const results: CmsGroupImportResult[] = [];\n for (const group of groups) {\n if (group.action === CmsImportAction.NONE || group.error) {\n results.push({\n action: group.action,\n group: group.group,\n imported: false,\n error: group.error || {\n message: \"No action to be ran on the group.\",\n code: \"NO_ACTION\"\n }\n });\n }\n /**\n * Cannot update if the group is created via plugin.\n */\n if (group.action === CmsImportAction.CODE) {\n results.push({\n action: group.action,\n group: group.group,\n imported: true\n });\n continue;\n }\n /**\n * Update the group.\n */\n //\n else if (group.action === CmsImportAction.UPDATE) {\n try {\n const result = await context.cms.updateGroup(group.group.id, {\n ...group.group,\n icon: group.group.icon ?? undefined,\n description: group.group.description || undefined\n });\n results.push({\n action: group.action,\n group: {\n ...result\n },\n imported: true\n });\n } catch (ex) {\n results.push({\n action: group.action,\n group: group.group,\n imported: false,\n error: {\n message: ex.message,\n code: ex.code || \"UPDATE_GROUP_ERROR\",\n data: {\n ...ex.data,\n group\n }\n }\n });\n }\n continue;\n }\n /**\n * Create the group\n */\n //\n try {\n const result = await context.cms.createGroup(group.group);\n results.push({\n action: group.action,\n group: {\n ...result\n },\n imported: true\n });\n } catch (ex) {\n results.push({\n action: group.action,\n group: group.group,\n imported: false,\n error: {\n message: ex.message,\n code: ex.code || \"CREATE_GROUP_ERROR\",\n data: {\n ...ex.data,\n group\n }\n }\n });\n }\n }\n\n return results;\n};\n"],"names":["importGroups","params","context","groups","results","group","CmsImportAction","result","undefined","ex"],"mappings":";AASO,MAAMA,eAAe,OAAOC;IAC/B,MAAM,EAAEC,OAAO,EAAEC,MAAM,EAAE,GAAGF;IAE5B,MAAMG,UAAkC,EAAE;IAC1C,KAAK,MAAMC,SAASF,OAAQ;QACxB,IAAIE,MAAM,MAAM,KAAKC,gBAAgB,IAAI,IAAID,MAAM,KAAK,EACpDD,QAAQ,IAAI,CAAC;YACT,QAAQC,MAAM,MAAM;YACpB,OAAOA,MAAM,KAAK;YAClB,UAAU;YACV,OAAOA,MAAM,KAAK,IAAI;gBAClB,SAAS;gBACT,MAAM;YACV;QACJ;QAKJ,IAAIA,MAAM,MAAM,KAAKC,gBAAgB,IAAI,EAAE;YACvCF,QAAQ,IAAI,CAAC;gBACT,QAAQC,MAAM,MAAM;gBACpB,OAAOA,MAAM,KAAK;gBAClB,UAAU;YACd;YACA;QACJ,OAKK,IAAIA,MAAM,MAAM,KAAKC,gBAAgB,MAAM,EAAE;YAC9C,IAAI;gBACA,MAAMC,SAAS,MAAML,QAAQ,GAAG,CAAC,WAAW,CAACG,MAAM,KAAK,CAAC,EAAE,EAAE;oBACzD,GAAGA,MAAM,KAAK;oBACd,MAAMA,MAAM,KAAK,CAAC,IAAI,IAAIG;oBAC1B,aAAaH,MAAM,KAAK,CAAC,WAAW,IAAIG;gBAC5C;gBACAJ,QAAQ,IAAI,CAAC;oBACT,QAAQC,MAAM,MAAM;oBACpB,OAAO;wBACH,GAAGE,MAAM;oBACb;oBACA,UAAU;gBACd;YACJ,EAAE,OAAOE,IAAI;gBACTL,QAAQ,IAAI,CAAC;oBACT,QAAQC,MAAM,MAAM;oBACpB,OAAOA,MAAM,KAAK;oBAClB,UAAU;oBACV,OAAO;wBACH,SAASI,GAAG,OAAO;wBACnB,MAAMA,GAAG,IAAI,IAAI;wBACjB,MAAM;4BACF,GAAGA,GAAG,IAAI;4BACVJ;wBACJ;oBACJ;gBACJ;YACJ;YACA;QACJ;QAKA,IAAI;YACA,MAAME,SAAS,MAAML,QAAQ,GAAG,CAAC,WAAW,CAACG,MAAM,KAAK;YACxDD,QAAQ,IAAI,CAAC;gBACT,QAAQC,MAAM,MAAM;gBACpB,OAAO;oBACH,GAAGE,MAAM;gBACb;gBACA,UAAU;YACd;QACJ,EAAE,OAAOE,IAAI;YACTL,QAAQ,IAAI,CAAC;gBACT,QAAQC,MAAM,MAAM;gBACpB,OAAOA,MAAM,KAAK;gBAClB,UAAU;gBACV,OAAO;oBACH,SAASI,GAAG,OAAO;oBACnB,MAAMA,GAAG,IAAI,IAAI;oBACjB,MAAM;wBACF,GAAGA,GAAG,IAAI;wBACVJ;oBACJ;gBACJ;YACJ;QACJ;IACJ;IAEA,OAAOD;AACX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export/crud/imports/validateModels.js","sources":["../../../../src/export/crud/imports/validateModels.ts"],"sourcesContent":["import { createModelImportValidation } from \"~/crud/contentModel/validation.js\";\nimport type {\n CmsImportError,\n HeadlessCmsImportStructureParamsDataModel,\n ValidatedCmsModel,\n ValidatedCmsModelResult\n} from \"~/export/types.js\";\nimport { CmsImportAction } from \"~/export/types.js\";\nimport type { CmsDynamicZoneTemplate, CmsGroup, CmsModel, CmsModelField } from \"~/types/index.js\";\nimport { createZodError } from \"@webiny/utils\";\n\ninterface CreateModelValidationParams {\n model: ValidatedCmsModel;\n models: CmsModel[];\n}\n\ninterface AddCodeMessageParams {\n action: CmsImportAction;\n}\n\nconst addCodeMessage = (params: AddCodeMessageParams) => {\n if (params.action !== CmsImportAction.CODE) {\n return params;\n }\n return {\n ...params,\n errors: [\n {\n message: `The model is defined via plugin and it cannot be updated.`,\n code: \"MODEL_IS_A_PLUGIN\"\n }\n ]\n };\n};\n\ninterface ValidationResult {\n errors?: CmsImportError[];\n action: CmsImportAction;\n}\n\nconst validateModel = (params: CreateModelValidationParams): ValidationResult => {\n const { model, models } = params;\n /**\n * Let's check if model values that must be unique, already exist.\n */\n const existingModelId = models.find(\n m => m.modelId.toLowerCase() === model.modelId.toLowerCase()\n );\n const existingSingularApiName = models.find(\n m =>\n m.singularApiName.toLowerCase() === model.singularApiName.toLowerCase() ||\n m.singularApiName.toLowerCase() === model.pluralApiName.toString()\n );\n const existingPluralApiName = models.find(\n m =>\n m.pluralApiName.toLowerCase() === model.pluralApiName.toLowerCase() ||\n m.pluralApiName.toLowerCase() === model.singularApiName.toString()\n );\n\n const UPDATE_KEYWORD = existingModelId?.isPlugin\n ? CmsImportAction.CODE\n : CmsImportAction.UPDATE;\n /**\n * There are few cases that we must address:\n *\n * 1. modelId, singular and plural names do not exist in any of the models\n * - this is OK, we can create the model\n */\n if (!existingModelId && !existingSingularApiName && !existingPluralApiName) {\n return {\n action: CmsImportAction.CREATE\n };\n }\n /**\n * 2. modelId, singular and plural names are a part of a single model\n * - this is OK, we can update the model\n */\n if (\n existingModelId &&\n existingSingularApiName &&\n existingPluralApiName &&\n existingModelId.modelId === existingSingularApiName.modelId &&\n existingModelId.modelId === existingPluralApiName.modelId\n ) {\n return addCodeMessage({\n action: UPDATE_KEYWORD\n });\n }\n /**\n * 3. modelId already exists, but singular and plural names do not\n * - this is OK, we can update the model\n */\n if (existingModelId && !existingSingularApiName && !existingPluralApiName) {\n return addCodeMessage({\n action: UPDATE_KEYWORD\n });\n }\n /**\n * 4. modelId already exists, but only the singular name exists.\n * - this is OK, we can update the model\n */\n if (\n existingModelId &&\n existingSingularApiName?.modelId === existingModelId.modelId &&\n !existingPluralApiName\n ) {\n return addCodeMessage({\n action: UPDATE_KEYWORD\n });\n }\n /**\n * 5. modelId already exists, but only the plural name exists.\n * - this is OK, we can update the model\n */\n if (\n existingModelId &&\n existingPluralApiName?.modelId === existingModelId.modelId &&\n !existingSingularApiName\n ) {\n return addCodeMessage({\n action: UPDATE_KEYWORD\n });\n }\n /**\n * 6. modelId already exists, but singular and plural names are in different models.\n */\n if (\n existingModelId &&\n (existingSingularApiName?.modelId !== existingModelId.modelId ||\n existingPluralApiName?.modelId !== existingModelId.modelId)\n ) {\n return {\n action: CmsImportAction.NONE,\n errors: [\n {\n message: `The model has singular or plural API names same as some other model.`,\n code: \"MODEL_API_NAMES_ERROR\"\n }\n ]\n };\n }\n\n return {\n action: CmsImportAction.NONE,\n errors: [\n {\n message: `The model cannot be imported.`,\n code: \"MODEL_IMPORT_ERROR\",\n data: {\n modelId: existingModelId?.modelId,\n singularApiName: existingSingularApiName?.modelId,\n pluralApiName: existingPluralApiName?.modelId\n }\n }\n ]\n };\n};\n\ninterface InputGroup extends Pick<CmsGroup, \"id\" | \"slug\"> {\n target: string;\n}\n\ninterface Params {\n groups: InputGroup[];\n models: CmsModel[];\n input: HeadlessCmsImportStructureParamsDataModel[];\n}\n\ninterface GetRelatedModelsParams {\n fields: CmsModelField[];\n models: CmsModel[];\n}\n\nconst getRelatedModels = (params: GetRelatedModelsParams): string[] => {\n const { fields, models } = params;\n\n const result: string[] = [];\n for (const field of fields) {\n if (field.type === \"ref\") {\n for (const model of field.settings?.models || []) {\n result.push(model.modelId);\n }\n } else if (field.type === \"object\") {\n result.push(...getRelatedModels({ fields: field.settings?.fields || [], models }));\n } else if (field.type === \"dynamicZone\") {\n const templates = (field.settings?.templates || []) as CmsDynamicZoneTemplate[];\n for (const tpl of templates) {\n result.push(\n ...getRelatedModels({\n fields: tpl.fields || [],\n models\n })\n );\n }\n }\n }\n\n return Array.from(new Set(result));\n};\n\nexport const validateModels = async (params: Params): Promise<ValidatedCmsModelResult[]> => {\n const { groups, models, input } = params;\n\n const validation = createModelImportValidation();\n\n return await Promise.all(\n input.map(async (model): Promise<ValidatedCmsModelResult> => {\n const result = await validation.safeParseAsync(model);\n if (!result.success) {\n const error = createZodError(result.error);\n return {\n model: model as ValidatedCmsModel,\n action: CmsImportAction.NONE,\n error: {\n message: error.message,\n code: error.code,\n data: error.data\n }\n };\n }\n const data = result.data as unknown as ValidatedCmsModel;\n const group = groups.find(g => g.slug === data.group || g.target === data.group);\n if (!group) {\n return {\n model: data,\n action: CmsImportAction.NONE,\n error: {\n message: `The model group \"${data.group}\" does not exist.`,\n code: \"MODEL_GROUP_NOT_FOUND\"\n }\n };\n } else if (!model.fields?.length) {\n return {\n model: data,\n action: CmsImportAction.NONE,\n error: {\n message: `Model is missing fields.`,\n code: \"MODEL_FIELDS_MISSING\"\n }\n };\n }\n\n const targetModel: ValidatedCmsModel = {\n ...data,\n group: group.slug\n };\n\n const modelValidationResult = validateModel({\n model: targetModel,\n models\n });\n\n if (!modelValidationResult.errors?.length) {\n return {\n model: targetModel,\n related: getRelatedModels({\n fields: targetModel.fields,\n models\n }),\n action: modelValidationResult.action\n };\n }\n return {\n model: targetModel,\n action: modelValidationResult.action,\n error: modelValidationResult.errors[0]\n };\n })\n );\n};\n"],"names":["addCodeMessage","params","CmsImportAction","validateModel","model","models","existingModelId","m","existingSingularApiName","existingPluralApiName","UPDATE_KEYWORD","getRelatedModels","fields","result","field","templates","tpl","Array","Set","validateModels","groups","input","validation","createModelImportValidation","Promise","error","createZodError","data","group","g","targetModel","modelValidationResult"],"mappings":";;;AAoBA,MAAMA,iBAAiB,CAACC;IACpB,IAAIA,OAAO,MAAM,KAAKC,gBAAgB,IAAI,EACtC,OAAOD;IAEX,OAAO;QACH,GAAGA,MAAM;QACT,QAAQ;YACJ;gBACI,SAAS;gBACT,MAAM;YACV;SACH;IACL;AACJ;AAOA,MAAME,gBAAgB,CAACF;IACnB,MAAM,EAAEG,KAAK,EAAEC,MAAM,EAAE,GAAGJ;IAI1B,MAAMK,kBAAkBD,OAAO,IAAI,CAC/BE,CAAAA,IAAKA,EAAE,OAAO,CAAC,WAAW,OAAOH,MAAM,OAAO,CAAC,WAAW;IAE9D,MAAMI,0BAA0BH,OAAO,IAAI,CACvCE,CAAAA,IACIA,EAAE,eAAe,CAAC,WAAW,OAAOH,MAAM,eAAe,CAAC,WAAW,MACrEG,EAAE,eAAe,CAAC,WAAW,OAAOH,MAAM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AAIE,EAAE,MAAM,KAAKF,KAAK,KAAK;QAC/E,IAAI,CAACC,OACD,OAAO;YACH,OAAOD;YACP,QAAQzB,gBAAgB,IAAI;YAC5B,OAAO;gBACH,SAAS,CAAC,iBAAiB,EAAEyB,KAAK,KAAK,CAAC,iBAAiB,CAAC;gBAC1D,MAAM;YACV;QACJ;QACG,IAAI,CAACvB,MAAM,MAAM,EAAE,QACtB,OAAO;YACH,OAAOuB;YACP,QAAQzB,gBAAgB,IAAI;YAC5B,OAAO;gBACH,SAAS;gBACT,MAAM;YACV;QACJ;QAGJ,MAAM4B,cAAiC;YACnC,GAAGH,IAAI;YACP,OAAOC,MAAM,IAAI;QACrB;QAEA,MAAMG,wBAAwB5B,cAAc;YACxC,OAAO2B;YACPzB;QACJ;QAEA,IAAI,CAAC0B,sBAAsB,MAAM,EAAE,QAC/B,OAAO;YACH,OAAOD;YACP,SAASnB,iBAAiB;gBACtB,QAAQmB,YAAY,MAAM;gBAC1BzB;YACJ;YACA,QAAQ0B,sBAAsB,MAAM;QACxC;QAEJ,OAAO;YACH,OAAOD;YACP,QAAQC,sBAAsB,MAAM;YACpC,OAAOA,sBAAsB,MAAM,CAAC,EAAE;QAC1C;IACJ;AAER"}
|
|
1
|
+
{"version":3,"file":"export/crud/imports/validateModels.js","sources":["../../../../src/export/crud/imports/validateModels.ts"],"sourcesContent":["import { createModelImportValidation } from \"~/crud/contentModel/validation.js\";\nimport type {\n CmsImportError,\n HeadlessCmsImportStructureParamsDataModel,\n ValidatedCmsModel,\n ValidatedCmsModelResult\n} from \"~/export/types.js\";\nimport { CmsImportAction } from \"~/export/types.js\";\nimport type { CmsDynamicZoneTemplate, CmsGroup, CmsModel, CmsModelField } from \"~/types/index.js\";\nimport { createZodError } from \"@webiny/utils\";\n\ninterface CreateModelValidationParams {\n model: ValidatedCmsModel;\n models: CmsModel[];\n}\n\ninterface AddCodeMessageParams {\n action: CmsImportAction;\n}\n\nconst addCodeMessage = (params: AddCodeMessageParams) => {\n if (params.action !== CmsImportAction.CODE) {\n return params;\n }\n return {\n ...params,\n errors: [\n {\n message: `The model is defined via plugin and it cannot be updated.`,\n code: \"MODEL_IS_A_PLUGIN\"\n }\n ]\n };\n};\n\ninterface ValidationResult {\n errors?: CmsImportError[];\n action: CmsImportAction;\n}\n\nconst validateModel = (params: CreateModelValidationParams): ValidationResult => {\n const { model, models } = params;\n /**\n * Let's check if model values that must be unique, already exist.\n */\n const existingModelId = models.find(\n m => m.modelId.toLowerCase() === model.modelId.toLowerCase()\n );\n const existingSingularApiName = models.find(\n m =>\n m.singularApiName.toLowerCase() === model.singularApiName.toLowerCase() ||\n m.singularApiName.toLowerCase() === model.pluralApiName.toString()\n );\n const existingPluralApiName = models.find(\n m =>\n m.pluralApiName.toLowerCase() === model.pluralApiName.toLowerCase() ||\n m.pluralApiName.toLowerCase() === model.singularApiName.toString()\n );\n\n const UPDATE_KEYWORD = existingModelId?.isPlugin\n ? CmsImportAction.CODE\n : CmsImportAction.UPDATE;\n /**\n * There are few cases that we must address:\n *\n * 1. modelId, singular and plural names do not exist in any of the models\n * - this is OK, we can create the model\n */\n if (!existingModelId && !existingSingularApiName && !existingPluralApiName) {\n return {\n action: CmsImportAction.CREATE\n };\n }\n /**\n * 2. modelId, singular and plural names are a part of a single model\n * - this is OK, we can update the model\n */\n if (\n existingModelId &&\n existingSingularApiName &&\n existingPluralApiName &&\n existingModelId.modelId === existingSingularApiName.modelId &&\n existingModelId.modelId === existingPluralApiName.modelId\n ) {\n return addCodeMessage({\n action: UPDATE_KEYWORD\n });\n }\n /**\n * 3. modelId already exists, but singular and plural names do not\n * - this is OK, we can update the model\n */\n if (existingModelId && !existingSingularApiName && !existingPluralApiName) {\n return addCodeMessage({\n action: UPDATE_KEYWORD\n });\n }\n /**\n * 4. modelId already exists, but only the singular name exists.\n * - this is OK, we can update the model\n */\n if (\n existingModelId &&\n existingSingularApiName?.modelId === existingModelId.modelId &&\n !existingPluralApiName\n ) {\n return addCodeMessage({\n action: UPDATE_KEYWORD\n });\n }\n /**\n * 5. modelId already exists, but only the plural name exists.\n * - this is OK, we can update the model\n */\n if (\n existingModelId &&\n existingPluralApiName?.modelId === existingModelId.modelId &&\n !existingSingularApiName\n ) {\n return addCodeMessage({\n action: UPDATE_KEYWORD\n });\n }\n /**\n * 6. modelId already exists, but singular and plural names are in different models.\n */\n if (\n existingModelId &&\n (existingSingularApiName?.modelId !== existingModelId.modelId ||\n existingPluralApiName?.modelId !== existingModelId.modelId)\n ) {\n return {\n action: CmsImportAction.NONE,\n errors: [\n {\n message: `The model has singular or plural API names same as some other model.`,\n code: \"MODEL_API_NAMES_ERROR\"\n }\n ]\n };\n }\n\n return {\n action: CmsImportAction.NONE,\n errors: [\n {\n message: `The model cannot be imported.`,\n code: \"MODEL_IMPORT_ERROR\",\n data: {\n modelId: existingModelId?.modelId,\n singularApiName: existingSingularApiName?.modelId,\n pluralApiName: existingPluralApiName?.modelId\n }\n }\n ]\n };\n};\n\ninterface InputGroup extends Pick<CmsGroup, \"id\" | \"slug\"> {\n target: string;\n}\n\ninterface Params {\n groups: InputGroup[];\n models: CmsModel[];\n input: HeadlessCmsImportStructureParamsDataModel[];\n}\n\ninterface GetRelatedModelsParams {\n fields: CmsModelField[];\n models: CmsModel[];\n}\n\nconst getRelatedModels = (params: GetRelatedModelsParams): string[] => {\n const { fields, models } = params;\n\n const result: string[] = [];\n for (const field of fields) {\n if (field.type === \"ref\") {\n for (const model of field.settings?.models || []) {\n result.push(model.modelId);\n }\n } else if (field.type === \"object\") {\n result.push(...getRelatedModels({ fields: field.settings?.fields || [], models }));\n } else if (field.type === \"dynamicZone\") {\n const templates = (field.settings?.templates || []) as CmsDynamicZoneTemplate[];\n for (const tpl of templates) {\n result.push(\n ...getRelatedModels({\n fields: tpl.fields || [],\n models\n })\n );\n }\n }\n }\n\n return Array.from(new Set(result));\n};\n\nexport const validateModels = async (params: Params): Promise<ValidatedCmsModelResult[]> => {\n const { groups, models, input } = params;\n\n const validation = createModelImportValidation();\n\n return await Promise.all(\n input.map(async (model): Promise<ValidatedCmsModelResult> => {\n const result = await validation.safeParseAsync(model);\n if (!result.success) {\n const error = createZodError(result.error);\n return {\n model: model as ValidatedCmsModel,\n action: CmsImportAction.NONE,\n error: {\n message: error.message,\n code: error.code,\n data: error.data\n }\n };\n }\n const data = result.data as unknown as ValidatedCmsModel;\n const group = groups.find(g => g.slug === data.group || g.target === data.group);\n if (!group) {\n return {\n model: data,\n action: CmsImportAction.NONE,\n error: {\n message: `The model group \"${data.group}\" does not exist.`,\n code: \"MODEL_GROUP_NOT_FOUND\"\n }\n };\n } else if (!model.fields?.length) {\n return {\n model: data,\n action: CmsImportAction.NONE,\n error: {\n message: `Model is missing fields.`,\n code: \"MODEL_FIELDS_MISSING\"\n }\n };\n }\n\n const targetModel: ValidatedCmsModel = {\n ...data,\n group: group.slug\n };\n\n const modelValidationResult = validateModel({\n model: targetModel,\n models\n });\n\n if (!modelValidationResult.errors?.length) {\n return {\n model: targetModel,\n related: getRelatedModels({\n fields: targetModel.fields,\n models\n }),\n action: modelValidationResult.action\n };\n }\n return {\n model: targetModel,\n action: modelValidationResult.action,\n error: modelValidationResult.errors[0]\n };\n })\n );\n};\n"],"names":["addCodeMessage","params","CmsImportAction","validateModel","model","models","existingModelId","m","existingSingularApiName","existingPluralApiName","UPDATE_KEYWORD","getRelatedModels","fields","result","field","templates","tpl","Array","Set","validateModels","groups","input","validation","createModelImportValidation","Promise","error","createZodError","data","group","g","targetModel","modelValidationResult"],"mappings":";;;AAoBA,MAAMA,iBAAiB,CAACC;IACpB,IAAIA,OAAO,MAAM,KAAKC,gBAAgB,IAAI,EACtC,OAAOD;IAEX,OAAO;QACH,GAAGA,MAAM;QACT,QAAQ;YACJ;gBACI,SAAS;gBACT,MAAM;YACV;SACH;IACL;AACJ;AAOA,MAAME,gBAAgB,CAACF;IACnB,MAAM,EAAEG,KAAK,EAAEC,MAAM,EAAE,GAAGJ;IAI1B,MAAMK,kBAAkBD,OAAO,IAA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B,IAAI;gBAC5B,OAAO;oBACH,SAASuB,MAAM,OAAO;oBACtB,MAAMA,MAAM,IAAI;oBAChB,MAAMA,MAAM,IAAI;gBACpB;YACJ;QACJ;QACA,MAAME,OAAOd,OAAO,IAAI;QACxB,MAAMe,QAAQR,OAAO,IAAI,CAACS,CAAAA,IAAKA,EAAE,IAAI,KAAKF,KAAK,KAAK,IAAIE,EAAE,MAAM,KAAKF,KAAK,KAAK;QAC/E,IAAI,CAACC,OACD,OAAO;YACH,OAAOD;YACP,QAAQzB,gBAAgB,IAAI;YAC5B,OAAO;gBACH,SAAS,CAAC,iBAAiB,EAAEyB,KAAK,KAAK,CAAC,iBAAiB,CAAC;gBAC1D,MAAM;YACV;QACJ;aACG,IAAI,CAACvB,MAAM,MAAM,EAAE,QACtB,OAAO;YACH,OAAOuB;YACP,QAAQzB,gBAAgB,IAAI;YAC5B,OAAO;gBACH,SAAS;gBACT,MAAM;YACV;QACJ;QAGJ,MAAM4B,cAAiC;YACnC,GAAGH,IAAI;YACP,OAAOC,MAAM,IAAI;QACrB;QAEA,MAAMG,wBAAwB5B,cAAc;YACxC,OAAO2B;YACPzB;QACJ;QAEA,IAAI,CAAC0B,sBAAsB,MAAM,EAAE,QAC/B,OAAO;YACH,OAAOD;YACP,SAASnB,iBAAiB;gBACtB,QAAQmB,YAAY,MAAM;gBAC1BzB;YACJ;YACA,QAAQ0B,sBAAsB,MAAM;QACxC;QAEJ,OAAO;YACH,OAAOD;YACP,QAAQC,sBAAsB,MAAM;YACpC,OAAOA,sBAAsB,MAAM,CAAC,EAAE;QAC1C;IACJ;AAER"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const getExpiresAt = (input, original)=>{
|
|
2
2
|
if (void 0 === input.expiresAt) return original?.expiresAt ?? null;
|
|
3
|
-
if (input.expiresAt instanceof Date) return input.expiresAt.getTime() / 1000;
|
|
4
|
-
if ("number" == typeof input.expiresAt && !isNaN(input.expiresAt) && input.expiresAt > 0) return input.expiresAt;
|
|
3
|
+
else if (input.expiresAt instanceof Date) return input.expiresAt.getTime() / 1000;
|
|
4
|
+
else if ("number" == typeof input.expiresAt && !isNaN(input.expiresAt) && input.expiresAt > 0) return input.expiresAt;
|
|
5
5
|
return null;
|
|
6
6
|
};
|
|
7
7
|
export { getExpiresAt };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/entryDataFactories/expiresAt.js","sources":["../../../../src/features/contentEntry/entryDataFactories/expiresAt.ts"],"sourcesContent":["import type { CmsEntry } from \"~/types/index.js\";\n\nexport interface IRawInput {\n expiresAt: Date | number | null | undefined;\n}\n\nexport const getExpiresAt = (input: IRawInput, original?: CmsEntry): number | null => {\n if (input.expiresAt === undefined) {\n return original?.expiresAt ?? null;\n } else if (input.expiresAt instanceof Date) {\n return input.expiresAt.getTime() / 1000;\n } else if (\n typeof input.expiresAt === \"number\" &&\n !isNaN(input.expiresAt) &&\n input.expiresAt > 0\n ) {\n return input.expiresAt;\n }\n return null;\n};\n"],"names":["getExpiresAt","input","original","undefined","Date","isNaN"],"mappings":"AAMO,MAAMA,eAAe,CAACC,OAAkBC;IAC3C,IAAID,AAAoBE,WAApBF,MAAM,SAAS,EACf,OAAOC,UAAU,aAAa;
|
|
1
|
+
{"version":3,"file":"features/contentEntry/entryDataFactories/expiresAt.js","sources":["../../../../src/features/contentEntry/entryDataFactories/expiresAt.ts"],"sourcesContent":["import type { CmsEntry } from \"~/types/index.js\";\n\nexport interface IRawInput {\n expiresAt: Date | number | null | undefined;\n}\n\nexport const getExpiresAt = (input: IRawInput, original?: CmsEntry): number | null => {\n if (input.expiresAt === undefined) {\n return original?.expiresAt ?? null;\n } else if (input.expiresAt instanceof Date) {\n return input.expiresAt.getTime() / 1000;\n } else if (\n typeof input.expiresAt === \"number\" &&\n !isNaN(input.expiresAt) &&\n input.expiresAt > 0\n ) {\n return input.expiresAt;\n }\n return null;\n};\n"],"names":["getExpiresAt","input","original","undefined","Date","isNaN"],"mappings":"AAMO,MAAMA,eAAe,CAACC,OAAkBC;IAC3C,IAAID,AAAoBE,WAApBF,MAAM,SAAS,EACf,OAAOC,UAAU,aAAa;SAC3B,IAAID,MAAM,SAAS,YAAYG,MAClC,OAAOH,MAAM,SAAS,CAAC,OAAO,KAAK;SAChC,IACH,AAA2B,YAA3B,OAAOA,MAAM,SAAS,IACtB,CAACI,MAAMJ,MAAM,SAAS,KACtBA,MAAM,SAAS,GAAG,GAElB,OAAOA,MAAM,SAAS;IAE1B,OAAO;AACX"}
|
|
@@ -21,8 +21,7 @@ const getModelId = (model)=>{
|
|
|
21
21
|
const isModelIdValid = camelCase(value).toLowerCase() === value.toLowerCase();
|
|
22
22
|
if (isModelIdValid) return value;
|
|
23
23
|
return camelCase(value);
|
|
24
|
-
}
|
|
25
|
-
if (name) return camelCase(name.trim());
|
|
24
|
+
} else if (name) return camelCase(name.trim());
|
|
26
25
|
throw new ModelValidationError('There is no "modelId" or "name" passed into the create model method.');
|
|
27
26
|
};
|
|
28
27
|
class CreateModelRepositoryImpl {
|