@strapi/i18n 5.52.0 → 5.52.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server/services/content-types.js +4 -9
- package/dist/server/services/content-types.js.map +1 -1
- package/dist/server/services/content-types.mjs +4 -5
- package/dist/server/services/content-types.mjs.map +1 -1
- package/dist/server/src/index.d.ts +1 -1
- package/dist/server/src/services/content-types.d.ts +2 -1
- package/dist/server/src/services/content-types.d.ts.map +1 -1
- package/dist/server/src/services/index.d.ts +1 -1
- package/package.json +8 -8
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var _ = require('lodash');
|
|
4
3
|
var fp = require('lodash/fp');
|
|
5
4
|
var utils = require('@strapi/utils');
|
|
6
5
|
var index = require('../utils/index.js');
|
|
7
6
|
|
|
8
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
|
|
10
|
-
var ___default = /*#__PURE__*/_interopDefault(_);
|
|
11
|
-
|
|
12
7
|
const { isRelationalAttribute, getVisibleAttributes, isTypedAttribute, getScalarAttributes, getRelationalAttributes } = utils.contentTypes;
|
|
13
8
|
const { ApplicationError } = utils.errors;
|
|
14
9
|
const hasLocalizedOption = (modelOrAttribute)=>{
|
|
@@ -57,7 +52,7 @@ const removeIdsMut = (model, entry)=>{
|
|
|
57
52
|
return entry;
|
|
58
53
|
}
|
|
59
54
|
removeId(entry);
|
|
60
|
-
|
|
55
|
+
for (const [attrName, attr] of Object.entries(model.attributes)){
|
|
61
56
|
const value = entry[attrName];
|
|
62
57
|
if (attr.type === 'dynamiczone' && fp.isArray(value)) {
|
|
63
58
|
value.forEach((compo)=>{
|
|
@@ -74,7 +69,7 @@ const removeIdsMut = (model, entry)=>{
|
|
|
74
69
|
removeIdsMut(model, value);
|
|
75
70
|
}
|
|
76
71
|
}
|
|
77
|
-
}
|
|
72
|
+
}
|
|
78
73
|
return entry;
|
|
79
74
|
};
|
|
80
75
|
/**
|
|
@@ -105,11 +100,11 @@ const removeIdsMut = (model, entry)=>{
|
|
|
105
100
|
}
|
|
106
101
|
const modelDef = strapi.getModel(model);
|
|
107
102
|
const relatedEntryCopy = copyNonLocalizedAttributes(modelDef, relatedEntry);
|
|
108
|
-
|
|
103
|
+
for (const [field, value] of Object.entries(relatedEntryCopy)){
|
|
109
104
|
if (fp.isNil(entry[field])) {
|
|
110
105
|
entry[field] = value;
|
|
111
106
|
}
|
|
112
|
-
}
|
|
107
|
+
}
|
|
113
108
|
};
|
|
114
109
|
/**
|
|
115
110
|
* build the populate param to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-types.js","sources":["../../../server/src/services/content-types.ts"],"sourcesContent":["import _ from 'lodash';\nimport { pick, pipe, has, prop, isNil, cloneDeep, isArray } from 'lodash/fp';\nimport { errors, contentTypes as contentTypeUtils } from '@strapi/utils';\nimport { getService } from '../utils';\n\nconst {\n isRelationalAttribute,\n getVisibleAttributes,\n isTypedAttribute,\n getScalarAttributes,\n getRelationalAttributes,\n} = contentTypeUtils;\nconst { ApplicationError } = errors;\n\nconst hasLocalizedOption = (modelOrAttribute: any) => {\n return prop('pluginOptions.i18n.localized', modelOrAttribute) === true;\n};\n\nconst getValidLocale = async (locale: any) => {\n const localesService = getService('locales');\n\n if (isNil(locale)) {\n return localesService.getDefaultLocale();\n }\n\n const foundLocale = await localesService.findByCode(locale);\n if (!foundLocale) {\n throw new ApplicationError('Locale not found');\n }\n\n return locale;\n};\n\n/**\n * Returns whether an attribute is localized or not\n * @param {*} attribute\n * @returns\n */\nconst isLocalizedAttribute = (attribute: any) => {\n return (\n hasLocalizedOption(attribute) ||\n isRelationalAttribute(attribute) ||\n isTypedAttribute(attribute, 'uid')\n );\n};\n\n/**\n * Returns whether a model is localized or not\n * @param {*} model\n * @returns\n */\nconst isLocalizedContentType = (model: any) => {\n return hasLocalizedOption(model);\n};\n\n/**\n * Returns the list of attribute names that are not localized\n * @param {object} model\n * @returns {string[]}\n */\nconst getNonLocalizedAttributes = (model: any) => {\n return getVisibleAttributes(model).filter(\n (attrName) => !isLocalizedAttribute(model.attributes[attrName])\n );\n};\n\nconst removeId = (value: any) => {\n if (typeof value === 'object' && has('id', value)) {\n delete value.id;\n }\n};\n\nconst removeIds = (model: any) => (entry: any) => removeIdsMut(model, cloneDeep(entry));\n\nconst removeIdsMut = (model: any, entry: any): Record<string, any> => {\n if (isNil(entry)) {\n return entry as unknown as Record<string, any>;\n }\n\n removeId(entry);\n\n _.forEach(model.attributes, (attr, attrName) => {\n const value = entry[attrName];\n if (attr.type === 'dynamiczone' && isArray(value)) {\n value.forEach((compo) => {\n if (has('__component', compo)) {\n const model = strapi.components[compo.__component];\n removeIdsMut(model, compo);\n }\n });\n } else if (attr.type === 'component') {\n const model = strapi.components[attr.component];\n if (isArray(value)) {\n value.forEach((compo) => removeIdsMut(model, compo));\n } else {\n removeIdsMut(model, value);\n }\n }\n });\n\n return entry;\n};\n\n/**\n * Returns a copy of an entry picking only its non localized attributes\n * @param {object} model\n * @param {object} entry\n * @returns {object}\n */\nconst copyNonLocalizedAttributes = (model: any, entry: any) => {\n const nonLocalizedAttributes = getNonLocalizedAttributes(model);\n\n return pipe(pick(nonLocalizedAttributes), removeIds(model))(entry);\n};\n\n/**\n * Returns the list of attribute names that are localized\n * @param {object} model\n * @returns {string[]}\n */\nconst getLocalizedAttributes = (model: any) => {\n return getVisibleAttributes(model).filter((attrName) =>\n isLocalizedAttribute(model.attributes[attrName])\n );\n};\n\n/**\n * Fill non localized fields of an entry if there are nil\n * @param {Object} entry entry to fill\n * @param {Object} relatedEntry values used to fill\n * @param {Object} options\n * @param {Object} options.model corresponding model\n */\nconst fillNonLocalizedAttributes = (entry: any, relatedEntry: any, { model }: any) => {\n if (isNil(relatedEntry)) {\n return;\n }\n\n const modelDef = strapi.getModel(model);\n const relatedEntryCopy = copyNonLocalizedAttributes(modelDef, relatedEntry);\n\n _.forEach(relatedEntryCopy, (value, field) => {\n if (isNil(entry[field])) {\n entry[field] = value;\n }\n });\n};\n\n/**\n * build the populate param to\n * @param {String} modelUID uid of the model, could be of a content-type or a component\n */\nconst getNestedPopulateOfNonLocalizedAttributes = (modelUID: any): string[] => {\n const schema = strapi.getModel(modelUID);\n const scalarAttributes = getScalarAttributes(schema);\n const nonLocalizedAttributes = getNonLocalizedAttributes(schema);\n\n const allAttributes = [...scalarAttributes, ...nonLocalizedAttributes];\n if (schema.modelType === 'component') {\n // When called recursively on a non localized component we\n // need to explicitly populate that components relations\n allAttributes.push(...getRelationalAttributes(schema));\n }\n\n const currentAttributesToPopulate = allAttributes.filter((value, index, self) => {\n return self.indexOf(value) === index && self.lastIndexOf(value) === index;\n });\n\n const attributesToPopulate = [...currentAttributesToPopulate];\n for (const attrName of currentAttributesToPopulate) {\n const attr = schema.attributes[attrName];\n if (attr.type === 'component') {\n const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(attr.component).map(\n (nestedAttr) => `${attrName}.${nestedAttr}`\n );\n attributesToPopulate.push(...nestedPopulate);\n } else if (attr.type === 'dynamiczone') {\n attr.components.forEach((componentName) => {\n const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(componentName).map(\n (nestedAttr) => `${attrName}.${nestedAttr}`\n );\n attributesToPopulate.push(...nestedPopulate);\n });\n }\n }\n\n return attributesToPopulate;\n};\n\nconst contentTypes = () => ({\n isLocalizedContentType,\n getValidLocale,\n getLocalizedAttributes,\n getNonLocalizedAttributes,\n copyNonLocalizedAttributes,\n fillNonLocalizedAttributes,\n getNestedPopulateOfNonLocalizedAttributes,\n});\n\ntype ContentTypesService = typeof contentTypes;\n\nexport default contentTypes;\nexport { ContentTypesService };\n"],"names":["isRelationalAttribute","getVisibleAttributes","isTypedAttribute","getScalarAttributes","getRelationalAttributes","contentTypeUtils","ApplicationError","errors","hasLocalizedOption","modelOrAttribute","prop","getValidLocale","locale","localesService","getService","isNil","getDefaultLocale","foundLocale","findByCode","isLocalizedAttribute","attribute","isLocalizedContentType","model","getNonLocalizedAttributes","filter","attrName","attributes","removeId","value","has","id","removeIds","entry","removeIdsMut","cloneDeep","_","forEach","attr","type","isArray","compo","strapi","components","__component","component","copyNonLocalizedAttributes","nonLocalizedAttributes","pipe","pick","getLocalizedAttributes","fillNonLocalizedAttributes","relatedEntry","modelDef","getModel","relatedEntryCopy","field","getNestedPopulateOfNonLocalizedAttributes","modelUID","schema","scalarAttributes","allAttributes","modelType","push","currentAttributesToPopulate","index","self","indexOf","lastIndexOf","attributesToPopulate","nestedPopulate","map","nestedAttr","componentName","contentTypes"],"mappings":";;;;;;;;;;;AAKA,MAAM,EACJA,qBAAqB,EACrBC,oBAAoB,EACpBC,gBAAgB,EAChBC,mBAAmB,EACnBC,uBAAuB,EACxB,GAAGC,kBAAAA;AACJ,MAAM,EAAEC,gBAAgB,EAAE,GAAGC,YAAAA;AAE7B,MAAMC,qBAAqB,CAACC,gBAAAA,GAAAA;IAC1B,OAAOC,OAAAA,CAAK,gCAAgCD,gBAAAA,CAAAA,KAAsB,IAAA;AACpE,CAAA;AAEA,MAAME,iBAAiB,OAAOC,MAAAA,GAAAA;AAC5B,IAAA,MAAMC,iBAAiBC,gBAAAA,CAAW,SAAA,CAAA;AAElC,IAAA,IAAIC,SAAMH,MAAAA,CAAAA,EAAS;AACjB,QAAA,OAAOC,eAAeG,gBAAgB,EAAA;AACxC,IAAA;AAEA,IAAA,MAAMC,WAAAA,GAAc,MAAMJ,cAAAA,CAAeK,UAAU,CAACN,MAAAA,CAAAA;AACpD,IAAA,IAAI,CAACK,WAAAA,EAAa;AAChB,QAAA,MAAM,IAAIX,gBAAAA,CAAiB,kBAAA,CAAA;AAC7B,IAAA;IAEA,OAAOM,MAAAA;AACT,CAAA;AAEA;;;;IAKA,MAAMO,uBAAuB,CAACC,SAAAA,GAAAA;AAC5B,IAAA,OACEZ,kBAAAA,CAAmBY,SAAAA,CAAAA,IACnBpB,qBAAAA,CAAsBoB,SAAAA,CAAAA,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":["import { pick, pipe, has, prop, isNil, cloneDeep, isArray } from 'lodash/fp';\nimport { errors, contentTypes as contentTypeUtils } from '@strapi/utils';\nimport type { Struct } from '@strapi/types';\nimport { getService } from '../utils';\n\nconst {\n isRelationalAttribute,\n getVisibleAttributes,\n isTypedAttribute,\n getScalarAttributes,\n getRelationalAttributes,\n} = contentTypeUtils;\nconst { ApplicationError } = errors;\n\nconst hasLocalizedOption = (modelOrAttribute: any) => {\n return prop('pluginOptions.i18n.localized', modelOrAttribute) === true;\n};\n\nconst getValidLocale = async (locale: any) => {\n const localesService = getService('locales');\n\n if (isNil(locale)) {\n return localesService.getDefaultLocale();\n }\n\n const foundLocale = await localesService.findByCode(locale);\n if (!foundLocale) {\n throw new ApplicationError('Locale not found');\n }\n\n return locale;\n};\n\n/**\n * Returns whether an attribute is localized or not\n * @param {*} attribute\n * @returns\n */\nconst isLocalizedAttribute = (attribute: any) => {\n return (\n hasLocalizedOption(attribute) ||\n isRelationalAttribute(attribute) ||\n isTypedAttribute(attribute, 'uid')\n );\n};\n\n/**\n * Returns whether a model is localized or not\n * @param {*} model\n * @returns\n */\nconst isLocalizedContentType = (model: any) => {\n return hasLocalizedOption(model);\n};\n\n/**\n * Returns the list of attribute names that are not localized\n * @param {object} model\n * @returns {string[]}\n */\nconst getNonLocalizedAttributes = (model: any) => {\n return getVisibleAttributes(model).filter(\n (attrName) => !isLocalizedAttribute(model.attributes[attrName])\n );\n};\n\nconst removeId = (value: any) => {\n if (typeof value === 'object' && has('id', value)) {\n delete value.id;\n }\n};\n\nconst removeIds = (model: Struct.ComponentSchema | Struct.ContentTypeSchema) => (entry: any) =>\n removeIdsMut(model, cloneDeep(entry));\n\nconst removeIdsMut = (\n model: Struct.ComponentSchema | Struct.ContentTypeSchema,\n entry: any\n): Record<string, any> => {\n if (isNil(entry)) {\n return entry as unknown as Record<string, any>;\n }\n\n removeId(entry);\n\n for (const [attrName, attr] of Object.entries(model.attributes)) {\n const value = entry[attrName];\n if (attr.type === 'dynamiczone' && isArray(value)) {\n value.forEach((compo) => {\n if (has('__component', compo)) {\n const model = strapi.components[compo.__component];\n removeIdsMut(model, compo);\n }\n });\n } else if (attr.type === 'component') {\n const model = strapi.components[attr.component];\n if (isArray(value)) {\n value.forEach((compo) => removeIdsMut(model, compo));\n } else {\n removeIdsMut(model, value);\n }\n }\n }\n\n return entry;\n};\n\n/**\n * Returns a copy of an entry picking only its non localized attributes\n * @param {object} model\n * @param {object} entry\n * @returns {object}\n */\nconst copyNonLocalizedAttributes = (\n model: Struct.ComponentSchema | Struct.ContentTypeSchema,\n entry: any\n) => {\n const nonLocalizedAttributes = getNonLocalizedAttributes(model);\n\n return pipe(pick(nonLocalizedAttributes), removeIds(model))(entry);\n};\n\n/**\n * Returns the list of attribute names that are localized\n * @param {object} model\n * @returns {string[]}\n */\nconst getLocalizedAttributes = (model: any) => {\n return getVisibleAttributes(model).filter((attrName) =>\n isLocalizedAttribute(model.attributes[attrName])\n );\n};\n\n/**\n * Fill non localized fields of an entry if there are nil\n * @param {Object} entry entry to fill\n * @param {Object} relatedEntry values used to fill\n * @param {Object} options\n * @param {Object} options.model corresponding model\n */\nconst fillNonLocalizedAttributes = (entry: any, relatedEntry: any, { model }: any) => {\n if (isNil(relatedEntry)) {\n return;\n }\n\n const modelDef = strapi.getModel(model);\n const relatedEntryCopy = copyNonLocalizedAttributes(modelDef, relatedEntry);\n\n for (const [field, value] of Object.entries(relatedEntryCopy)) {\n if (isNil(entry[field])) {\n entry[field] = value;\n }\n }\n};\n\n/**\n * build the populate param to\n * @param {String} modelUID uid of the model, could be of a content-type or a component\n */\nconst getNestedPopulateOfNonLocalizedAttributes = (modelUID: any): string[] => {\n const schema = strapi.getModel(modelUID);\n const scalarAttributes = getScalarAttributes(schema);\n const nonLocalizedAttributes = getNonLocalizedAttributes(schema);\n\n const allAttributes = [...scalarAttributes, ...nonLocalizedAttributes];\n if (schema.modelType === 'component') {\n // When called recursively on a non localized component we\n // need to explicitly populate that components relations\n allAttributes.push(...getRelationalAttributes(schema));\n }\n\n const currentAttributesToPopulate = allAttributes.filter((value, index, self) => {\n return self.indexOf(value) === index && self.lastIndexOf(value) === index;\n });\n\n const attributesToPopulate = [...currentAttributesToPopulate];\n for (const attrName of currentAttributesToPopulate) {\n const attr = schema.attributes[attrName];\n if (attr.type === 'component') {\n const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(attr.component).map(\n (nestedAttr) => `${attrName}.${nestedAttr}`\n );\n attributesToPopulate.push(...nestedPopulate);\n } else if (attr.type === 'dynamiczone') {\n attr.components.forEach((componentName) => {\n const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(componentName).map(\n (nestedAttr) => `${attrName}.${nestedAttr}`\n );\n attributesToPopulate.push(...nestedPopulate);\n });\n }\n }\n\n return attributesToPopulate;\n};\n\nconst contentTypes = () => ({\n isLocalizedContentType,\n getValidLocale,\n getLocalizedAttributes,\n getNonLocalizedAttributes,\n copyNonLocalizedAttributes,\n fillNonLocalizedAttributes,\n getNestedPopulateOfNonLocalizedAttributes,\n});\n\ntype ContentTypesService = typeof contentTypes;\n\nexport default contentTypes;\nexport { ContentTypesService };\n"],"names":["isRelationalAttribute","getVisibleAttributes","isTypedAttribute","getScalarAttributes","getRelationalAttributes","contentTypeUtils","ApplicationError","errors","hasLocalizedOption","modelOrAttribute","prop","getValidLocale","locale","localesService","getService","isNil","getDefaultLocale","foundLocale","findByCode","isLocalizedAttribute","attribute","isLocalizedContentType","model","getNonLocalizedAttributes","filter","attrName","attributes","removeId","value","has","id","removeIds","entry","removeIdsMut","cloneDeep","attr","Object","entries","type","isArray","forEach","compo","strapi","components","__component","component","copyNonLocalizedAttributes","nonLocalizedAttributes","pipe","pick","getLocalizedAttributes","fillNonLocalizedAttributes","relatedEntry","modelDef","getModel","relatedEntryCopy","field","getNestedPopulateOfNonLocalizedAttributes","modelUID","schema","scalarAttributes","allAttributes","modelType","push","currentAttributesToPopulate","index","self","indexOf","lastIndexOf","attributesToPopulate","nestedPopul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F,CAACC,UAAAA,GAAe,CAAA,EAAG/C,QAAAA,CAAS,CAAC,EAAE+C,UAAAA,CAAAA,CAAY,CAAA;AAE7CH,YAAAA,oBAAAA,CAAqBN,IAAI,CAAA,GAAIO,cAAAA,CAAAA;AAC/B,QAAA,CAAA,MAAO,IAAInC,IAAAA,CAAKG,IAAI,KAAK,aAAA,EAAe;AACtCH,YAAAA,IAAAA,CAAKQ,UAAU,CAACH,OAAO,CAAC,CAACiC,aAAAA,GAAAA;gBACvB,MAAMH,cAAAA,GAAiBb,yCAAAA,CAA0CgB,aAAAA,CAAAA,CAAeF,GAAG,CACjF,CAACC,UAAAA,GAAe,CAAA,EAAG/C,QAAAA,CAAS,CAAC,EAAE+C,UAAAA,CAAAA,CAAY,CAAA;AAE7CH,gBAAAA,oBAAAA,CAAqBN,IAAI,CAAA,GAAIO,cAAAA,CAAAA;AAC/B,YAAA,CAAA,CAAA;AACF,QAAA;AACF,IAAA;IAEA,OAAOD,oBAAAA;AACT,CAAA;AAEA,MAAMK,YAAAA,GAAe,KAAO;AAC1BrD,QAAAA,sBAAAA;AACAV,QAAAA,cAAAA;AACAuC,QAAAA,sBAAAA;AACA3B,QAAAA,yBAAAA;AACAuB,QAAAA,0BAAAA;AACAK,QAAAA,0BAAAA;AACAM,QAAAA;KACF;;;;"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
1
|
import { isNil, pipe, pick, cloneDeep, prop, isArray, has } from 'lodash/fp';
|
|
3
2
|
import { contentTypes as contentTypes$1, errors } from '@strapi/utils';
|
|
4
3
|
import { getService } from '../utils/index.mjs';
|
|
@@ -51,7 +50,7 @@ const removeIdsMut = (model, entry)=>{
|
|
|
51
50
|
return entry;
|
|
52
51
|
}
|
|
53
52
|
removeId(entry);
|
|
54
|
-
|
|
53
|
+
for (const [attrName, attr] of Object.entries(model.attributes)){
|
|
55
54
|
const value = entry[attrName];
|
|
56
55
|
if (attr.type === 'dynamiczone' && isArray(value)) {
|
|
57
56
|
value.forEach((compo)=>{
|
|
@@ -68,7 +67,7 @@ const removeIdsMut = (model, entry)=>{
|
|
|
68
67
|
removeIdsMut(model, value);
|
|
69
68
|
}
|
|
70
69
|
}
|
|
71
|
-
}
|
|
70
|
+
}
|
|
72
71
|
return entry;
|
|
73
72
|
};
|
|
74
73
|
/**
|
|
@@ -99,11 +98,11 @@ const removeIdsMut = (model, entry)=>{
|
|
|
99
98
|
}
|
|
100
99
|
const modelDef = strapi.getModel(model);
|
|
101
100
|
const relatedEntryCopy = copyNonLocalizedAttributes(modelDef, relatedEntry);
|
|
102
|
-
|
|
101
|
+
for (const [field, value] of Object.entries(relatedEntryCopy)){
|
|
103
102
|
if (isNil(entry[field])) {
|
|
104
103
|
entry[field] = value;
|
|
105
104
|
}
|
|
106
|
-
}
|
|
105
|
+
}
|
|
107
106
|
};
|
|
108
107
|
/**
|
|
109
108
|
* build the populate param to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-types.mjs","sources":["../../../server/src/services/content-types.ts"],"sourcesContent":["import _ from 'lodash';\nimport { pick, pipe, has, prop, isNil, cloneDeep, isArray } from 'lodash/fp';\nimport { errors, contentTypes as contentTypeUtils } from '@strapi/utils';\nimport { getService } from '../utils';\n\nconst {\n isRelationalAttribute,\n getVisibleAttributes,\n isTypedAttribute,\n getScalarAttributes,\n getRelationalAttributes,\n} = contentTypeUtils;\nconst { ApplicationError } = errors;\n\nconst hasLocalizedOption = (modelOrAttribute: any) => {\n return prop('pluginOptions.i18n.localized', modelOrAttribute) === true;\n};\n\nconst getValidLocale = async (locale: any) => {\n const localesService = getService('locales');\n\n if (isNil(locale)) {\n return localesService.getDefaultLocale();\n }\n\n const foundLocale = await localesService.findByCode(locale);\n if (!foundLocale) {\n throw new ApplicationError('Locale not found');\n }\n\n return locale;\n};\n\n/**\n * Returns whether an attribute is localized or not\n * @param {*} attribute\n * @returns\n */\nconst isLocalizedAttribute = (attribute: any) => {\n return (\n hasLocalizedOption(attribute) ||\n isRelationalAttribute(attribute) ||\n isTypedAttribute(attribute, 'uid')\n );\n};\n\n/**\n * Returns whether a model is localized or not\n * @param {*} model\n * @returns\n */\nconst isLocalizedContentType = (model: any) => {\n return hasLocalizedOption(model);\n};\n\n/**\n * Returns the list of attribute names that are not localized\n * @param {object} model\n * @returns {string[]}\n */\nconst getNonLocalizedAttributes = (model: any) => {\n return getVisibleAttributes(model).filter(\n (attrName) => !isLocalizedAttribute(model.attributes[attrName])\n );\n};\n\nconst removeId = (value: any) => {\n if (typeof value === 'object' && has('id', value)) {\n delete value.id;\n }\n};\n\nconst removeIds = (model: any) => (entry: any) => removeIdsMut(model, cloneDeep(entry));\n\nconst removeIdsMut = (model: any, entry: any): Record<string, any> => {\n if (isNil(entry)) {\n return entry as unknown as Record<string, any>;\n }\n\n removeId(entry);\n\n _.forEach(model.attributes, (attr, attrName) => {\n const value = entry[attrName];\n if (attr.type === 'dynamiczone' && isArray(value)) {\n value.forEach((compo) => {\n if (has('__component', compo)) {\n const model = strapi.components[compo.__component];\n removeIdsMut(model, compo);\n }\n });\n } else if (attr.type === 'component') {\n const model = strapi.components[attr.component];\n if (isArray(value)) {\n value.forEach((compo) => removeIdsMut(model, compo));\n } else {\n removeIdsMut(model, value);\n }\n }\n });\n\n return entry;\n};\n\n/**\n * Returns a copy of an entry picking only its non localized attributes\n * @param {object} model\n * @param {object} entry\n * @returns {object}\n */\nconst copyNonLocalizedAttributes = (model: any, entry: any) => {\n const nonLocalizedAttributes = getNonLocalizedAttributes(model);\n\n return pipe(pick(nonLocalizedAttributes), removeIds(model))(entry);\n};\n\n/**\n * Returns the list of attribute names that are localized\n * @param {object} model\n * @returns {string[]}\n */\nconst getLocalizedAttributes = (model: any) => {\n return getVisibleAttributes(model).filter((attrName) =>\n isLocalizedAttribute(model.attributes[attrName])\n );\n};\n\n/**\n * Fill non localized fields of an entry if there are nil\n * @param {Object} entry entry to fill\n * @param {Object} relatedEntry values used to fill\n * @param {Object} options\n * @param {Object} options.model corresponding model\n */\nconst fillNonLocalizedAttributes = (entry: any, relatedEntry: any, { model }: any) => {\n if (isNil(relatedEntry)) {\n return;\n }\n\n const modelDef = strapi.getModel(model);\n const relatedEntryCopy = copyNonLocalizedAttributes(modelDef, relatedEntry);\n\n _.forEach(relatedEntryCopy, (value, field) => {\n if (isNil(entry[field])) {\n entry[field] = value;\n }\n });\n};\n\n/**\n * build the populate param to\n * @param {String} modelUID uid of the model, could be of a content-type or a component\n */\nconst getNestedPopulateOfNonLocalizedAttributes = (modelUID: any): string[] => {\n const schema = strapi.getModel(modelUID);\n const scalarAttributes = getScalarAttributes(schema);\n const nonLocalizedAttributes = getNonLocalizedAttributes(schema);\n\n const allAttributes = [...scalarAttributes, ...nonLocalizedAttributes];\n if (schema.modelType === 'component') {\n // When called recursively on a non localized component we\n // need to explicitly populate that components relations\n allAttributes.push(...getRelationalAttributes(schema));\n }\n\n const currentAttributesToPopulate = allAttributes.filter((value, index, self) => {\n return self.indexOf(value) === index && self.lastIndexOf(value) === index;\n });\n\n const attributesToPopulate = [...currentAttributesToPopulate];\n for (const attrName of currentAttributesToPopulate) {\n const attr = schema.attributes[attrName];\n if (attr.type === 'component') {\n const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(attr.component).map(\n (nestedAttr) => `${attrName}.${nestedAttr}`\n );\n attributesToPopulate.push(...nestedPopulate);\n } else if (attr.type === 'dynamiczone') {\n attr.components.forEach((componentName) => {\n const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(componentName).map(\n (nestedAttr) => `${attrName}.${nestedAttr}`\n );\n attributesToPopulate.push(...nestedPopulate);\n });\n }\n }\n\n return attributesToPopulate;\n};\n\nconst contentTypes = () => ({\n isLocalizedContentType,\n getValidLocale,\n getLocalizedAttributes,\n getNonLocalizedAttributes,\n copyNonLocalizedAttributes,\n fillNonLocalizedAttributes,\n getNestedPopulateOfNonLocalizedAttributes,\n});\n\ntype ContentTypesService = typeof contentTypes;\n\nexport default contentTypes;\nexport { ContentTypesService };\n"],"names":["isRelationalAttribute","getVisibleAttributes","isTypedAttribute","getScalarAttributes","getRelationalAttributes","contentTypeUtils","ApplicationError","errors","hasLocalizedOption","modelOrAttribute","prop","getValidLocale","locale","localesService","getService","isNil","getDefaultLocale","foundLocale","findByCode","isLocalizedAttribute","attribute","isLocalizedContentType","model","getNonLocalizedAttributes","filter","attrName","attributes","removeId","value","has","id","removeIds","entry","removeIdsMut","cloneDeep","_","forEach","attr","type","isArray","compo","strapi","components","__component","component","copyNonLocalizedAttributes","nonLocalizedAttributes","pipe","pick","getLocalizedAttributes","fillNonLocalizedAttributes","relatedEntry","modelDef","getModel","relatedEntryCopy","field","getNestedPopulateOfNonLocalizedAttributes","modelUID","schema","scalarAttributes","allAttributes","modelType","push","currentAttributesToPopulate","index","self","indexOf","lastIndexOf","attributesToPopulate","nestedPopulate","map","nestedAttr","componentName","contentTypes"],"mappings":";;;;;AAKA,MAAM,EACJA,qBAAqB,EACrBC,oBAAoB,EACpBC,gBAAgB,EAChBC,mBAAmB,EACnBC,uBAAuB,EACxB,GAAGC,cAAAA;AACJ,MAAM,EAAEC,gBAAgB,EAAE,GAAGC,MAAAA;AAE7B,MAAMC,qBAAqB,CAACC,gBAAAA,GAAAA;IAC1B,OAAOC,IAAAA,CAAK,gCAAgCD,gBAAAA,CAAAA,KAAsB,IAAA;AACpE,CAAA;AAEA,MAAME,iBAAiB,OAAOC,MAAAA,GAAAA;AAC5B,IAAA,MAAMC,iBAAiBC,UAAAA,CAAW,SAAA,CAAA;AAElC,IAAA,IAAIC,MAAMH,MAAAA,CAAAA,EAAS;AACjB,QAAA,OAAOC,eAAeG,gBAAgB,EAAA;AACxC,IAAA;AAEA,IAAA,MAAMC,WAAAA,GAAc,MAAMJ,cAAAA,CAAeK,UAAU,CAACN,MAAAA,CAAAA;AACpD,IAAA,IAAI,CAACK,WAAAA,EAAa;AAChB,QAAA,MAAM,IAAIX,gBAAAA,CAAiB,kBAAA,CAAA;AAC7B,IA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sC,QAAAA,sBAAAA;AACA1B,QAAAA,yBAAAA;AACAsB,QAAAA,0BAAAA;AACAK,QAAAA,0BAAAA;AACAM,QAAAA;KACF;;;;"}
|
|
1
|
+
{"version":3,"file":"content-types.mjs","sources":["../../../server/src/services/content-types.ts"],"sourcesContent":["import { pick, pipe, has, prop, isNil, cloneDeep, isArray } from 'lodash/fp';\nimport { errors, contentTypes as contentTypeUtils } from '@strapi/utils';\nimport type { Struct } from '@strapi/types';\nimport { getService } from '../utils';\n\nconst {\n isRelationalAttribute,\n getVisibleAttributes,\n isTypedAttribute,\n getScalarAttributes,\n getRelationalAttributes,\n} = contentTypeUtils;\nconst { ApplicationError } = errors;\n\nconst hasLocalizedOption = (modelOrAttribute: any) => {\n return prop('pluginOptions.i18n.localized', modelOrAttribute) === true;\n};\n\nconst getValidLocale = async (locale: any) => {\n const localesService = getService('locales');\n\n if (isNil(locale)) {\n return localesService.getDefaultLocale();\n }\n\n const foundLocale = await localesService.findByCode(locale);\n if (!foundLocale) {\n throw new ApplicationError('Locale not found');\n }\n\n return locale;\n};\n\n/**\n * Returns whether an attribute is localized or not\n * @param {*} attribute\n * @returns\n */\nconst isLocalizedAttribute = (attribute: any) => {\n return (\n hasLocalizedOption(attribute) ||\n isRelationalAttribute(attribute) ||\n isTypedAttribute(attribute, 'uid')\n );\n};\n\n/**\n * Returns whether a model is localized or not\n * @param {*} model\n * @returns\n */\nconst isLocalizedContentType = (model: any) => {\n return hasLocalizedOption(model);\n};\n\n/**\n * Returns the list of attribute names that are not localized\n * @param {object} model\n * @returns {string[]}\n */\nconst getNonLocalizedAttributes = (model: any) => {\n return getVisibleAttributes(model).filter(\n (attrName) => !isLocalizedAttribute(model.attributes[attrName])\n );\n};\n\nconst removeId = (value: any) => {\n if (typeof value === 'object' && has('id', value)) {\n delete value.id;\n }\n};\n\nconst removeIds = (model: Struct.ComponentSchema | Struct.ContentTypeSchema) => (entry: any) =>\n removeIdsMut(model, cloneDeep(entry));\n\nconst removeIdsMut = (\n model: Struct.ComponentSchema | Struct.ContentTypeSchema,\n entry: any\n): Record<string, any> => {\n if (isNil(entry)) {\n return entry as unknown as Record<string, any>;\n }\n\n removeId(entry);\n\n for (const [attrName, attr] of Object.entries(model.attributes)) {\n const value = entry[attrName];\n if (attr.type === 'dynamiczone' && isArray(value)) {\n value.forEach((compo) => {\n if (has('__component', compo)) {\n const model = strapi.components[compo.__component];\n removeIdsMut(model, compo);\n }\n });\n } else if (attr.type === 'component') {\n const model = strapi.components[attr.component];\n if (isArray(value)) {\n value.forEach((compo) => removeIdsMut(model, compo));\n } else {\n removeIdsMut(model, value);\n }\n }\n }\n\n return entry;\n};\n\n/**\n * Returns a copy of an entry picking only its non localized attributes\n * @param {object} model\n * @param {object} entry\n * @returns {object}\n */\nconst copyNonLocalizedAttributes = (\n model: Struct.ComponentSchema | Struct.ContentTypeSchema,\n entry: any\n) => {\n const nonLocalizedAttributes = getNonLocalizedAttributes(model);\n\n return pipe(pick(nonLocalizedAttributes), removeIds(model))(entry);\n};\n\n/**\n * Returns the list of attribute names that are localized\n * @param {object} model\n * @returns {string[]}\n */\nconst getLocalizedAttributes = (model: any) => {\n return getVisibleAttributes(model).filter((attrName) =>\n isLocalizedAttribute(model.attributes[attrName])\n );\n};\n\n/**\n * Fill non localized fields of an entry if there are nil\n * @param {Object} entry entry to fill\n * @param {Object} relatedEntry values used to fill\n * @param {Object} options\n * @param {Object} options.model corresponding model\n */\nconst fillNonLocalizedAttributes = (entry: any, relatedEntry: any, { model }: any) => {\n if (isNil(relatedEntry)) {\n return;\n }\n\n const modelDef = strapi.getModel(model);\n const relatedEntryCopy = copyNonLocalizedAttributes(modelDef, relatedEntry);\n\n for (const [field, value] of Object.entries(relatedEntryCopy)) {\n if (isNil(entry[field])) {\n entry[field] = value;\n }\n }\n};\n\n/**\n * build the populate param to\n * @param {String} modelUID uid of the model, could be of a content-type or a component\n */\nconst getNestedPopulateOfNonLocalizedAttributes = (modelUID: any): string[] => {\n const schema = strapi.getModel(modelUID);\n const scalarAttributes = getScalarAttributes(schema);\n const nonLocalizedAttributes = getNonLocalizedAttributes(schema);\n\n const allAttributes = [...scalarAttributes, ...nonLocalizedAttributes];\n if (schema.modelType === 'component') {\n // When called recursively on a non localized component we\n // need to explicitly populate that components relations\n allAttributes.push(...getRelationalAttributes(schema));\n }\n\n const currentAttributesToPopulate = allAttributes.filter((value, index, self) => {\n return self.indexOf(value) === index && self.lastIndexOf(value) === index;\n });\n\n const attributesToPopulate = [...currentAttributesToPopulate];\n for (const attrName of currentAttributesToPopulate) {\n const attr = schema.attributes[attrName];\n if (attr.type === 'component') {\n const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(attr.component).map(\n (nestedAttr) => `${attrName}.${nestedAttr}`\n );\n attributesToPopulate.push(...nestedPopulate);\n } else if (attr.type === 'dynamiczone') {\n attr.components.forEach((componentName) => {\n const nestedPopulate = getNestedPopulateOfNonLocalizedAttributes(componentName).map(\n (nestedAttr) => `${attrName}.${nestedAttr}`\n );\n attributesToPopulate.push(...nestedPopulate);\n });\n }\n }\n\n return attributesToPopulate;\n};\n\nconst contentTypes = () => ({\n isLocalizedContentType,\n getValidLocale,\n getLocalizedAttributes,\n getNonLocalizedAttributes,\n copyNonLocalizedAttributes,\n fillNonLocalizedAttributes,\n getNestedPopulateOfNonLocalizedAttributes,\n});\n\ntype ContentTypesService = typeof contentTypes;\n\nexport default contentTypes;\nexport { ContentTypesService };\n"],"names":["isRelationalAttribute","getVisibleAttributes","isTypedAttribute","getScalarAttributes","getRelationalAttributes","contentTypeUtils","ApplicationError","errors","hasLocalizedOption","modelOrAttribute","prop","getValidLocale","locale","localesService","getService","isNil","getDefaultLocale","foundLocale","findByCode","isLocalizedAttribute","attribute","isLocalizedContentType","model","getNonLocalizedAttributes","filter","attrName","attributes","removeId","value","has","id","removeIds","entry","removeIdsMut","cloneDeep","attr","Object","entries","type","isArray","forEach","compo","strapi","components","__component","component","copyNonLocalizedAttributes","nonLocalizedAttributes","pipe","pick","getLocalizedAttributes","fillNonLocalizedAttributes","relatedEntry","modelDef","getModel","relatedEntryCopy","field","getNestedPopulateOfNonLocalizedAttributes","modelUID","schema","scalarAttributes","allAttributes","modelType","push","currentAttributesToPopulate","index","self","indexOf","lastIndexOf","attributesToPopulate","nestedPopulate","map","nestedAttr","componentName","contentTypes"],"mappings":";;;;AAKA,MAAM,EACJA,qBAAqB,EACrBC,oBAAoB,EACpBC,gBAAgB,EAChBC,mBAAmB,EACnBC,uBAAuB,EACxB,GAAGC,cAAAA;AACJ,MAAM,EAAEC,gBAAgB,EAAE,GAAGC,MAAAA;AAE7B,MAAMC,qBAAqB,CAACC,gBAAAA,GAAAA;IAC1B,OAAOC,IAAAA,CAAK,gCAAgCD,gBAAAA,CAAAA,KAAsB,IAAA;AACpE,CAAA;AAEA,MAAME,iBAAiB,OAAOC,MAAAA,GAAAA;AAC5B,IAAA,MAAMC,iBAAiBC,UAAAA,CAAW,SAAA,CAAA;AAElC,IAAA,IAAIC,MAAMH,MAAAA,CAAAA,EAAS;AACjB,QAAA,OAAOC,eAAeG,gBAAgB,EAAA;AACxC,IAAA;AAEA,IAAA,MAAMC,WAAAA,GAAc,MAAMJ,cAAAA,CAAeK,UAAU,CAACN,MAAAA,CAAAA;AACpD,IAAA,IAAI,CAACK,WAAAA,EAAa;AAChB,QAAA,MAAM,IAAIX,gBAAAA,CAAiB,kBAAA,CAAA;AAC7B,IAAA;IAEA,OAAOM,MAAAA;AACT,CAAA;AAEA;;;;IAKA,MAAMO,uBAAuB,CAACC,SAAAA,GAAAA;AAC5B,IAAA,OACEZ,kBAAAA,CAAmBY,SAAAA,CAAAA,IACnBpB,qBAAAA,CAAsBoB,SAAAA,CAAAA,IACtBlB,iBAAiBkB,SAAAA,EAAW,KAAA,CAAA;AAEhC,CAAA;AAEA;;;;IAKA,MAAMC,yBAAyB,CAACC,KAAAA,GAAAA;AAC9B,IAAA,OAAOd,kBAAAA,CAAmBc,KAAAA,CAAAA;AAC5B,CAAA;A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AU,CAACD,QAAAA,CAAS;QACxC,IAAIU,IAAAA,CAAKG,IAAI,KAAK,WAAA,EAAa;AAC7B,YAAA,MAAMgC,cAAAA,GAAiBb,yCAAAA,CAA0CtB,IAAAA,CAAKU,SAAS,CAAA,CAAE0B,GAAG,CAClF,CAACC,UAAAA,GAAe,CAAA,EAAG/C,QAAAA,CAAS,CAAC,EAAE+C,UAAAA,CAAAA,CAAY,CAAA;AAE7CH,YAAAA,oBAAAA,CAAqBN,IAAI,CAAA,GAAIO,cAAAA,CAAAA;AAC/B,QAAA,CAAA,MAAO,IAAInC,IAAAA,CAAKG,IAAI,KAAK,aAAA,EAAe;AACtCH,YAAAA,IAAAA,CAAKQ,UAAU,CAACH,OAAO,CAAC,CAACiC,aAAAA,GAAAA;gBACvB,MAAMH,cAAAA,GAAiBb,yCAAAA,CAA0CgB,aAAAA,CAAAA,CAAeF,GAAG,CACjF,CAACC,UAAAA,GAAe,CAAA,EAAG/C,QAAAA,CAAS,CAAC,EAAE+C,UAAAA,CAAAA,CAAY,CAAA;AAE7CH,gBAAAA,oBAAAA,CAAqBN,IAAI,CAAA,GAAIO,cAAAA,CAAAA;AAC/B,YAAA,CAAA,CAAA;AACF,QAAA;AACF,IAAA;IAEA,OAAOD,oBAAAA;AACT,CAAA;AAEA,MAAMK,YAAAA,GAAe,KAAO;AAC1BrD,QAAAA,sBAAAA;AACAV,QAAAA,cAAAA;AACAuC,QAAAA,sBAAAA;AACA3B,QAAAA,yBAAAA;AACAuB,QAAAA,0BAAAA;AACAK,QAAAA,0BAAAA;AACAM,QAAAA;KACF;;;;"}
|
|
@@ -156,7 +156,7 @@ declare const _default: () => {
|
|
|
156
156
|
getValidLocale: (locale: any) => Promise<any>;
|
|
157
157
|
getLocalizedAttributes: (model: any) => string[];
|
|
158
158
|
getNonLocalizedAttributes: (model: any) => string[];
|
|
159
|
-
copyNonLocalizedAttributes: (model:
|
|
159
|
+
copyNonLocalizedAttributes: (model: import("@strapi/types/dist/struct/schema.js").ComponentSchema | import("@strapi/types/dist/struct/schema.js").ContentTypeSchema, entry: any) => Record<string, any>;
|
|
160
160
|
fillNonLocalizedAttributes: (entry: any, relatedEntry: any, { model }: any) => void;
|
|
161
161
|
getNestedPopulateOfNonLocalizedAttributes: (modelUID: any) => string[];
|
|
162
162
|
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import type { Struct } from '@strapi/types';
|
|
1
2
|
declare const contentTypes: () => {
|
|
2
3
|
isLocalizedContentType: (model: any) => boolean;
|
|
3
4
|
getValidLocale: (locale: any) => Promise<any>;
|
|
4
5
|
getLocalizedAttributes: (model: any) => string[];
|
|
5
6
|
getNonLocalizedAttributes: (model: any) => string[];
|
|
6
|
-
copyNonLocalizedAttributes: (model:
|
|
7
|
+
copyNonLocalizedAttributes: (model: Struct.ComponentSchema | Struct.ContentTypeSchema, entry: any) => Record<string, any>;
|
|
7
8
|
fillNonLocalizedAttributes: (entry: any, relatedEntry: any, { model }: any) => void;
|
|
8
9
|
getNestedPopulateOfNonLocalizedAttributes: (modelUID: any) => string[];
|
|
9
10
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-types.d.ts","sourceRoot":"","sources":["../../../../server/src/services/content-types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"content-types.d.ts","sourceRoot":"","sources":["../../../../server/src/services/content-types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAkM5C,QAAA,MAAM,YAAY;oCAjJqB,GAAG;6BAjCJ,GAAG;oCA6GF,GAAG;uCAnEA,GAAG;wCAsDpC,MAAM,CAAC,eAAe,GAAG,MAAM,CAAC,iBAAiB,SACjD,GAAG;wCAyB+B,GAAG,gBAAgB,GAAG,aAAa,GAAG;0DAmBpB,GAAG,KAAG,MAAM,EAAE;CA6CzE,CAAC;AAEH,KAAK,mBAAmB,GAAG,OAAO,YAAY,CAAC;AAE/C,eAAe,YAAY,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -76,7 +76,7 @@ declare const _default: {
|
|
|
76
76
|
getValidLocale: (locale: any) => Promise<any>;
|
|
77
77
|
getLocalizedAttributes: (model: any) => string[];
|
|
78
78
|
getNonLocalizedAttributes: (model: any) => string[];
|
|
79
|
-
copyNonLocalizedAttributes: (model:
|
|
79
|
+
copyNonLocalizedAttributes: (model: import("@strapi/types/dist/struct/schema.js").ComponentSchema | import("@strapi/types/dist/struct/schema.js").ContentTypeSchema, entry: any) => Record<string, any>;
|
|
80
80
|
fillNonLocalizedAttributes: (entry: any, relatedEntry: any, { model }: any) => void;
|
|
81
81
|
getNestedPopulateOfNonLocalizedAttributes: (modelUID: any) => string[];
|
|
82
82
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/i18n",
|
|
3
|
-
"version": "5.52.
|
|
3
|
+
"version": "5.52.2",
|
|
4
4
|
"description": "Create read and update content in different languages, both from the Admin Panel and from the API",
|
|
5
5
|
"homepage": "https://strapi.io",
|
|
6
6
|
"bugs": {
|
|
@@ -63,20 +63,20 @@
|
|
|
63
63
|
"@reduxjs/toolkit": "1.9.7",
|
|
64
64
|
"@strapi/design-system": "2.2.4",
|
|
65
65
|
"@strapi/icons": "2.2.4",
|
|
66
|
-
"@strapi/utils": "5.52.
|
|
66
|
+
"@strapi/utils": "5.52.2",
|
|
67
67
|
"lodash": "4.18.1",
|
|
68
68
|
"qs": "6.15.3",
|
|
69
69
|
"react-intl": "6.6.2",
|
|
70
70
|
"react-redux": "8.1.3",
|
|
71
71
|
"yup": "0.32.9",
|
|
72
|
-
"zod": "
|
|
72
|
+
"zod": "4.4.3"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@strapi/admin": "5.52.
|
|
76
|
-
"@strapi/admin-test-utils": "5.52.
|
|
77
|
-
"@strapi/content-manager": "5.52.
|
|
78
|
-
"@strapi/database": "5.52.
|
|
79
|
-
"@strapi/types": "5.52.
|
|
75
|
+
"@strapi/admin": "5.52.2",
|
|
76
|
+
"@strapi/admin-test-utils": "5.52.2",
|
|
77
|
+
"@strapi/content-manager": "5.52.2",
|
|
78
|
+
"@strapi/database": "5.52.2",
|
|
79
|
+
"@strapi/types": "5.52.2",
|
|
80
80
|
"@testing-library/dom": "10.4.1",
|
|
81
81
|
"@testing-library/jest-dom": "6.9.1",
|
|
82
82
|
"@testing-library/react": "16.3.2",
|