@strapi/core 0.0.0-experimental.da76e83c9180ce7e4ab187aece17ea6bf19c783c → 0.0.0-experimental.da850ac6030a73229550aab5ce80ce47be683429
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.
Potentially problematic release.
This version of @strapi/core might be problematic. Click here for more details.
- package/dist/Strapi.d.ts +1 -0
- package/dist/Strapi.d.ts.map +1 -1
- package/dist/Strapi.js +21 -2
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +21 -2
- package/dist/Strapi.mjs.map +1 -1
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +6 -0
- package/dist/constants.js.map +1 -0
- package/dist/constants.mjs +4 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/core-api/controller/index.d.ts.map +1 -1
- package/dist/core-api/controller/index.js +2 -1
- package/dist/core-api/controller/index.js.map +1 -1
- package/dist/core-api/controller/index.mjs +2 -1
- package/dist/core-api/controller/index.mjs.map +1 -1
- package/dist/core-api/controller/transform.d.ts +3 -2
- package/dist/core-api/controller/transform.d.ts.map +1 -1
- package/dist/core-api/controller/transform.js +13 -3
- package/dist/core-api/controller/transform.js.map +1 -1
- package/dist/core-api/controller/transform.mjs +13 -3
- package/dist/core-api/controller/transform.mjs.map +1 -1
- package/dist/core-api/routes/validation/attributes.d.ts +1 -1
- package/dist/core-api/routes/validation/mappers.d.ts.map +1 -1
- package/dist/core-api/routes/validation/mappers.js +35 -0
- package/dist/core-api/routes/validation/mappers.js.map +1 -1
- package/dist/core-api/routes/validation/mappers.mjs +35 -0
- package/dist/core-api/routes/validation/mappers.mjs.map +1 -1
- package/dist/core-api/routes/validation/utils.d.ts.map +1 -1
- package/dist/core-api/routes/validation/utils.js +22 -6
- package/dist/core-api/routes/validation/utils.js.map +1 -1
- package/dist/core-api/routes/validation/utils.mjs +22 -6
- package/dist/core-api/routes/validation/utils.mjs.map +1 -1
- package/dist/loaders/plugins/index.js +1 -1
- package/dist/loaders/plugins/index.js.map +1 -1
- package/dist/loaders/plugins/index.mjs +1 -1
- package/dist/loaders/plugins/index.mjs.map +1 -1
- package/dist/middlewares/security.d.ts.map +1 -1
- package/dist/middlewares/security.js +2 -15
- package/dist/middlewares/security.js.map +1 -1
- package/dist/middlewares/security.mjs +2 -15
- package/dist/middlewares/security.mjs.map +1 -1
- package/dist/package.json.js +13 -11
- package/dist/package.json.js.map +1 -1
- package/dist/package.json.mjs +13 -11
- package/dist/package.json.mjs.map +1 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +2 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/index.mjs +2 -0
- package/dist/providers/index.mjs.map +1 -1
- package/dist/providers/session-manager.d.ts +3 -0
- package/dist/providers/session-manager.d.ts.map +1 -0
- package/dist/providers/session-manager.js +23 -0
- package/dist/providers/session-manager.js.map +1 -0
- package/dist/providers/session-manager.mjs +21 -0
- package/dist/providers/session-manager.mjs.map +1 -0
- package/dist/services/content-api/index.d.ts +1 -1
- package/dist/services/content-api/index.d.ts.map +1 -1
- package/dist/services/content-api/index.js +1 -1
- package/dist/services/content-api/index.js.map +1 -1
- package/dist/services/content-api/index.mjs +2 -2
- package/dist/services/content-api/index.mjs.map +1 -1
- package/dist/services/content-source-maps.d.ts +13 -0
- package/dist/services/content-source-maps.d.ts.map +1 -0
- package/dist/services/content-source-maps.js +108 -0
- package/dist/services/content-source-maps.js.map +1 -0
- package/dist/services/content-source-maps.mjs +106 -0
- package/dist/services/content-source-maps.mjs.map +1 -0
- package/dist/services/document-service/components.d.ts +31 -1
- package/dist/services/document-service/components.d.ts.map +1 -1
- package/dist/services/document-service/components.js +109 -0
- package/dist/services/document-service/components.js.map +1 -1
- package/dist/services/document-service/components.mjs +107 -1
- package/dist/services/document-service/components.mjs.map +1 -1
- package/dist/services/document-service/repository.d.ts.map +1 -1
- package/dist/services/document-service/repository.js +4 -0
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +5 -1
- package/dist/services/document-service/repository.mjs.map +1 -1
- package/dist/services/document-service/utils/clean-component-join-table.d.ts +7 -0
- package/dist/services/document-service/utils/clean-component-join-table.d.ts.map +1 -0
- package/dist/services/document-service/utils/clean-component-join-table.js +145 -0
- package/dist/services/document-service/utils/clean-component-join-table.js.map +1 -0
- package/dist/services/document-service/utils/clean-component-join-table.mjs +143 -0
- package/dist/services/document-service/utils/clean-component-join-table.mjs.map +1 -0
- package/dist/services/document-service/utils/unidirectional-relations.d.ts +19 -2
- package/dist/services/document-service/utils/unidirectional-relations.d.ts.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.js +21 -6
- package/dist/services/document-service/utils/unidirectional-relations.js.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.mjs +21 -6
- package/dist/services/document-service/utils/unidirectional-relations.mjs.map +1 -1
- package/dist/services/metrics/index.js +2 -1
- package/dist/services/metrics/index.js.map +1 -1
- package/dist/services/metrics/index.mjs +2 -1
- package/dist/services/metrics/index.mjs.map +1 -1
- package/dist/services/metrics/middleware.d.ts +2 -1
- package/dist/services/metrics/middleware.d.ts.map +1 -1
- package/dist/services/metrics/middleware.js +2 -2
- package/dist/services/metrics/middleware.js.map +1 -1
- package/dist/services/metrics/middleware.mjs +2 -2
- package/dist/services/metrics/middleware.mjs.map +1 -1
- package/dist/services/metrics/sender.d.ts.map +1 -1
- package/dist/services/metrics/sender.js +2 -1
- package/dist/services/metrics/sender.js.map +1 -1
- package/dist/services/metrics/sender.mjs +2 -1
- package/dist/services/metrics/sender.mjs.map +1 -1
- package/dist/services/session-manager.d.ts +167 -0
- package/dist/services/session-manager.d.ts.map +1 -0
- package/dist/services/session-manager.js +529 -0
- package/dist/services/session-manager.js.map +1 -0
- package/dist/services/session-manager.mjs +526 -0
- package/dist/services/session-manager.mjs.map +1 -0
- package/package.json +13 -11
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineProvider } from './provider.mjs';
|
|
2
|
+
import { createSessionManager } from '../services/session-manager.mjs';
|
|
3
|
+
|
|
4
|
+
var sessionManager = defineProvider({
|
|
5
|
+
init (strapi) {
|
|
6
|
+
strapi.add('sessionManager', ()=>createSessionManager({
|
|
7
|
+
db: strapi.db
|
|
8
|
+
}));
|
|
9
|
+
},
|
|
10
|
+
async register (strapi) {
|
|
11
|
+
// Get JWT secret from admin auth settings (same as admin token service)
|
|
12
|
+
const adminAuth = strapi.config.get('admin.auth', {});
|
|
13
|
+
const jwtSecret = adminAuth.secret;
|
|
14
|
+
if (!jwtSecret) {
|
|
15
|
+
throw new Error('Missing admin.auth.secret configuration. The SessionManager requires a JWT secret');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export { sessionManager as default };
|
|
21
|
+
//# sourceMappingURL=session-manager.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-manager.mjs","sources":["../../src/providers/session-manager.ts"],"sourcesContent":["import type { Algorithm } from 'jsonwebtoken';\nimport { defineProvider } from './provider';\nimport { createSessionManager } from '../services/session-manager';\n\ninterface AdminAuthConfig {\n secret?: string;\n options?: {\n algorithm?: Algorithm;\n [key: string]: unknown;\n };\n}\n\nexport default defineProvider({\n init(strapi) {\n strapi.add('sessionManager', () =>\n createSessionManager({\n db: strapi.db,\n })\n );\n },\n\n async register(strapi) {\n // Get JWT secret from admin auth settings (same as admin token service)\n const adminAuth = strapi.config.get<AdminAuthConfig>('admin.auth', {});\n const jwtSecret = adminAuth.secret;\n\n if (!jwtSecret) {\n throw new Error(\n 'Missing admin.auth.secret configuration. The SessionManager requires a JWT secret'\n );\n }\n },\n});\n"],"names":["defineProvider","init","strapi","add","createSessionManager","db","register","adminAuth","config","get","jwtSecret","secret","Error"],"mappings":";;;AAYA,qBAAeA,cAAe,CAAA;AAC5BC,IAAAA,IAAAA,CAAAA,CAAKC,MAAM,EAAA;AACTA,QAAAA,MAAAA,CAAOC,GAAG,CAAC,gBAAkB,EAAA,IAC3BC,oBAAqB,CAAA;AACnBC,gBAAAA,EAAAA,EAAIH,OAAOG;AACb,aAAA,CAAA,CAAA;AAEJ,KAAA;AAEA,IAAA,MAAMC,UAASJ,MAAM,EAAA;;AAEnB,QAAA,MAAMK,YAAYL,MAAOM,CAAAA,MAAM,CAACC,GAAG,CAAkB,cAAc,EAAC,CAAA;QACpE,MAAMC,SAAAA,GAAYH,UAAUI,MAAM;AAElC,QAAA,IAAI,CAACD,SAAW,EAAA;AACd,YAAA,MAAM,IAAIE,KACR,CAAA,mFAAA,CAAA;AAEJ;AACF;AACF,CAAG,CAAA;;;;"}
|
|
@@ -47,7 +47,7 @@ declare const createContentAPI: (strapi: Core.Strapi) => {
|
|
|
47
47
|
controllers: Record<string, string[]>;
|
|
48
48
|
}>;
|
|
49
49
|
};
|
|
50
|
-
getRoutesMap: () => Promise<Record<string,
|
|
50
|
+
getRoutesMap: () => Promise<Record<string, unknown>>;
|
|
51
51
|
sanitize: {
|
|
52
52
|
input: sanitize.SanitizeFunc;
|
|
53
53
|
output: sanitize.SanitizeFunc;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/content-api/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/content-api/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAqC,MAAM,eAAe,CAAC;AAEtF,OAAO,KAAK,EAAE,IAAI,EAAO,MAAM,eAAe,CAAC;AAgB/C;;GAEG;AACH,QAAA,MAAM,gBAAgB,WAAY,KAAK,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgF5C,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -49,7 +49,7 @@ const filterContentAPI = (route)=>route.info.type === 'content-api';
|
|
|
49
49
|
path: `${apiPrefix}${route.path}`
|
|
50
50
|
}));
|
|
51
51
|
});
|
|
52
|
-
return routesMap;
|
|
52
|
+
return strapiUtils.sanitizeRoutesMapForSerialization(routesMap);
|
|
53
53
|
};
|
|
54
54
|
const sanitizer = strapiUtils.sanitize.createAPISanitizers({
|
|
55
55
|
getModel (uid) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/services/content-api/index.ts"],"sourcesContent":["import _ from 'lodash';\nimport { sanitize, validate } from '@strapi/utils';\n\nimport type { Core, UID } from '@strapi/types';\n\nimport instantiatePermissionsUtilities from './permissions';\n\nconst transformRoutePrefixFor = (pluginName: string) => (route: Core.Route) => {\n const prefix = route.config && route.config.prefix;\n const path = prefix !== undefined ? `${prefix}${route.path}` : `/${pluginName}${route.path}`;\n\n return {\n ...route,\n path,\n };\n};\n\nconst filterContentAPI = (route: Core.Route) => route.info.type === 'content-api';\n\n/**\n * Create a content API container that holds logic, tools and utils. (eg: permissions, ...)\n */\nconst createContentAPI = (strapi: Core.Strapi) => {\n const getRoutesMap = async () => {\n const routesMap: Record<string, Core.Route[]> = {};\n\n _.forEach(strapi.apis, (api, apiName) => {\n const routes = _.flatMap(api.routes, (route) => {\n if ('routes' in route) {\n return route.routes;\n }\n\n return route;\n }).filter(filterContentAPI);\n\n if (routes.length === 0) {\n return;\n }\n\n const apiPrefix = strapi.config.get('api.rest.prefix');\n routesMap[`api::${apiName}`] = routes.map((route) => ({\n ...route,\n path: `${apiPrefix}${route.path}`,\n }));\n });\n\n _.forEach(strapi.plugins, (plugin, pluginName) => {\n const transformPrefix = transformRoutePrefixFor(pluginName);\n\n if (Array.isArray(plugin.routes)) {\n return plugin.routes.map(transformPrefix).filter(filterContentAPI);\n }\n\n const routes = _.flatMap(plugin.routes, (route) => route.routes.map(transformPrefix)).filter(\n filterContentAPI\n );\n\n if (routes.length === 0) {\n return;\n }\n\n const apiPrefix = strapi.config.get('api.rest.prefix');\n routesMap[`plugin::${pluginName}`] = routes.map((route) => ({\n ...route,\n path: `${apiPrefix}${route.path}`,\n }));\n });\n\n return routesMap;\n };\n\n const sanitizer = sanitize.createAPISanitizers({\n getModel(uid: string) {\n return strapi.getModel(uid as UID.Schema);\n },\n // NOTE: use lazy access to allow registration of sanitizers after the creation of the container\n get sanitizers() {\n return {\n input: strapi.sanitizers.get('content-api.input'),\n output: strapi.sanitizers.get('content-api.output'),\n };\n },\n });\n\n const validator = validate.createAPIValidators({\n getModel(uid: string) {\n return strapi.getModel(uid as UID.Schema);\n },\n // NOTE: use lazy access to allow registration of validators after the creation of the container\n get validators() {\n return {\n input: strapi.validators.get('content-api.input'),\n };\n },\n });\n\n return {\n permissions: instantiatePermissionsUtilities(strapi),\n getRoutesMap,\n sanitize: sanitizer,\n validate: validator,\n };\n};\n\nexport default createContentAPI;\n"],"names":["transformRoutePrefixFor","pluginName","route","prefix","config","path","undefined","filterContentAPI","info","type","createContentAPI","strapi","getRoutesMap","routesMap","_","forEach","apis","api","apiName","routes","flatMap","filter","length","apiPrefix","get","map","plugins","plugin","transformPrefix","Array","isArray","sanitizer","sanitize","createAPISanitizers","getModel","uid","sanitizers","input","output","validator","validate","createAPIValidators","validators","permissions","instantiatePermissionsUtilities"],"mappings":";;;;;;AAOA,MAAMA,uBAAAA,GAA0B,CAACC,UAAAA,GAAuB,CAACC,KAAAA,GAAAA;AACvD,QAAA,MAAMC,SAASD,KAAME,CAAAA,MAAM,IAAIF,KAAME,CAAAA,MAAM,CAACD,MAAM;QAClD,MAAME,IAAAA,GAAOF,WAAWG,SAAY,GAAA,CAAC,EAAEH,MAAO,CAAA,EAAED,MAAMG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,EAAEJ,UAAAA,CAAW,EAAEC,KAAMG,CAAAA,IAAI,CAAC,CAAC;QAE5F,OAAO;AACL,YAAA,GAAGH,KAAK;AACRG,YAAAA;AACF,SAAA;A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M,CAAG,EAAA;AAChC,gBAAA,OAAOQ,OAAOR,MAAM,CAACM,GAAG,CAACG,eAAAA,CAAAA,CAAiBP,MAAM,CAACd,gBAAAA,CAAAA;AACnD;AAEA,YAAA,MAAMY,SAASL,CAAEM,CAAAA,OAAO,CAACO,MAAAA,CAAOR,MAAM,EAAE,CAACjB,KAAUA,GAAAA,KAAAA,CAAMiB,MAAM,CAACM,GAAG,CAACG,eAAAA,CAAAA,CAAAA,CAAkBP,MAAM,CAC1Fd,gBAAAA,CAAAA;YAGF,IAAIY,MAAAA,CAAOG,MAAM,KAAK,CAAG,EAAA;AACvB,gBAAA;AACF;AAEA,YAAA,MAAMC,SAAYZ,GAAAA,MAAAA,CAAOP,MAAM,CAACoB,GAAG,CAAC,iBAAA,CAAA;AACpCX,YAAAA,SAAS,CAAC,CAAC,QAAQ,EAAEZ,UAAW,CAAA,CAAC,CAAC,GAAGkB,MAAOM,CAAAA,GAAG,CAAC,CAACvB,SAAW;AAC1D,oBAAA,GAAGA,KAAK;AACRG,oBAAAA,IAAAA,EAAM,CAAC,EAAEkB,SAAAA,CAAU,EAAErB,KAAMG,CAAAA,IAAI,CAAC;iBAClC,CAAA,CAAA;AACF,SAAA,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/services/content-api/index.ts"],"sourcesContent":["import _ from 'lodash';\nimport { sanitize, validate, sanitizeRoutesMapForSerialization } from '@strapi/utils';\n\nimport type { Core, UID } from '@strapi/types';\n\nimport instantiatePermissionsUtilities from './permissions';\n\nconst transformRoutePrefixFor = (pluginName: string) => (route: Core.Route) => {\n const prefix = route.config && route.config.prefix;\n const path = prefix !== undefined ? `${prefix}${route.path}` : `/${pluginName}${route.path}`;\n\n return {\n ...route,\n path,\n };\n};\n\nconst filterContentAPI = (route: Core.Route) => route.info.type === 'content-api';\n\n/**\n * Create a content API container that holds logic, tools and utils. (eg: permissions, ...)\n */\nconst createContentAPI = (strapi: Core.Strapi) => {\n const getRoutesMap = async () => {\n const routesMap: Record<string, Core.Route[]> = {};\n\n _.forEach(strapi.apis, (api, apiName) => {\n const routes = _.flatMap(api.routes, (route) => {\n if ('routes' in route) {\n return route.routes;\n }\n\n return route;\n }).filter(filterContentAPI);\n\n if (routes.length === 0) {\n return;\n }\n\n const apiPrefix = strapi.config.get('api.rest.prefix');\n routesMap[`api::${apiName}`] = routes.map((route) => ({\n ...route,\n path: `${apiPrefix}${route.path}`,\n }));\n });\n\n _.forEach(strapi.plugins, (plugin, pluginName) => {\n const transformPrefix = transformRoutePrefixFor(pluginName);\n\n if (Array.isArray(plugin.routes)) {\n return plugin.routes.map(transformPrefix).filter(filterContentAPI);\n }\n\n const routes = _.flatMap(plugin.routes, (route) => route.routes.map(transformPrefix)).filter(\n filterContentAPI\n );\n\n if (routes.length === 0) {\n return;\n }\n\n const apiPrefix = strapi.config.get('api.rest.prefix');\n routesMap[`plugin::${pluginName}`] = routes.map((route) => ({\n ...route,\n path: `${apiPrefix}${route.path}`,\n }));\n });\n\n return sanitizeRoutesMapForSerialization(routesMap);\n };\n\n const sanitizer = sanitize.createAPISanitizers({\n getModel(uid: string) {\n return strapi.getModel(uid as UID.Schema);\n },\n // NOTE: use lazy access to allow registration of sanitizers after the creation of the container\n get sanitizers() {\n return {\n input: strapi.sanitizers.get('content-api.input'),\n output: strapi.sanitizers.get('content-api.output'),\n };\n },\n });\n\n const validator = validate.createAPIValidators({\n getModel(uid: string) {\n return strapi.getModel(uid as UID.Schema);\n },\n // NOTE: use lazy access to allow registration of validators after the creation of the container\n get validators() {\n return {\n input: strapi.validators.get('content-api.input'),\n };\n },\n });\n\n return {\n permissions: instantiatePermissionsUtilities(strapi),\n getRoutesMap,\n sanitize: sanitizer,\n validate: validator,\n };\n};\n\nexport default createContentAPI;\n"],"names":["transformRoutePrefixFor","pluginName","route","prefix","config","path","undefined","filterContentAPI","info","type","createContentAPI","strapi","getRoutesMap","routesMap","_","forEach","apis","api","apiName","routes","flatMap","filter","length","apiPrefix","get","map","plugins","plugin","transformPrefix","Array","isArray","sanitizeRoutesMapForSerialization","sanitizer","sanitize","createAPISanitizers","getModel","uid","sanitizers","input","output","validator","validate","createAPIValidators","validators","permissions","instantiatePermissionsUtilities"],"mappings":";;;;;;AAOA,MAAMA,uBAAAA,GAA0B,CAACC,UAAAA,GAAuB,CAACC,KAAAA,GAAAA;AACvD,QAAA,MAAMC,SAASD,KAAME,CAAAA,MAAM,IAAIF,KAAME,CAAAA,MAAM,CAACD,MAAM;QAClD,MAAME,IAAAA,GAAOF,WAAWG,SAAY,GAAA,CAAC,EAAEH,MAAO,CAAA,EAAED,MAAMG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,EAAEJ,UAAAA,CAAW,EAAEC,KAAMG,CAAAA,IAAI,CAAC,CAAC;QAE5F,OAAO;AACL,YAAA,GAAGH,KAAK;AACRG,YAAAA;AACF,SAAA;AACF,KAAA;AAEA,MAAME,mBAAmB,CAACL,KAAAA,GAAsBA,MAAMM,IAAI,CAACC,IAAI,KAAK,aAAA;AAEpE;;IAGA,MAAMC,mBAAmB,CAACC,MAAAA,GAAAA;AACxB,IAAA,MAAMC,YAAe,GAAA,UAAA;AACnB,QAAA,MAAMC,YAA0C,EAAC;AAEjDC,QAAAA,CAAAA,CAAEC,OAAO,CAACJ,MAAAA,CAAOK,IAAI,EAAE,CAACC,GAAKC,EAAAA,OAAAA,GAAAA;AAC3B,YAAA,MAAMC,SAASL,CAAEM,CAAAA,OAAO,CAACH,GAAIE,CAAAA,MAAM,EAAE,CAACjB,KAAAA,GAAAA;AACpC,gBAAA,IAAI,YAAYA,KAAO,EAAA;AACrB,oBAAA,OAAOA,MAAMiB,MAAM;AACrB;gBAEA,OAAOjB,KAAAA;AACT,aAAA,CAAA,CAAGmB,MAAM,CAACd,gBAAAA,CAAAA;YAEV,IAAIY,MAAAA,CAAOG,MAAM,KAAK,CAAG,EAAA;AACvB,gBAAA;AACF;AAEA,YAAA,MAAMC,SAAYZ,GAAAA,MAAAA,CAAOP,MAA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KAAMG,CAAAA,IAAI,CAAC;iBAClC,CAAA,CAAA;AACF,SAAA,CAAA;AAEA,QAAA,OAAO0B,6CAAkClB,CAAAA,SAAAA,CAAAA;AAC3C,KAAA;IAEA,MAAMmB,SAAAA,GAAYC,oBAASC,CAAAA,mBAAmB,CAAC;AAC7CC,QAAAA,QAAAA,CAAAA,CAASC,GAAW,EAAA;YAClB,OAAOzB,MAAAA,CAAOwB,QAAQ,CAACC,GAAAA,CAAAA;AACzB,SAAA;;AAEA,QAAA,IAAIC,UAAa,CAAA,GAAA;YACf,OAAO;AACLC,gBAAAA,KAAAA,EAAO3B,MAAO0B,CAAAA,UAAU,CAACb,GAAG,CAAC,mBAAA,CAAA;AAC7Be,gBAAAA,MAAAA,EAAQ5B,MAAO0B,CAAAA,UAAU,CAACb,GAAG,CAAC,oBAAA;AAChC,aAAA;AACF;AACF,KAAA,CAAA;IAEA,MAAMgB,SAAAA,GAAYC,oBAASC,CAAAA,mBAAmB,CAAC;AAC7CP,QAAAA,QAAAA,CAAAA,CAASC,GAAW,EAAA;YAClB,OAAOzB,MAAAA,CAAOwB,QAAQ,CAACC,GAAAA,CAAAA;AACzB,SAAA;;AAEA,QAAA,IAAIO,UAAa,CAAA,GAAA;YACf,OAAO;AACLL,gBAAAA,KAAAA,EAAO3B,MAAOgC,CAAAA,UAAU,CAACnB,GAAG,CAAC,mBAAA;AAC/B,aAAA;AACF;AACF,KAAA,CAAA;IAEA,OAAO;AACLoB,QAAAA,WAAAA,EAAaC,KAAgClC,CAAAA,MAAAA,CAAAA;AAC7CC,QAAAA,YAAAA;QACAqB,QAAUD,EAAAA,SAAAA;QACVS,QAAUD,EAAAA;AACZ,KAAA;AACF;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
|
-
import { sanitize, validate } from '@strapi/utils';
|
|
2
|
+
import { sanitize, validate, sanitizeRoutesMapForSerialization } from '@strapi/utils';
|
|
3
3
|
import instantiatePermissionsUtilities from './permissions/index.mjs';
|
|
4
4
|
|
|
5
5
|
const transformRoutePrefixFor = (pluginName)=>(route)=>{
|
|
@@ -47,7 +47,7 @@ const filterContentAPI = (route)=>route.info.type === 'content-api';
|
|
|
47
47
|
path: `${apiPrefix}${route.path}`
|
|
48
48
|
}));
|
|
49
49
|
});
|
|
50
|
-
return routesMap;
|
|
50
|
+
return sanitizeRoutesMapForSerialization(routesMap);
|
|
51
51
|
};
|
|
52
52
|
const sanitizer = sanitize.createAPISanitizers({
|
|
53
53
|
getModel (uid) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/services/content-api/index.ts"],"sourcesContent":["import _ from 'lodash';\nimport { sanitize, validate } from '@strapi/utils';\n\nimport type { Core, UID } from '@strapi/types';\n\nimport instantiatePermissionsUtilities from './permissions';\n\nconst transformRoutePrefixFor = (pluginName: string) => (route: Core.Route) => {\n const prefix = route.config && route.config.prefix;\n const path = prefix !== undefined ? `${prefix}${route.path}` : `/${pluginName}${route.path}`;\n\n return {\n ...route,\n path,\n };\n};\n\nconst filterContentAPI = (route: Core.Route) => route.info.type === 'content-api';\n\n/**\n * Create a content API container that holds logic, tools and utils. (eg: permissions, ...)\n */\nconst createContentAPI = (strapi: Core.Strapi) => {\n const getRoutesMap = async () => {\n const routesMap: Record<string, Core.Route[]> = {};\n\n _.forEach(strapi.apis, (api, apiName) => {\n const routes = _.flatMap(api.routes, (route) => {\n if ('routes' in route) {\n return route.routes;\n }\n\n return route;\n }).filter(filterContentAPI);\n\n if (routes.length === 0) {\n return;\n }\n\n const apiPrefix = strapi.config.get('api.rest.prefix');\n routesMap[`api::${apiName}`] = routes.map((route) => ({\n ...route,\n path: `${apiPrefix}${route.path}`,\n }));\n });\n\n _.forEach(strapi.plugins, (plugin, pluginName) => {\n const transformPrefix = transformRoutePrefixFor(pluginName);\n\n if (Array.isArray(plugin.routes)) {\n return plugin.routes.map(transformPrefix).filter(filterContentAPI);\n }\n\n const routes = _.flatMap(plugin.routes, (route) => route.routes.map(transformPrefix)).filter(\n filterContentAPI\n );\n\n if (routes.length === 0) {\n return;\n }\n\n const apiPrefix = strapi.config.get('api.rest.prefix');\n routesMap[`plugin::${pluginName}`] = routes.map((route) => ({\n ...route,\n path: `${apiPrefix}${route.path}`,\n }));\n });\n\n return routesMap;\n };\n\n const sanitizer = sanitize.createAPISanitizers({\n getModel(uid: string) {\n return strapi.getModel(uid as UID.Schema);\n },\n // NOTE: use lazy access to allow registration of sanitizers after the creation of the container\n get sanitizers() {\n return {\n input: strapi.sanitizers.get('content-api.input'),\n output: strapi.sanitizers.get('content-api.output'),\n };\n },\n });\n\n const validator = validate.createAPIValidators({\n getModel(uid: string) {\n return strapi.getModel(uid as UID.Schema);\n },\n // NOTE: use lazy access to allow registration of validators after the creation of the container\n get validators() {\n return {\n input: strapi.validators.get('content-api.input'),\n };\n },\n });\n\n return {\n permissions: instantiatePermissionsUtilities(strapi),\n getRoutesMap,\n sanitize: sanitizer,\n validate: validator,\n };\n};\n\nexport default createContentAPI;\n"],"names":["transformRoutePrefixFor","pluginName","route","prefix","config","path","undefined","filterContentAPI","info","type","createContentAPI","strapi","getRoutesMap","routesMap","_","forEach","apis","api","apiName","routes","flatMap","filter","length","apiPrefix","get","map","plugins","plugin","transformPrefix","Array","isArray","sanitizer","sanitize","createAPISanitizers","getModel","uid","sanitizers","input","output","validator","validate","createAPIValidators","validators","permissions","instantiatePermissionsUtilities"],"mappings":";;;;AAOA,MAAMA,uBAAAA,GAA0B,CAACC,UAAAA,GAAuB,CAACC,KAAAA,GAAAA;AACvD,QAAA,MAAMC,SAASD,KAAME,CAAAA,MAAM,IAAIF,KAAME,CAAAA,MAAM,CAACD,MAAM;QAClD,MAAME,IAAAA,GAAOF,WAAWG,SAAY,GAAA,CAAC,EAAEH,MAAO,CAAA,EAAED,MAAMG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,EAAEJ,UAAAA,CAAW,EAAEC,KAAMG,CAAAA,IAAI,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,CAAAA;AAEhD,YAAA,IAAI4B,KAAMC,CAAAA,OAAO,CAACH,MAAAA,CAAOR,MAAM,CAAG,EAAA;AAChC,gBAAA,OAAOQ,OAAOR,MAAM,CAACM,GAAG,CAACG,eAAAA,CAAAA,CAAiBP,MAAM,CAACd,gBAAAA,CAAAA;AACnD;AAEA,YAAA,MAAMY,SAASL,CAAEM,CAAAA,OAAO,CAACO,MAAAA,CAAOR,MAAM,EAAE,CAACjB,KAAUA,GAAAA,KAAAA,CAAMiB,MAAM,CAACM,GAAG,CAACG,eAAAA,CAAAA,CAAAA,CAAkBP,MAAM,CAC1Fd,gBAAAA,CAAAA;YAGF,IAAIY,MAAAA,CAAOG,MAAM,KAAK,CAAG,EAAA;AACvB,gBAAA;AACF;AAEA,YAAA,MAAMC,SAAYZ,GAAAA,MAAAA,CAAOP,MAAM,CAACoB,GAAG,CAAC,iBAAA,CAAA;AACpCX,YAAAA,SAAS,CAAC,CAAC,QAAQ,EAAEZ,UAAW,CAAA,CAAC,CAAC,GAAGkB,MAAOM,CAAAA,GAAG,CAAC,CAACvB,SAAW;AAC1D,oBAAA,GAAGA,KAAK;AACRG,oBAAAA,IAAAA,EAAM,CAAC,EAAEkB,SAAAA,CAAU,EAAErB,KAAMG,CAAAA,IAAI,CAAC;iBAClC,CAAA,CAAA;AACF,SAAA,CAAA;
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/services/content-api/index.ts"],"sourcesContent":["import _ from 'lodash';\nimport { sanitize, validate, sanitizeRoutesMapForSerialization } from '@strapi/utils';\n\nimport type { Core, UID } from '@strapi/types';\n\nimport instantiatePermissionsUtilities from './permissions';\n\nconst transformRoutePrefixFor = (pluginName: string) => (route: Core.Route) => {\n const prefix = route.config && route.config.prefix;\n const path = prefix !== undefined ? `${prefix}${route.path}` : `/${pluginName}${route.path}`;\n\n return {\n ...route,\n path,\n };\n};\n\nconst filterContentAPI = (route: Core.Route) => route.info.type === 'content-api';\n\n/**\n * Create a content API container that holds logic, tools and utils. (eg: permissions, ...)\n */\nconst createContentAPI = (strapi: Core.Strapi) => {\n const getRoutesMap = async () => {\n const routesMap: Record<string, Core.Route[]> = {};\n\n _.forEach(strapi.apis, (api, apiName) => {\n const routes = _.flatMap(api.routes, (route) => {\n if ('routes' in route) {\n return route.routes;\n }\n\n return route;\n }).filter(filterContentAPI);\n\n if (routes.length === 0) {\n return;\n }\n\n const apiPrefix = strapi.config.get('api.rest.prefix');\n routesMap[`api::${apiName}`] = routes.map((route) => ({\n ...route,\n path: `${apiPrefix}${route.path}`,\n }));\n });\n\n _.forEach(strapi.plugins, (plugin, pluginName) => {\n const transformPrefix = transformRoutePrefixFor(pluginName);\n\n if (Array.isArray(plugin.routes)) {\n return plugin.routes.map(transformPrefix).filter(filterContentAPI);\n }\n\n const routes = _.flatMap(plugin.routes, (route) => route.routes.map(transformPrefix)).filter(\n filterContentAPI\n );\n\n if (routes.length === 0) {\n return;\n }\n\n const apiPrefix = strapi.config.get('api.rest.prefix');\n routesMap[`plugin::${pluginName}`] = routes.map((route) => ({\n ...route,\n path: `${apiPrefix}${route.path}`,\n }));\n });\n\n return sanitizeRoutesMapForSerialization(routesMap);\n };\n\n const sanitizer = sanitize.createAPISanitizers({\n getModel(uid: string) {\n return strapi.getModel(uid as UID.Schema);\n },\n // NOTE: use lazy access to allow registration of sanitizers after the creation of the container\n get sanitizers() {\n return {\n input: strapi.sanitizers.get('content-api.input'),\n output: strapi.sanitizers.get('content-api.output'),\n };\n },\n });\n\n const validator = validate.createAPIValidators({\n getModel(uid: string) {\n return strapi.getModel(uid as UID.Schema);\n },\n // NOTE: use lazy access to allow registration of validators after the creation of the container\n get validators() {\n return {\n input: strapi.validators.get('content-api.input'),\n };\n },\n });\n\n return {\n permissions: instantiatePermissionsUtilities(strapi),\n getRoutesMap,\n sanitize: sanitizer,\n validate: validator,\n };\n};\n\nexport default createContentAPI;\n"],"names":["transformRoutePrefixFor","pluginName","route","prefix","config","path","undefined","filterContentAPI","info","type","createContentAPI","strapi","getRoutesMap","routesMap","_","forEach","apis","api","apiName","routes","flatMap","filter","length","apiPrefix","get","map","plugins","plugin","transformPrefix","Array","isArray","sanitizeRoutesMapForSerialization","sanitizer","sanitize","createAPISanitizers","getModel","uid","sanitizers","input","output","validator","validate","createAPIValidators","validators","permissions","instantiatePermissionsUtilities"],"mappings":";;;;AAOA,MAAMA,uBAAAA,GAA0B,CAACC,UAAAA,GAAuB,CAACC,KAAAA,GAAAA;AACvD,QAAA,MAAMC,SAASD,KAAME,CAAAA,MAAM,IAAIF,KAAME,CAAAA,MAAM,CAACD,MAAM;QAClD,MAAME,IAAAA,GAAOF,WAAWG,SAAY,GAAA,CAAC,EAAEH,MAAO,CAAA,EAAED,MAAMG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,EAAEJ,UAAAA,CAAW,EAAEC,KAAMG,CAAAA,IAAI,CAAC,CAAC;QAE5F,OAAO;AACL,YAAA,GAAGH,KAAK;AACRG,YAAAA;AACF,SAAA;AACF,KAAA;AAEA,MAAME,mBAAmB,CAACL,KAAAA,GAAsBA,MAAMM,IAAI,CAACC,IAAI,KAAK,aAAA;AAEpE;;IAGA,MAAMC,mBAAmB,CAACC,MAAAA,GAAAA;AACxB,IAAA,MAAMC,YAAe,GAAA,UAAA;AACnB,QAAA,MAAMC,YAA0C,EAAC;AAEjDC,QAAAA,CAAAA,CAAEC,OAAO,CAACJ,MAAAA,CAAOK,IAAI,EAAE,CAACC,GAAKC,EAAAA,OAAAA,GAAAA;AAC3B,YAAA,MAAMC,SAASL,CAAEM,CAAAA,OAAO,CAACH,GAAIE,CAAAA,MAAM,EAAE,CAACjB,KAAAA,GAAAA;AACpC,gBAAA,IAAI,YAAYA,KAAO,EAAA;AACrB,oBAAA,OAAOA,MAAMiB,MAAM;AACrB;gBAEA,OAAOjB,KAAAA;AACT,aAAA,CAAA,CAAGmB,MAAM,CAACd,gBAAAA,CAAAA;YAEV,IAAIY,MAAAA,CAAOG,MAAM,KAAK,CAAG,EA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strapi-admin';
|
|
3
|
+
interface EncodingInfo {
|
|
4
|
+
data: any;
|
|
5
|
+
schema: Struct.Schema;
|
|
6
|
+
}
|
|
7
|
+
declare const createContentSourceMapsService: (strapi: Core.Strapi) => {
|
|
8
|
+
encodeField(text: string, { kind, model, documentId, type, path, locale }: FieldContentSourceMap): string;
|
|
9
|
+
encodeEntry({ data, schema }: EncodingInfo): Promise<any>;
|
|
10
|
+
encodeSourceMaps({ data, schema }: EncodingInfo): Promise<any>;
|
|
11
|
+
};
|
|
12
|
+
export { createContentSourceMapsService };
|
|
13
|
+
//# sourceMappingURL=content-source-maps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-source-maps.d.ts","sourceRoot":"","sources":["../../src/services/content-source-maps.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAO,MAAM,eAAe,CAAC;AAEvD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAwCxE,UAAU,YAAY;IACpB,IAAI,EAAE,GAAG,CAAC;IACV,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;CACvB;AAMD,QAAA,MAAM,8BAA8B,WAAY,KAAK,MAAM;sBAG/C,MAAM,mDACqC,qBAAqB;kCAyBpC,YAAY,GAAG,QAAQ,GAAG,CAAC;uCAiCtB,YAAY,GAAG,QAAQ,GAAG,CAAC;CAmBvE,CAAC;AAEF,OAAO,EAAE,8BAA8B,EAAE,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var stega = require('@vercel/stega');
|
|
4
|
+
var strapiUtils = require('@strapi/utils');
|
|
5
|
+
|
|
6
|
+
const ENCODABLE_TYPES = [
|
|
7
|
+
'string',
|
|
8
|
+
'text',
|
|
9
|
+
'richtext',
|
|
10
|
+
'biginteger',
|
|
11
|
+
'date',
|
|
12
|
+
'time',
|
|
13
|
+
'datetime',
|
|
14
|
+
'timestamp',
|
|
15
|
+
'boolean',
|
|
16
|
+
'enumeration',
|
|
17
|
+
'json',
|
|
18
|
+
'media',
|
|
19
|
+
'email',
|
|
20
|
+
'password'
|
|
21
|
+
];
|
|
22
|
+
// TODO: use a centralized store for these fields that would be shared with the CM and CTB
|
|
23
|
+
const EXCLUDED_FIELDS = [
|
|
24
|
+
'id',
|
|
25
|
+
'documentId',
|
|
26
|
+
'locale',
|
|
27
|
+
'localizations',
|
|
28
|
+
'created_by',
|
|
29
|
+
'updated_by',
|
|
30
|
+
'created_at',
|
|
31
|
+
'updated_at',
|
|
32
|
+
'publishedAt'
|
|
33
|
+
];
|
|
34
|
+
const isObject = (value)=>{
|
|
35
|
+
return typeof value === 'object' && value !== null;
|
|
36
|
+
};
|
|
37
|
+
const createContentSourceMapsService = (strapi)=>{
|
|
38
|
+
return {
|
|
39
|
+
encodeField (text, { kind, model, documentId, type, path, locale }) {
|
|
40
|
+
/**
|
|
41
|
+
* Combine all metadata into into a one string so we only have to deal with one data-atribute
|
|
42
|
+
* on the frontend. Make it human readable because that data-attribute may be set manually by
|
|
43
|
+
* users for fields that don't support sourcemap encoding.
|
|
44
|
+
*/ const strapiSource = new URLSearchParams();
|
|
45
|
+
strapiSource.set('documentId', documentId);
|
|
46
|
+
strapiSource.set('type', type);
|
|
47
|
+
strapiSource.set('path', path);
|
|
48
|
+
if (model) {
|
|
49
|
+
strapiSource.set('model', model);
|
|
50
|
+
}
|
|
51
|
+
if (kind) {
|
|
52
|
+
strapiSource.set('kind', kind);
|
|
53
|
+
}
|
|
54
|
+
if (locale) {
|
|
55
|
+
strapiSource.set('locale', locale);
|
|
56
|
+
}
|
|
57
|
+
return stega.vercelStegaCombine(text, {
|
|
58
|
+
strapiSource: strapiSource.toString()
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
async encodeEntry ({ data, schema }) {
|
|
62
|
+
if (!isObject(data) || data === undefined) {
|
|
63
|
+
return data;
|
|
64
|
+
}
|
|
65
|
+
return strapiUtils.traverseEntity(({ key, value, attribute, schema, path }, { set })=>{
|
|
66
|
+
if (!attribute || EXCLUDED_FIELDS.includes(key)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (ENCODABLE_TYPES.includes(attribute.type) && typeof value === 'string') {
|
|
70
|
+
set(key, this.encodeField(value, {
|
|
71
|
+
path: path.rawWithIndices,
|
|
72
|
+
type: attribute.type,
|
|
73
|
+
kind: schema.kind,
|
|
74
|
+
model: schema.uid,
|
|
75
|
+
locale: data.locale,
|
|
76
|
+
documentId: data.documentId
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
}, {
|
|
80
|
+
schema,
|
|
81
|
+
getModel: (uid)=>strapi.getModel(uid)
|
|
82
|
+
}, data);
|
|
83
|
+
},
|
|
84
|
+
async encodeSourceMaps ({ data, schema }) {
|
|
85
|
+
try {
|
|
86
|
+
if (Array.isArray(data)) {
|
|
87
|
+
return await Promise.all(data.map((item)=>this.encodeSourceMaps({
|
|
88
|
+
data: item,
|
|
89
|
+
schema
|
|
90
|
+
})));
|
|
91
|
+
}
|
|
92
|
+
if (!isObject(data)) {
|
|
93
|
+
return data;
|
|
94
|
+
}
|
|
95
|
+
return await this.encodeEntry({
|
|
96
|
+
data,
|
|
97
|
+
schema
|
|
98
|
+
});
|
|
99
|
+
} catch (error) {
|
|
100
|
+
strapi.log.error('Error encoding source maps:', error);
|
|
101
|
+
return data;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
exports.createContentSourceMapsService = createContentSourceMapsService;
|
|
108
|
+
//# sourceMappingURL=content-source-maps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-source-maps.js","sources":["../../src/services/content-source-maps.ts"],"sourcesContent":["import { vercelStegaCombine } from '@vercel/stega';\nimport type { Core, Struct, UID } from '@strapi/types';\nimport { traverseEntity } from '@strapi/utils';\nimport type { FieldContentSourceMap } from '@strapi/admin/strapi-admin';\n\nconst ENCODABLE_TYPES = [\n 'string',\n 'text',\n 'richtext',\n 'biginteger',\n 'date',\n 'time',\n 'datetime',\n 'timestamp',\n 'boolean',\n 'enumeration',\n 'json',\n 'media',\n 'email',\n 'password',\n /**\n * We cannot modify the response shape, so types that aren't based on string cannot be encoded:\n * - json: object\n * - blocks: object, will require a custom implementation in a dedicated PR\n * - integer, float and decimal: number\n * - boolean: boolean (believe it or not)\n * - uid: can be stringified but would mess up URLs\n */\n];\n\n// TODO: use a centralized store for these fields that would be shared with the CM and CTB\nconst EXCLUDED_FIELDS = [\n 'id',\n 'documentId',\n 'locale',\n 'localizations',\n 'created_by',\n 'updated_by',\n 'created_at',\n 'updated_at',\n 'publishedAt',\n];\n\ninterface EncodingInfo {\n data: any;\n schema: Struct.Schema;\n}\n\nconst isObject = (value: unknown): value is Record<string, any> => {\n return typeof value === 'object' && value !== null;\n};\n\nconst createContentSourceMapsService = (strapi: Core.Strapi) => {\n return {\n encodeField(\n text: string,\n { kind, model, documentId, type, path, locale }: FieldContentSourceMap\n ) {\n /**\n * Combine all metadata into into a one string so we only have to deal with one data-atribute\n * on the frontend. Make it human readable because that data-attribute may be set manually by\n * users for fields that don't support sourcemap encoding.\n */\n const strapiSource = new URLSearchParams();\n strapiSource.set('documentId', documentId);\n strapiSource.set('type', type);\n strapiSource.set('path', path);\n\n if (model) {\n strapiSource.set('model', model);\n }\n if (kind) {\n strapiSource.set('kind', kind);\n }\n if (locale) {\n strapiSource.set('locale', locale);\n }\n\n return vercelStegaCombine(text, { strapiSource: strapiSource.toString() });\n },\n\n async encodeEntry({ data, schema }: EncodingInfo): Promise<any> {\n if (!isObject(data) || data === undefined) {\n return data;\n }\n\n return traverseEntity(\n ({ key, value, attribute, schema, path }, { set }) => {\n if (!attribute || EXCLUDED_FIELDS.includes(key)) {\n return;\n }\n\n if (ENCODABLE_TYPES.includes(attribute.type) && typeof value === 'string') {\n set(\n key,\n this.encodeField(value, {\n path: path.rawWithIndices!,\n type: attribute.type,\n kind: schema.kind,\n model: schema.uid as UID.Schema,\n locale: data.locale,\n documentId: data.documentId,\n }) as any\n );\n }\n },\n {\n schema,\n getModel: (uid) => strapi.getModel(uid as UID.Schema),\n },\n data\n );\n },\n\n async encodeSourceMaps({ data, schema }: EncodingInfo): Promise<any> {\n try {\n if (Array.isArray(data)) {\n return await Promise.all(\n data.map((item) => this.encodeSourceMaps({ data: item, schema }))\n );\n }\n\n if (!isObject(data)) {\n return data;\n }\n\n return await this.encodeEntry({ data, schema });\n } catch (error) {\n strapi.log.error('Error encoding source maps:', error);\n return data;\n }\n },\n };\n};\n\nexport { createContentSourceMapsService };\n"],"names":["ENCODABLE_TYPES","EXCLUDED_FIELDS","isObject","value","createContentSourceMapsService","strapi","encodeField","text","kind","model","documentId","type","path","locale","strapiSource","URLSearchParams","set","vercelStegaCombine","toString","encodeEntry","data","schema","undefined","traverseEntity","key","attribute","includes","rawWithIndices","uid","getModel","encodeSourceMaps","Array","isArray","Promise","all","map","item","error","log"],"mappings":";;;;;AAKA,MAAMA,eAAkB,GAAA;AACtB,IAAA,QAAA;AACA,IAAA,MAAA;AACA,IAAA,UAAA;AACA,IAAA,YAAA;AACA,IAAA,MAAA;AACA,IAAA,MAAA;AACA,IAAA,UAAA;AACA,IAAA,WAAA;AACA,IAAA,SAAA;AACA,IAAA,aAAA;AACA,IAAA,MAAA;AACA,IAAA,OAAA;AACA,IAAA,OAAA;AACA,IAAA;AASD,CAAA;AAED;AACA,MAAMC,eAAkB,GAAA;AACtB,IAAA,IAAA;AACA,IAAA,YAAA;AACA,IAAA,QAAA;AACA,IAAA,eAAA;AACA,IAAA,YAAA;AACA,IAAA,YAAA;AACA,IAAA,YAAA;AACA,IAAA,YAAA;AACA,IAAA;AACD,CAAA;AAOD,MAAMC,WAAW,CAACC,KAAAA,GAAAA;IAChB,OAAO,OAAOA,KAAU,KAAA,QAAA,IAAYA,KAAU,KAAA,IAAA;AAChD,CAAA;A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AAA,CAAE,OAAOgB,KAAO,EAAA;AACdhC,gBAAAA,MAAAA,CAAOiC,GAAG,CAACD,KAAK,CAAC,6BAA+BA,EAAAA,KAAAA,CAAAA;gBAChD,OAAOjB,IAAAA;AACT;AACF;AACF,KAAA;AACF;;;;"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { vercelStegaCombine } from '@vercel/stega';
|
|
2
|
+
import { traverseEntity } from '@strapi/utils';
|
|
3
|
+
|
|
4
|
+
const ENCODABLE_TYPES = [
|
|
5
|
+
'string',
|
|
6
|
+
'text',
|
|
7
|
+
'richtext',
|
|
8
|
+
'biginteger',
|
|
9
|
+
'date',
|
|
10
|
+
'time',
|
|
11
|
+
'datetime',
|
|
12
|
+
'timestamp',
|
|
13
|
+
'boolean',
|
|
14
|
+
'enumeration',
|
|
15
|
+
'json',
|
|
16
|
+
'media',
|
|
17
|
+
'email',
|
|
18
|
+
'password'
|
|
19
|
+
];
|
|
20
|
+
// TODO: use a centralized store for these fields that would be shared with the CM and CTB
|
|
21
|
+
const EXCLUDED_FIELDS = [
|
|
22
|
+
'id',
|
|
23
|
+
'documentId',
|
|
24
|
+
'locale',
|
|
25
|
+
'localizations',
|
|
26
|
+
'created_by',
|
|
27
|
+
'updated_by',
|
|
28
|
+
'created_at',
|
|
29
|
+
'updated_at',
|
|
30
|
+
'publishedAt'
|
|
31
|
+
];
|
|
32
|
+
const isObject = (value)=>{
|
|
33
|
+
return typeof value === 'object' && value !== null;
|
|
34
|
+
};
|
|
35
|
+
const createContentSourceMapsService = (strapi)=>{
|
|
36
|
+
return {
|
|
37
|
+
encodeField (text, { kind, model, documentId, type, path, locale }) {
|
|
38
|
+
/**
|
|
39
|
+
* Combine all metadata into into a one string so we only have to deal with one data-atribute
|
|
40
|
+
* on the frontend. Make it human readable because that data-attribute may be set manually by
|
|
41
|
+
* users for fields that don't support sourcemap encoding.
|
|
42
|
+
*/ const strapiSource = new URLSearchParams();
|
|
43
|
+
strapiSource.set('documentId', documentId);
|
|
44
|
+
strapiSource.set('type', type);
|
|
45
|
+
strapiSource.set('path', path);
|
|
46
|
+
if (model) {
|
|
47
|
+
strapiSource.set('model', model);
|
|
48
|
+
}
|
|
49
|
+
if (kind) {
|
|
50
|
+
strapiSource.set('kind', kind);
|
|
51
|
+
}
|
|
52
|
+
if (locale) {
|
|
53
|
+
strapiSource.set('locale', locale);
|
|
54
|
+
}
|
|
55
|
+
return vercelStegaCombine(text, {
|
|
56
|
+
strapiSource: strapiSource.toString()
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
async encodeEntry ({ data, schema }) {
|
|
60
|
+
if (!isObject(data) || data === undefined) {
|
|
61
|
+
return data;
|
|
62
|
+
}
|
|
63
|
+
return traverseEntity(({ key, value, attribute, schema, path }, { set })=>{
|
|
64
|
+
if (!attribute || EXCLUDED_FIELDS.includes(key)) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (ENCODABLE_TYPES.includes(attribute.type) && typeof value === 'string') {
|
|
68
|
+
set(key, this.encodeField(value, {
|
|
69
|
+
path: path.rawWithIndices,
|
|
70
|
+
type: attribute.type,
|
|
71
|
+
kind: schema.kind,
|
|
72
|
+
model: schema.uid,
|
|
73
|
+
locale: data.locale,
|
|
74
|
+
documentId: data.documentId
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
}, {
|
|
78
|
+
schema,
|
|
79
|
+
getModel: (uid)=>strapi.getModel(uid)
|
|
80
|
+
}, data);
|
|
81
|
+
},
|
|
82
|
+
async encodeSourceMaps ({ data, schema }) {
|
|
83
|
+
try {
|
|
84
|
+
if (Array.isArray(data)) {
|
|
85
|
+
return await Promise.all(data.map((item)=>this.encodeSourceMaps({
|
|
86
|
+
data: item,
|
|
87
|
+
schema
|
|
88
|
+
})));
|
|
89
|
+
}
|
|
90
|
+
if (!isObject(data)) {
|
|
91
|
+
return data;
|
|
92
|
+
}
|
|
93
|
+
return await this.encodeEntry({
|
|
94
|
+
data,
|
|
95
|
+
schema
|
|
96
|
+
});
|
|
97
|
+
} catch (error) {
|
|
98
|
+
strapi.log.error('Error encoding source maps:', error);
|
|
99
|
+
return data;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export { createContentSourceMapsService };
|
|
106
|
+
//# sourceMappingURL=content-source-maps.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-source-maps.mjs","sources":["../../src/services/content-source-maps.ts"],"sourcesContent":["import { vercelStegaCombine } from '@vercel/stega';\nimport type { Core, Struct, UID } from '@strapi/types';\nimport { traverseEntity } from '@strapi/utils';\nimport type { FieldContentSourceMap } from '@strapi/admin/strapi-admin';\n\nconst ENCODABLE_TYPES = [\n 'string',\n 'text',\n 'richtext',\n 'biginteger',\n 'date',\n 'time',\n 'datetime',\n 'timestamp',\n 'boolean',\n 'enumeration',\n 'json',\n 'media',\n 'email',\n 'password',\n /**\n * We cannot modify the response shape, so types that aren't based on string cannot be encoded:\n * - json: object\n * - blocks: object, will require a custom implementation in a dedicated PR\n * - integer, float and decimal: number\n * - boolean: boolean (believe it or not)\n * - uid: can be stringified but would mess up URLs\n */\n];\n\n// TODO: use a centralized store for these fields that would be shared with the CM and CTB\nconst EXCLUDED_FIELDS = [\n 'id',\n 'documentId',\n 'locale',\n 'localizations',\n 'created_by',\n 'updated_by',\n 'created_at',\n 'updated_at',\n 'publishedAt',\n];\n\ninterface EncodingInfo {\n data: any;\n schema: Struct.Schema;\n}\n\nconst isObject = (value: unknown): value is Record<string, any> => {\n return typeof value === 'object' && value !== null;\n};\n\nconst createContentSourceMapsService = (strapi: Core.Strapi) => {\n return {\n encodeField(\n text: string,\n { kind, model, documentId, type, path, locale }: FieldContentSourceMap\n ) {\n /**\n * Combine all metadata into into a one string so we only have to deal with one data-atribute\n * on the frontend. Make it human readable because that data-attribute may be set manually by\n * users for fields that don't support sourcemap encoding.\n */\n const strapiSource = new URLSearchParams();\n strapiSource.set('documentId', documentId);\n strapiSource.set('type', type);\n strapiSource.set('path', path);\n\n if (model) {\n strapiSource.set('model', model);\n }\n if (kind) {\n strapiSource.set('kind', kind);\n }\n if (locale) {\n strapiSource.set('locale', locale);\n }\n\n return vercelStegaCombine(text, { strapiSource: strapiSource.toString() });\n },\n\n async encodeEntry({ data, schema }: EncodingInfo): Promise<any> {\n if (!isObject(data) || data === undefined) {\n return data;\n }\n\n return traverseEntity(\n ({ key, value, attribute, schema, path }, { set }) => {\n if (!attribute || EXCLUDED_FIELDS.includes(key)) {\n return;\n }\n\n if (ENCODABLE_TYPES.includes(attribute.type) && typeof value === 'string') {\n set(\n key,\n this.encodeField(value, {\n path: path.rawWithIndices!,\n type: attribute.type,\n kind: schema.kind,\n model: schema.uid as UID.Schema,\n locale: data.locale,\n documentId: data.documentId,\n }) as any\n );\n }\n },\n {\n schema,\n getModel: (uid) => strapi.getModel(uid as UID.Schema),\n },\n data\n );\n },\n\n async encodeSourceMaps({ data, schema }: EncodingInfo): Promise<any> {\n try {\n if (Array.isArray(data)) {\n return await Promise.all(\n data.map((item) => this.encodeSourceMaps({ data: item, schema }))\n );\n }\n\n if (!isObject(data)) {\n return data;\n }\n\n return await this.encodeEntry({ data, schema });\n } catch (error) {\n strapi.log.error('Error encoding source maps:', error);\n return data;\n }\n },\n };\n};\n\nexport { createContentSourceMapsService };\n"],"names":["ENCODABLE_TYPES","EXCLUDED_FIELDS","isObject","value","createContentSourceMapsService","strapi","encodeField","text","kind","model","documentId","type","path","locale","strapiSource","URLSearchParams","set","vercelStegaCombine","toString","encodeEntry","data","schema","undefined","traverseEntity","key","attribute","includes","rawWithIndices","uid","getModel","encodeSourceMaps","Array","isArray","Promise","all","map","item","error","log"],"mappings":";;;AAKA,MAAMA,eAAkB,GAAA;AACtB,IAAA,QAAA;AACA,IAAA,MAAA;AACA,IAAA,UAAA;AACA,IAAA,YAAA;AACA,IAAA,MAAA;AACA,IAAA,MAAA;AACA,IAAA,UAAA;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O,CAACZ,IAAO,CAAA,EAAA;AACvB,oBAAA,OAAO,MAAMa,OAAAA,CAAQC,GAAG,CACtBd,IAAKe,CAAAA,GAAG,CAAC,CAACC,IAAS,GAAA,IAAI,CAACN,gBAAgB,CAAC;4BAAEV,IAAMgB,EAAAA,IAAAA;AAAMf,4BAAAA;AAAO,yBAAA,CAAA,CAAA,CAAA;AAElE;gBAEA,IAAI,CAACnB,SAASkB,IAAO,CAAA,EAAA;oBACnB,OAAOA,IAAAA;AACT;AAEA,gBAAA,OAAO,MAAM,IAAI,CAACD,WAAW,CAAC;AAAEC,oBAAAA,IAAAA;AAAMC,oBAAAA;AAAO,iBAAA,CAAA;AAC/C,aAAA,CAAE,OAAOgB,KAAO,EAAA;AACdhC,gBAAAA,MAAAA,CAAOiC,GAAG,CAACD,KAAK,CAAC,6BAA+BA,EAAAA,KAAAA,CAAAA;gBAChD,OAAOjB,IAAAA;AACT;AACF;AACF,KAAA;AACF;;;;"}
|
|
@@ -22,5 +22,35 @@ declare const deleteComponents: <TUID extends UID.Schema, TEntity extends Data.E
|
|
|
22
22
|
}) => Promise<void>;
|
|
23
23
|
declare const deleteComponent: <TUID extends `${string}.${string}`>(uid: TUID, componentToDelete: Data.Component<TUID>) => Promise<void>;
|
|
24
24
|
declare const assignComponentData: _.CurriedFunction3<import("@strapi/types/dist/struct").ComponentSchema | import("@strapi/types/dist/struct").ContentTypeSchema, ComponentBody, Input<UID.Schema>, ComponentBody & Partial<Input<UID.Schema>>>;
|
|
25
|
-
|
|
25
|
+
/** *************************
|
|
26
|
+
Component relation handling for document operations
|
|
27
|
+
************************** */
|
|
28
|
+
/**
|
|
29
|
+
* Find the parent entry of a component instance.
|
|
30
|
+
*
|
|
31
|
+
* Given a component model, a specific component instance id, and the list of
|
|
32
|
+
* possible parent content types (those that can embed this component),
|
|
33
|
+
* this function checks each parent's *_cmps join table to see if the component
|
|
34
|
+
* instance is linked to a parent entity.
|
|
35
|
+
*
|
|
36
|
+
* - Returns the parent uid, parent table name, and parent id if found.
|
|
37
|
+
* - Returns null if no parent relationship exists.
|
|
38
|
+
*/
|
|
39
|
+
declare const findComponentParent: (componentSchema: Schema.Component, componentId: number | string, parentSchemasForComponent: (Schema.ContentType | Schema.Component)[], opts?: {
|
|
40
|
+
trx?: any;
|
|
41
|
+
}) => Promise<{
|
|
42
|
+
uid: string;
|
|
43
|
+
table: string;
|
|
44
|
+
parentId: number | string;
|
|
45
|
+
} | null>;
|
|
46
|
+
/**
|
|
47
|
+
* Finds content types that contain the given component and have draft & publish enabled.
|
|
48
|
+
*/
|
|
49
|
+
declare const getParentSchemasForComponent: (componentSchema: Schema.Component) => Array<Schema.ContentType | Schema.Component>;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a filter function for component relations that can be passed to the generic
|
|
52
|
+
* unidirectional relations utility
|
|
53
|
+
*/
|
|
54
|
+
declare const createComponentRelationFilter: () => (relation: Record<string, any>, model: Schema.Component | Schema.ContentType, trx: any) => Promise<boolean>;
|
|
55
|
+
export { omitComponentData, assignComponentData, getComponents, createComponents, updateComponents, deleteComponents, deleteComponent, createComponentRelationFilter, findComponentParent, getParentSchemasForComponent, };
|
|
26
56
|
//# sourceMappingURL=components.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../../../src/services/document-service/components.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,OAAO,KAAK,EAAS,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../../../src/services/document-service/components.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,OAAO,KAAK,EAAS,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAUvE,KAAK,KAAK,CAAC,CAAC,SAAS,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CAAC;AAyDF,QAAA,MAAM,eAAe,4CACd,IAAI,qBACU,KAAK,SAAS,CAAC,IAAI,CAAC,kBAIxC,CAAC;AAEF,QAAA,MAAM,mBAAmB,+MAIxB,CAAC;AAEF;;6BAE6B;AAE7B;;;;;;;;;;GAUG;AACH,QAAA,MAAM,mBAAmB,oBACN,OAAO,SAAS,eACpB,MAAM,GAAG,MAAM,6BACD,CAAC,OAAO,WAAW,GAAG,OAAO,SAAS,CAAC,EAAE,SAC7D;IAAE,GAAG,CAAC,EAAE,GAAG,CAAA;CAAE,KACnB,QAAQ;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAAG,IAAI,CA0C1E,CAAC;AAEF;;GAEG;AACH,QAAA,MAAM,4BAA4B,oBACf,OAAO,SAAS,KAChC,MAAM,OAAO,WAAW,GAAG,OAAO,SAAS,CAa7C,CAAC;AAsDF;;;GAGG;AACH,QAAA,MAAM,6BAA6B,mBAErB,OAAO,MAAM,EAAE,GAAG,CAAC,SACtB,OAAO,SAAS,GAAG,OAAO,WAAW,OACvC,GAAG,KACP,QAAQ,OAAO,CAqBnB,CAAC;AAEF,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,6BAA6B,EAC7B,mBAAmB,EACnB,4BAA4B,GAC7B,CAAC"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var _ = require('lodash');
|
|
4
4
|
var fp = require('lodash/fp');
|
|
5
5
|
var strapiUtils = require('@strapi/utils');
|
|
6
|
+
var transformContentTypesToModels = require('../../utils/transform-content-types-to-models.js');
|
|
6
7
|
|
|
7
8
|
const omitComponentData = fp.curry((schema, data)=>{
|
|
8
9
|
const { attributes } = schema;
|
|
@@ -275,12 +276,120 @@ const deleteComponent = async (uid, componentToDelete)=>{
|
|
|
275
276
|
const assignComponentData = fp.curry((schema, componentData, data)=>{
|
|
276
277
|
return fp.pipe(omitComponentData(schema), fp.assign(componentData))(data);
|
|
277
278
|
});
|
|
279
|
+
/** *************************
|
|
280
|
+
Component relation handling for document operations
|
|
281
|
+
************************** */ /**
|
|
282
|
+
* Find the parent entry of a component instance.
|
|
283
|
+
*
|
|
284
|
+
* Given a component model, a specific component instance id, and the list of
|
|
285
|
+
* possible parent content types (those that can embed this component),
|
|
286
|
+
* this function checks each parent's *_cmps join table to see if the component
|
|
287
|
+
* instance is linked to a parent entity.
|
|
288
|
+
*
|
|
289
|
+
* - Returns the parent uid, parent table name, and parent id if found.
|
|
290
|
+
* - Returns null if no parent relationship exists.
|
|
291
|
+
*/ const findComponentParent = async (componentSchema, componentId, parentSchemasForComponent, opts)=>{
|
|
292
|
+
if (!componentSchema?.uid) return null;
|
|
293
|
+
const schemaBuilder = strapi.db.getSchemaConnection(opts?.trx);
|
|
294
|
+
const withTrx = (qb)=>opts?.trx ? qb.transacting(opts.trx) : qb;
|
|
295
|
+
for (const parent of parentSchemasForComponent){
|
|
296
|
+
if (!parent.collectionName) continue;
|
|
297
|
+
// Use the exact same functions that create the tables
|
|
298
|
+
const identifiers = strapi.db.metadata.identifiers;
|
|
299
|
+
const joinTableName = transformContentTypesToModels.getComponentJoinTableName(parent.collectionName, identifiers);
|
|
300
|
+
try {
|
|
301
|
+
const tableExists = await schemaBuilder.hasTable(joinTableName);
|
|
302
|
+
if (!tableExists) continue;
|
|
303
|
+
// Use the exact same functions that create the columns
|
|
304
|
+
const entityIdColumn = transformContentTypesToModels.getComponentJoinColumnEntityName(identifiers);
|
|
305
|
+
const componentIdColumn = transformContentTypesToModels.getComponentJoinColumnInverseName(identifiers);
|
|
306
|
+
const componentTypeColumn = transformContentTypesToModels.getComponentTypeColumn(identifiers);
|
|
307
|
+
const parentRow = await withTrx(strapi.db.getConnection(joinTableName)).where({
|
|
308
|
+
[componentIdColumn]: componentId,
|
|
309
|
+
[componentTypeColumn]: componentSchema.uid
|
|
310
|
+
}).first(entityIdColumn);
|
|
311
|
+
if (parentRow) {
|
|
312
|
+
return {
|
|
313
|
+
uid: parent.uid,
|
|
314
|
+
table: parent.collectionName,
|
|
315
|
+
parentId: parentRow[entityIdColumn]
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
} catch {
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return null;
|
|
323
|
+
};
|
|
324
|
+
/**
|
|
325
|
+
* Finds content types that contain the given component and have draft & publish enabled.
|
|
326
|
+
*/ const getParentSchemasForComponent = (componentSchema)=>{
|
|
327
|
+
// Find direct parents in contentTypes and components
|
|
328
|
+
return [
|
|
329
|
+
...Object.values(strapi.contentTypes),
|
|
330
|
+
...Object.values(strapi.components)
|
|
331
|
+
].filter((schema)=>{
|
|
332
|
+
if (!schema?.attributes) return false;
|
|
333
|
+
return Object.values(schema.attributes).some((attr)=>{
|
|
334
|
+
return attr.type === 'component' && attr.component === componentSchema.uid || attr.type === 'dynamiczone' && attr.components?.includes(componentSchema.uid);
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
};
|
|
338
|
+
/**
|
|
339
|
+
* Determines if a component relation should be propagated to a new document version
|
|
340
|
+
* when a document with draft and publish is updated.
|
|
341
|
+
*/ const shouldPropagateComponentRelationToNewVersion = async (componentRelation, componentSchema, parentSchemasForComponent, trx)=>{
|
|
342
|
+
// Get the component ID column name using the actual component model name
|
|
343
|
+
const componentIdColumn = strapi.db.metadata.identifiers.getJoinColumnAttributeIdName(_.snakeCase(componentSchema.modelName));
|
|
344
|
+
const componentId = componentRelation[componentIdColumn] ?? componentRelation.parentId;
|
|
345
|
+
const parent = await findComponentParent(componentSchema, componentId, parentSchemasForComponent, {
|
|
346
|
+
trx
|
|
347
|
+
});
|
|
348
|
+
// Keep relation if component has no parent entry
|
|
349
|
+
if (!parent?.uid) {
|
|
350
|
+
return true;
|
|
351
|
+
}
|
|
352
|
+
if (strapi.components[parent.uid]) {
|
|
353
|
+
// If the parent is a component, we need to check its parents recursively
|
|
354
|
+
const parentComponentSchema = strapi.components[parent.uid];
|
|
355
|
+
const grandParentSchemas = getParentSchemasForComponent(parentComponentSchema);
|
|
356
|
+
return shouldPropagateComponentRelationToNewVersion(parent, parentComponentSchema, grandParentSchemas, trx);
|
|
357
|
+
}
|
|
358
|
+
const parentContentType = strapi.contentTypes[parent.uid];
|
|
359
|
+
// Keep relation if parent doesn't have draft & publish enabled
|
|
360
|
+
if (!parentContentType?.options?.draftAndPublish) {
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
// Discard relation if parent has draft & publish enabled
|
|
364
|
+
return false;
|
|
365
|
+
};
|
|
366
|
+
/**
|
|
367
|
+
* Creates a filter function for component relations that can be passed to the generic
|
|
368
|
+
* unidirectional relations utility
|
|
369
|
+
*/ const createComponentRelationFilter = ()=>{
|
|
370
|
+
return async (relation, model, trx)=>{
|
|
371
|
+
// Only apply component-specific filtering for components
|
|
372
|
+
if (model.modelType !== 'component') {
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
375
|
+
const componentSchema = model;
|
|
376
|
+
const parentSchemas = getParentSchemasForComponent(componentSchema);
|
|
377
|
+
// Exit if no draft & publish parent types exist
|
|
378
|
+
if (parentSchemas.length === 0) {
|
|
379
|
+
return true;
|
|
380
|
+
}
|
|
381
|
+
return shouldPropagateComponentRelationToNewVersion(relation, componentSchema, parentSchemas, trx);
|
|
382
|
+
};
|
|
383
|
+
};
|
|
278
384
|
|
|
279
385
|
exports.assignComponentData = assignComponentData;
|
|
386
|
+
exports.createComponentRelationFilter = createComponentRelationFilter;
|
|
280
387
|
exports.createComponents = createComponents;
|
|
281
388
|
exports.deleteComponent = deleteComponent;
|
|
282
389
|
exports.deleteComponents = deleteComponents;
|
|
390
|
+
exports.findComponentParent = findComponentParent;
|
|
283
391
|
exports.getComponents = getComponents;
|
|
392
|
+
exports.getParentSchemasForComponent = getParentSchemasForComponent;
|
|
284
393
|
exports.omitComponentData = omitComponentData;
|
|
285
394
|
exports.updateComponents = updateComponents;
|
|
286
395
|
//# sourceMappingURL=components.js.map
|