fix: Some bugs

pull/40/head
Boaz Poolman 2022-01-17 21:02:50 +01:00
parent 02e0d5bd13
commit d0982f6390
4 changed files with 5 additions and 5 deletions

0
bin/config-sync Executable file → Normal file
View File

View File

@ -13,9 +13,9 @@ const ConfigType = class ConfigType {
process.exit(0); process.exit(0);
} }
// uid could be a single key or an array for a combined uid. So the type of uid is either string or string[] // uid could be a single key or an array for a combined uid. So the type of uid is either string or string[]
if(typeof uid === "string"){ if (typeof uid === "string") {
this.uidKeys = [uid]; this.uidKeys = [uid];
} else if(Array.isArray(uid)){ } else if (Array.isArray(uid)) {
this.uidKeys = uid.sort(); this.uidKeys = uid.sort();
} else { } else {
strapi.log.error(logMessage(`Wrong uid config for the '${configName}' config type.`)); strapi.log.error(logMessage(`Wrong uid config for the '${configName}' config type.`));
@ -139,7 +139,6 @@ const ConfigType = class ConfigType {
if (shouldExclude) return; if (shouldExclude) return;
const currentConfig = formattedDiff.databaseConfig[configName]; const currentConfig = formattedDiff.databaseConfig[configName];
const combinedUid = getCombinedUid(this.uidKeys, currentConfig);
if ( if (
!currentConfig !currentConfig
@ -147,6 +146,7 @@ const ConfigType = class ConfigType {
) { ) {
await strapi.plugin('config-sync').service('main').deleteConfigFile(configName); await strapi.plugin('config-sync').service('main').deleteConfigFile(configName);
} else { } else {
const combinedUid = getCombinedUid(this.uidKeys, currentConfig);
await strapi.plugin('config-sync').service('main').writeConfigFile(this.configPrefix, combinedUid, currentConfig); await strapi.plugin('config-sync').service('main').writeConfigFile(this.configPrefix, combinedUid, currentConfig);
} }
} }

View File

@ -3,7 +3,7 @@
const COMBINED_UID_JOINSTR = '+.+'; const COMBINED_UID_JOINSTR = '+.+';
const escapeUid = (uid) => typeof uid === "string" ? uid.replace(/\+\.\+/g, '+_._+') : uid; const escapeUid = (uid) => typeof uid === "string" ? uid.replace(/\+\.\+/g, '+_._+') : uid;
const unEscapeUid = (uid) => typeof uid === "string" ? uid.replace(/\+_\._\+_/g, '+.+') : uid; const unEscapeUid = (uid) => typeof uid === "string" ? uid.replace(/\+_\._\+/g, '+.+') : uid;
const getCombinedUid = (uidKeys, params) => uidKeys.map((uidKey) => escapeUid(params[uidKey])).join(COMBINED_UID_JOINSTR); const getCombinedUid = (uidKeys, params) => uidKeys.map((uidKey) => escapeUid(params[uidKey])).join(COMBINED_UID_JOINSTR);
const getCombinedUidWhereFilter = (uidKeys, params) => uidKeys.reduce(((akku, uidKey) => ({ ...akku, [uidKey]: params[uidKey] })), {}); const getCombinedUidWhereFilter = (uidKeys, params) => uidKeys.reduce(((akku, uidKey) => ({ ...akku, [uidKey]: params[uidKey] })), {});
const getUidParamsFromName = (uidKeys, configName) => configName.split(COMBINED_UID_JOINSTR).map(unEscapeUid).reduce((akku, param, i) => ({ ...akku, [uidKeys[i]]: param }), {}); const getUidParamsFromName = (uidKeys, configName) => configName.split(COMBINED_UID_JOINSTR).map(unEscapeUid).reduce((akku, param, i) => ({ ...akku, [uidKeys[i]]: param }), {});

View File

@ -12493,4 +12493,4 @@ yup@^0.32.9:
lodash-es "^4.17.21" lodash-es "^4.17.21"
nanoclone "^0.2.1" nanoclone "^0.2.1"
property-expr "^2.0.4" property-expr "^2.0.4"
toposort "^2.0.2" toposort "^2.0.2"