@strapi/core 5.0.0-beta.1 → 5.0.0-beta.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.
Files changed (109) hide show
  1. package/dist/Strapi.d.ts +4 -11
  2. package/dist/Strapi.d.ts.map +1 -1
  3. package/dist/Strapi.js +9 -16
  4. package/dist/Strapi.js.map +1 -1
  5. package/dist/Strapi.mjs +9 -17
  6. package/dist/Strapi.mjs.map +1 -1
  7. package/dist/configuration/config-loader.d.ts.map +1 -1
  8. package/dist/configuration/config-loader.js +8 -5
  9. package/dist/configuration/config-loader.js.map +1 -1
  10. package/dist/configuration/config-loader.mjs +8 -5
  11. package/dist/configuration/config-loader.mjs.map +1 -1
  12. package/dist/factories.js.map +1 -1
  13. package/dist/factories.mjs.map +1 -1
  14. package/dist/index.d.ts +4 -2
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +8 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +10 -3
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/loaders/plugins/get-enabled-plugins.d.ts.map +1 -1
  21. package/dist/loaders/plugins/get-enabled-plugins.js +2 -1
  22. package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
  23. package/dist/loaders/plugins/get-enabled-plugins.mjs +2 -1
  24. package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
  25. package/dist/services/content-api/index.js +1 -1
  26. package/dist/services/content-api/index.js.map +1 -1
  27. package/dist/services/content-api/index.mjs +1 -1
  28. package/dist/services/content-api/index.mjs.map +1 -1
  29. package/dist/services/content-api/permissions/index.js +1 -1
  30. package/dist/services/content-api/permissions/index.js.map +1 -1
  31. package/dist/services/content-api/permissions/index.mjs +1 -1
  32. package/dist/services/content-api/permissions/index.mjs.map +1 -1
  33. package/dist/services/document-service/index.d.ts.map +1 -1
  34. package/dist/services/document-service/index.js +4 -0
  35. package/dist/services/document-service/index.js.map +1 -1
  36. package/dist/services/document-service/index.mjs +4 -0
  37. package/dist/services/document-service/index.mjs.map +1 -1
  38. package/dist/services/document-service/repository.d.ts.map +1 -1
  39. package/dist/services/document-service/repository.js +11 -1
  40. package/dist/services/document-service/repository.js.map +1 -1
  41. package/dist/services/document-service/repository.mjs +11 -1
  42. package/dist/services/document-service/repository.mjs.map +1 -1
  43. package/dist/services/document-service/transform/data.d.ts.map +1 -1
  44. package/dist/services/document-service/transform/data.js +4 -2
  45. package/dist/services/document-service/transform/data.js.map +1 -1
  46. package/dist/services/document-service/transform/data.mjs +4 -2
  47. package/dist/services/document-service/transform/data.mjs.map +1 -1
  48. package/dist/services/document-service/transform/relations/extract/data-ids.d.ts +8 -7
  49. package/dist/services/document-service/transform/relations/extract/data-ids.d.ts.map +1 -1
  50. package/dist/services/document-service/transform/relations/extract/data-ids.js +42 -78
  51. package/dist/services/document-service/transform/relations/extract/data-ids.js.map +1 -1
  52. package/dist/services/document-service/transform/relations/extract/data-ids.mjs +42 -78
  53. package/dist/services/document-service/transform/relations/extract/data-ids.mjs.map +1 -1
  54. package/dist/services/document-service/transform/relations/transform/data-ids.d.ts +7 -3
  55. package/dist/services/document-service/transform/relations/transform/data-ids.d.ts.map +1 -1
  56. package/dist/services/document-service/transform/relations/transform/data-ids.js +57 -125
  57. package/dist/services/document-service/transform/relations/transform/data-ids.js.map +1 -1
  58. package/dist/services/document-service/transform/relations/transform/data-ids.mjs +58 -126
  59. package/dist/services/document-service/transform/relations/transform/data-ids.mjs.map +1 -1
  60. package/dist/services/document-service/transform/relations/transform/default-locale.d.ts +9 -0
  61. package/dist/services/document-service/transform/relations/transform/default-locale.d.ts.map +1 -0
  62. package/dist/services/document-service/transform/relations/transform/default-locale.js +32 -0
  63. package/dist/services/document-service/transform/relations/transform/default-locale.js.map +1 -0
  64. package/dist/services/document-service/transform/relations/transform/default-locale.mjs +32 -0
  65. package/dist/services/document-service/transform/relations/transform/default-locale.mjs.map +1 -0
  66. package/dist/services/document-service/transform/relations/utils/i18n.d.ts +2 -2
  67. package/dist/services/document-service/transform/relations/utils/i18n.d.ts.map +1 -1
  68. package/dist/services/document-service/transform/relations/utils/i18n.js +3 -9
  69. package/dist/services/document-service/transform/relations/utils/i18n.js.map +1 -1
  70. package/dist/services/document-service/transform/relations/utils/i18n.mjs +3 -9
  71. package/dist/services/document-service/transform/relations/utils/i18n.mjs.map +1 -1
  72. package/dist/services/document-service/transform/relations/utils/map-relation.d.ts +6 -0
  73. package/dist/services/document-service/transform/relations/utils/map-relation.d.ts.map +1 -0
  74. package/dist/services/document-service/transform/relations/utils/map-relation.js +87 -0
  75. package/dist/services/document-service/transform/relations/utils/map-relation.js.map +1 -0
  76. package/dist/services/document-service/transform/relations/utils/map-relation.mjs +87 -0
  77. package/dist/services/document-service/transform/relations/utils/map-relation.mjs.map +1 -0
  78. package/dist/services/document-service/transform/relations/utils/types.d.ts +6 -0
  79. package/dist/services/document-service/transform/relations/utils/types.d.ts.map +1 -1
  80. package/dist/services/entity-service/components.d.ts.map +1 -1
  81. package/dist/services/entity-service/components.js +1 -4
  82. package/dist/services/entity-service/components.js.map +1 -1
  83. package/dist/services/entity-service/components.mjs +1 -4
  84. package/dist/services/entity-service/components.mjs.map +1 -1
  85. package/dist/services/entity-validator/index.d.ts.map +1 -1
  86. package/dist/services/entity-validator/index.js +93 -87
  87. package/dist/services/entity-validator/index.js.map +1 -1
  88. package/dist/services/entity-validator/index.mjs +93 -87
  89. package/dist/services/entity-validator/index.mjs.map +1 -1
  90. package/dist/services/metrics/rate-limiter.d.ts.map +1 -1
  91. package/dist/services/metrics/rate-limiter.js.map +1 -1
  92. package/dist/services/metrics/rate-limiter.mjs.map +1 -1
  93. package/dist/services/server/register-routes.js +2 -2
  94. package/dist/services/server/register-routes.js.map +1 -1
  95. package/dist/services/server/register-routes.mjs +2 -2
  96. package/dist/services/server/register-routes.mjs.map +1 -1
  97. package/dist/utils/transform-content-types-to-models.d.ts +21 -16
  98. package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
  99. package/dist/utils/transform-content-types-to-models.js +95 -57
  100. package/dist/utils/transform-content-types-to-models.js.map +1 -1
  101. package/dist/utils/transform-content-types-to-models.mjs +95 -57
  102. package/dist/utils/transform-content-types-to-models.mjs.map +1 -1
  103. package/package.json +15 -15
  104. package/dist/services/document-service/transform/relations/transform/output-ids.d.ts +0 -2
  105. package/dist/services/document-service/transform/relations/transform/output-ids.d.ts.map +0 -1
  106. package/dist/services/document-service/transform/relations/utils/data.js +0 -12
  107. package/dist/services/document-service/transform/relations/utils/data.js.map +0 -1
  108. package/dist/services/document-service/transform/relations/utils/data.mjs +0 -12
  109. package/dist/services/document-service/transform/relations/utils/data.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"rate-limiter.js","sources":["../../../src/services/metrics/rate-limiter.ts"],"sourcesContent":["import type { Sender } from './sender';\n\ninterface Options {\n limitedEvents?: string[];\n}\n\ntype TailParams<T extends (...args: any[]) => any> = Parameters<T> extends [unknown, ...infer U]\n ? U\n : never;\n\nexport default (sender: Sender, { limitedEvents = [] }: Options = {}) => {\n let currentDay = new Date().getDate();\n const eventCache = new Map();\n\n return async (event: string, ...args: TailParams<Sender>) => {\n if (!limitedEvents.includes(event)) {\n return sender(event, ...args);\n }\n\n if (new Date().getDate() !== currentDay) {\n eventCache.clear();\n currentDay = new Date().getDate();\n }\n\n if (eventCache.has(event)) {\n return false;\n }\n\n eventCache.set(event, true);\n return sender(event, ...args);\n };\n};\n"],"names":[],"mappings":";AAUA,MAAe,oBAAA,CAAC,QAAgB,EAAE,gBAAgB,CAAG,EAAA,IAAa,CAAA,MAAO;AACvE,MAAI,cAAa,oBAAI,KAAK,GAAE,QAAQ;AAC9B,QAAA,iCAAiB;AAEhB,SAAA,OAAO,UAAkB,SAA6B;AAC3D,QAAI,CAAC,cAAc,SAAS,KAAK,GAAG;AAC3B,aAAA,OAAO,OAAO,GAAG,IAAI;AAAA,IAC9B;AAEA,SAAQ,oBAAA,KAAA,GAAO,QAAA,MAAc,YAAY;AACvC,iBAAW,MAAM;AACJ,oBAAA,oBAAI,KAAK,GAAE,QAAQ;AAAA,IAClC;AAEI,QAAA,WAAW,IAAI,KAAK,GAAG;AAClB,aAAA;AAAA,IACT;AAEW,eAAA,IAAI,OAAO,IAAI;AACnB,WAAA,OAAO,OAAO,GAAG,IAAI;AAAA,EAAA;AAEhC;;"}
1
+ {"version":3,"file":"rate-limiter.js","sources":["../../../src/services/metrics/rate-limiter.ts"],"sourcesContent":["import type { Sender } from './sender';\n\ninterface Options {\n limitedEvents?: string[];\n}\n\ntype TailParams<T extends (...args: any[]) => any> =\n Parameters<T> extends [unknown, ...infer U] ? U : never;\n\nexport default (sender: Sender, { limitedEvents = [] }: Options = {}) => {\n let currentDay = new Date().getDate();\n const eventCache = new Map();\n\n return async (event: string, ...args: TailParams<Sender>) => {\n if (!limitedEvents.includes(event)) {\n return sender(event, ...args);\n }\n\n if (new Date().getDate() !== currentDay) {\n eventCache.clear();\n currentDay = new Date().getDate();\n }\n\n if (eventCache.has(event)) {\n return false;\n }\n\n eventCache.set(event, true);\n return sender(event, ...args);\n };\n};\n"],"names":[],"mappings":";AASA,MAAe,oBAAA,CAAC,QAAgB,EAAE,gBAAgB,CAAG,EAAA,IAAa,CAAA,MAAO;AACvE,MAAI,cAAa,oBAAI,KAAK,GAAE,QAAQ;AAC9B,QAAA,iCAAiB;AAEhB,SAAA,OAAO,UAAkB,SAA6B;AAC3D,QAAI,CAAC,cAAc,SAAS,KAAK,GAAG;AAC3B,aAAA,OAAO,OAAO,GAAG,IAAI;AAAA,IAC9B;AAEA,SAAQ,oBAAA,KAAA,GAAO,QAAA,MAAc,YAAY;AACvC,iBAAW,MAAM;AACJ,oBAAA,oBAAI,KAAK,GAAE,QAAQ;AAAA,IAClC;AAEI,QAAA,WAAW,IAAI,KAAK,GAAG;AAClB,aAAA;AAAA,IACT;AAEW,eAAA,IAAI,OAAO,IAAI;AACnB,WAAA,OAAO,OAAO,GAAG,IAAI;AAAA,EAAA;AAEhC;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"rate-limiter.mjs","sources":["../../../src/services/metrics/rate-limiter.ts"],"sourcesContent":["import type { Sender } from './sender';\n\ninterface Options {\n limitedEvents?: string[];\n}\n\ntype TailParams<T extends (...args: any[]) => any> = Parameters<T> extends [unknown, ...infer U]\n ? U\n : never;\n\nexport default (sender: Sender, { limitedEvents = [] }: Options = {}) => {\n let currentDay = new Date().getDate();\n const eventCache = new Map();\n\n return async (event: string, ...args: TailParams<Sender>) => {\n if (!limitedEvents.includes(event)) {\n return sender(event, ...args);\n }\n\n if (new Date().getDate() !== currentDay) {\n eventCache.clear();\n currentDay = new Date().getDate();\n }\n\n if (eventCache.has(event)) {\n return false;\n }\n\n eventCache.set(event, true);\n return sender(event, ...args);\n };\n};\n"],"names":[],"mappings":"AAUA,MAAe,oBAAA,CAAC,QAAgB,EAAE,gBAAgB,CAAG,EAAA,IAAa,CAAA,MAAO;AACvE,MAAI,cAAa,oBAAI,KAAK,GAAE,QAAQ;AAC9B,QAAA,iCAAiB;AAEhB,SAAA,OAAO,UAAkB,SAA6B;AAC3D,QAAI,CAAC,cAAc,SAAS,KAAK,GAAG;AAC3B,aAAA,OAAO,OAAO,GAAG,IAAI;AAAA,IAC9B;AAEA,SAAQ,oBAAA,KAAA,GAAO,QAAA,MAAc,YAAY;AACvC,iBAAW,MAAM;AACJ,oBAAA,oBAAI,KAAK,GAAE,QAAQ;AAAA,IAClC;AAEI,QAAA,WAAW,IAAI,KAAK,GAAG;AAClB,aAAA;AAAA,IACT;AAEW,eAAA,IAAI,OAAO,IAAI;AACnB,WAAA,OAAO,OAAO,GAAG,IAAI;AAAA,EAAA;AAEhC;"}
1
+ {"version":3,"file":"rate-limiter.mjs","sources":["../../../src/services/metrics/rate-limiter.ts"],"sourcesContent":["import type { Sender } from './sender';\n\ninterface Options {\n limitedEvents?: string[];\n}\n\ntype TailParams<T extends (...args: any[]) => any> =\n Parameters<T> extends [unknown, ...infer U] ? U : never;\n\nexport default (sender: Sender, { limitedEvents = [] }: Options = {}) => {\n let currentDay = new Date().getDate();\n const eventCache = new Map();\n\n return async (event: string, ...args: TailParams<Sender>) => {\n if (!limitedEvents.includes(event)) {\n return sender(event, ...args);\n }\n\n if (new Date().getDate() !== currentDay) {\n eventCache.clear();\n currentDay = new Date().getDate();\n }\n\n if (eventCache.has(event)) {\n return false;\n }\n\n eventCache.set(event, true);\n return sender(event, ...args);\n };\n};\n"],"names":[],"mappings":"AASA,MAAe,oBAAA,CAAC,QAAgB,EAAE,gBAAgB,CAAG,EAAA,IAAa,CAAA,MAAO;AACvE,MAAI,cAAa,oBAAI,KAAK,GAAE,QAAQ;AAC9B,QAAA,iCAAiB;AAEhB,SAAA,OAAO,UAAkB,SAA6B;AAC3D,QAAI,CAAC,cAAc,SAAS,KAAK,GAAG;AAC3B,aAAA,OAAO,OAAO,GAAG,IAAI;AAAA,IAC9B;AAEA,SAAQ,oBAAA,KAAA,GAAO,QAAA,MAAc,YAAY;AACvC,iBAAW,MAAM;AACJ,oBAAA,oBAAI,KAAK,GAAE,QAAQ;AAAA,IAClC;AAEI,QAAA,WAAW,IAAI,KAAK,GAAG;AAClB,aAAA;AAAA,IACT;AAEW,eAAA,IAAI,OAAO,IAAI;AACnB,WAAA,OAAO,OAAO,GAAG,IAAI;AAAA,EAAA;AAEhC;"}
@@ -59,8 +59,8 @@ const registerPluginRoutes = (strapi) => {
59
59
  }
60
60
  };
61
61
  const registerAPIRoutes = (strapi) => {
62
- for (const apiName of Object.keys(strapi.api)) {
63
- const api = strapi.api[apiName];
62
+ for (const apiName of Object.keys(strapi.apis)) {
63
+ const api = strapi.api(apiName);
64
64
  const generateRouteScope = createRouteScopeGenerator(`api::${apiName}`);
65
65
  ___default.default.forEach(api.routes, (router) => {
66
66
  router.type = "content-api";
@@ -1 +1 @@
1
- {"version":3,"file":"register-routes.js","sources":["../../../src/services/server/register-routes.ts"],"sourcesContent":["import _ from 'lodash';\nimport type { Core } from '@strapi/types';\n\nconst createRouteScopeGenerator = (namespace: string) => (route: Core.RouteInput) => {\n const prefix = namespace.endsWith('::') ? namespace : `${namespace}.`;\n\n if (typeof route.handler === 'string') {\n _.defaultsDeep(route, {\n config: {\n auth: {\n scope: [`${route.handler.startsWith(prefix) ? '' : prefix}${route.handler}`],\n },\n },\n });\n }\n};\n\n/**\n * Register all routes\n */\nexport default (strapi: Core.Strapi) => {\n registerAdminRoutes(strapi);\n registerAPIRoutes(strapi);\n registerPluginRoutes(strapi);\n};\n\n/**\n * Register admin routes\n * @param {import('../../').Strapi} strapi\n */\nconst registerAdminRoutes = (strapi: Core.Strapi) => {\n const generateRouteScope = createRouteScopeGenerator(`admin::`);\n\n _.forEach(strapi.admin?.routes, (router) => {\n router.type = router.type || 'admin';\n router.prefix = router.prefix || `/admin`;\n router.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName: 'admin' };\n });\n strapi.server.routes(router);\n });\n};\n\n/**\n * Register plugin routes\n * @param {import('../../').Strapi} strapi\n */\nconst registerPluginRoutes = (strapi: Core.Strapi) => {\n for (const pluginName of Object.keys(strapi.plugins)) {\n const plugin = strapi.plugins[pluginName];\n\n const generateRouteScope = createRouteScopeGenerator(`plugin::${pluginName}`);\n\n if (Array.isArray(plugin.routes)) {\n plugin.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName };\n });\n\n strapi.server.routes({\n type: 'admin',\n prefix: `/${pluginName}`,\n routes: plugin.routes,\n });\n } else {\n _.forEach(plugin.routes, (router) => {\n router.type = router.type || 'admin';\n router.prefix = router.prefix || `/${pluginName}`;\n router.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName };\n });\n\n strapi.server.routes(router);\n });\n }\n }\n};\n\n/**\n * Register api routes\n */\nconst registerAPIRoutes = (strapi: Core.Strapi) => {\n for (const apiName of Object.keys(strapi.api)) {\n const api = strapi.api[apiName];\n\n const generateRouteScope = createRouteScopeGenerator(`api::${apiName}`);\n\n _.forEach(api.routes, (router) => {\n // TODO: remove once auth setup\n // pass meta down to compose endpoint\n router.type = 'content-api';\n router.routes?.forEach((route) => {\n generateRouteScope(route);\n route.info = { apiName };\n });\n\n return strapi.server.routes(router);\n });\n }\n};\n"],"names":["_"],"mappings":";;;;AAGA,MAAM,4BAA4B,CAAC,cAAsB,CAAC,UAA2B;AACnF,QAAM,SAAS,UAAU,SAAS,IAAI,IAAI,YAAY,GAAG,SAAS;AAE9D,MAAA,OAAO,MAAM,YAAY,UAAU;AACrCA,eAAA,QAAE,aAAa,OAAO;AAAA,MACpB,QAAQ;AAAA,QACN,MAAM;AAAA,UACJ,OAAO,CAAC,GAAG,MAAM,QAAQ,WAAW,MAAM,IAAI,KAAK,MAAM,GAAG,MAAM,OAAO,EAAE;AAAA,QAC7E;AAAA,MACF;AAAA,IAAA,CACD;AAAA,EACH;AACF;AAKA,MAAe,oBAAA,CAAC,WAAwB;AACtC,sBAAoB,MAAM;AAC1B,oBAAkB,MAAM;AACxB,uBAAqB,MAAM;AAC7B;AAMA,MAAM,sBAAsB,CAAC,WAAwB;AAC7C,QAAA,qBAAqB,0BAA0B,SAAS;AAE9DA,aAAA,QAAE,QAAQ,OAAO,OAAO,QAAQ,CAAC,WAAW;AACnC,WAAA,OAAO,OAAO,QAAQ;AACtB,WAAA,SAAS,OAAO,UAAU;AAC1B,WAAA,OAAO,QAAQ,CAAC,UAAU;AAC/B,yBAAmB,KAAK;AAClB,YAAA,OAAO,EAAE,YAAY,QAAQ;AAAA,IAAA,CACpC;AACM,WAAA,OAAO,OAAO,MAAM;AAAA,EAAA,CAC5B;AACH;AAMA,MAAM,uBAAuB,CAAC,WAAwB;AACpD,aAAW,cAAc,OAAO,KAAK,OAAO,OAAO,GAAG;AAC9C,UAAA,SAAS,OAAO,QAAQ,UAAU;AAExC,UAAM,qBAAqB,0BAA0B,WAAW,UAAU,EAAE;AAE5E,QAAI,MAAM,QAAQ,OAAO,MAAM,GAAG;AACzB,aAAA,OAAO,QAAQ,CAAC,UAAU;AAC/B,2BAAmB,KAAK;AAClB,cAAA,OAAO,EAAE;MAAW,CAC3B;AAED,aAAO,OAAO,OAAO;AAAA,QACnB,MAAM;AAAA,QACN,QAAQ,IAAI,UAAU;AAAA,QACtB,QAAQ,OAAO;AAAA,MAAA,CAChB;AAAA,IAAA,OACI;AACLA,iBAAAA,QAAE,QAAQ,OAAO,QAAQ,CAAC,WAAW;AAC5B,eAAA,OAAO,OAAO,QAAQ;AAC7B,eAAO,SAAS,OAAO,UAAU,IAAI,UAAU;AACxC,eAAA,OAAO,QAAQ,CAAC,UAAU;AAC/B,6BAAmB,KAAK;AAClB,gBAAA,OAAO,EAAE;QAAW,CAC3B;AAEM,eAAA,OAAO,OAAO,MAAM;AAAA,MAAA,CAC5B;AAAA,IACH;AAAA,EACF;AACF;AAKA,MAAM,oBAAoB,CAAC,WAAwB;AACjD,aAAW,WAAW,OAAO,KAAK,OAAO,GAAG,GAAG;AACvC,UAAA,MAAM,OAAO,IAAI,OAAO;AAE9B,UAAM,qBAAqB,0BAA0B,QAAQ,OAAO,EAAE;AAEtEA,eAAAA,QAAE,QAAQ,IAAI,QAAQ,CAAC,WAAW;AAGhC,aAAO,OAAO;AACP,aAAA,QAAQ,QAAQ,CAAC,UAAU;AAChC,2BAAmB,KAAK;AAClB,cAAA,OAAO,EAAE;MAAQ,CACxB;AAEM,aAAA,OAAO,OAAO,OAAO,MAAM;AAAA,IAAA,CACnC;AAAA,EACH;AACF;;"}
1
+ {"version":3,"file":"register-routes.js","sources":["../../../src/services/server/register-routes.ts"],"sourcesContent":["import _ from 'lodash';\nimport type { Core } from '@strapi/types';\n\nconst createRouteScopeGenerator = (namespace: string) => (route: Core.RouteInput) => {\n const prefix = namespace.endsWith('::') ? namespace : `${namespace}.`;\n\n if (typeof route.handler === 'string') {\n _.defaultsDeep(route, {\n config: {\n auth: {\n scope: [`${route.handler.startsWith(prefix) ? '' : prefix}${route.handler}`],\n },\n },\n });\n }\n};\n\n/**\n * Register all routes\n */\nexport default (strapi: Core.Strapi) => {\n registerAdminRoutes(strapi);\n registerAPIRoutes(strapi);\n registerPluginRoutes(strapi);\n};\n\n/**\n * Register admin routes\n * @param {import('../../').Strapi} strapi\n */\nconst registerAdminRoutes = (strapi: Core.Strapi) => {\n const generateRouteScope = createRouteScopeGenerator(`admin::`);\n\n _.forEach(strapi.admin?.routes, (router) => {\n router.type = router.type || 'admin';\n router.prefix = router.prefix || `/admin`;\n router.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName: 'admin' };\n });\n strapi.server.routes(router);\n });\n};\n\n/**\n * Register plugin routes\n * @param {import('../../').Strapi} strapi\n */\nconst registerPluginRoutes = (strapi: Core.Strapi) => {\n for (const pluginName of Object.keys(strapi.plugins)) {\n const plugin = strapi.plugins[pluginName];\n\n const generateRouteScope = createRouteScopeGenerator(`plugin::${pluginName}`);\n\n if (Array.isArray(plugin.routes)) {\n plugin.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName };\n });\n\n strapi.server.routes({\n type: 'admin',\n prefix: `/${pluginName}`,\n routes: plugin.routes,\n });\n } else {\n _.forEach(plugin.routes, (router) => {\n router.type = router.type || 'admin';\n router.prefix = router.prefix || `/${pluginName}`;\n router.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName };\n });\n\n strapi.server.routes(router);\n });\n }\n }\n};\n\n/**\n * Register api routes\n */\nconst registerAPIRoutes = (strapi: Core.Strapi) => {\n for (const apiName of Object.keys(strapi.apis)) {\n const api = strapi.api(apiName);\n\n const generateRouteScope = createRouteScopeGenerator(`api::${apiName}`);\n\n _.forEach(api.routes, (router) => {\n // TODO: remove once auth setup\n // pass meta down to compose endpoint\n router.type = 'content-api';\n router.routes?.forEach((route) => {\n generateRouteScope(route);\n route.info = { apiName };\n });\n\n return strapi.server.routes(router);\n });\n }\n};\n"],"names":["_"],"mappings":";;;;AAGA,MAAM,4BAA4B,CAAC,cAAsB,CAAC,UAA2B;AACnF,QAAM,SAAS,UAAU,SAAS,IAAI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AAW;AAC5B,eAAA,OAAO,OAAO,QAAQ;AAC7B,eAAO,SAAS,OAAO,UAAU,IAAI,UAAU;AACxC,eAAA,OAAO,QAAQ,CAAC,UAAU;AAC/B,6BAAmB,KAAK;AAClB,gBAAA,OAAO,EAAE;QAAW,CAC3B;AAEM,eAAA,OAAO,OAAO,MAAM;AAAA,MAAA,CAC5B;AAAA,IACH;AAAA,EACF;AACF;AAKA,MAAM,oBAAoB,CAAC,WAAwB;AACjD,aAAW,WAAW,OAAO,KAAK,OAAO,IAAI,GAAG;AACxC,UAAA,MAAM,OAAO,IAAI,OAAO;AAE9B,UAAM,qBAAqB,0BAA0B,QAAQ,OAAO,EAAE;AAEtEA,eAAAA,QAAE,QAAQ,IAAI,QAAQ,CAAC,WAAW;AAGhC,aAAO,OAAO;AACP,aAAA,QAAQ,QAAQ,CAAC,UAAU;AAChC,2BAAmB,KAAK;AAClB,cAAA,OAAO,EAAE;MAAQ,CACxB;AAEM,aAAA,OAAO,OAAO,OAAO,MAAM;AAAA,IAAA,CACnC;AAAA,EACH;AACF;;"}
@@ -56,8 +56,8 @@ const registerPluginRoutes = (strapi) => {
56
56
  }
57
57
  };
58
58
  const registerAPIRoutes = (strapi) => {
59
- for (const apiName of Object.keys(strapi.api)) {
60
- const api = strapi.api[apiName];
59
+ for (const apiName of Object.keys(strapi.apis)) {
60
+ const api = strapi.api(apiName);
61
61
  const generateRouteScope = createRouteScopeGenerator(`api::${apiName}`);
62
62
  _.forEach(api.routes, (router) => {
63
63
  router.type = "content-api";
@@ -1 +1 @@
1
- {"version":3,"file":"register-routes.mjs","sources":["../../../src/services/server/register-routes.ts"],"sourcesContent":["import _ from 'lodash';\nimport type { Core } from '@strapi/types';\n\nconst createRouteScopeGenerator = (namespace: string) => (route: Core.RouteInput) => {\n const prefix = namespace.endsWith('::') ? namespace : `${namespace}.`;\n\n if (typeof route.handler === 'string') {\n _.defaultsDeep(route, {\n config: {\n auth: {\n scope: [`${route.handler.startsWith(prefix) ? '' : prefix}${route.handler}`],\n },\n },\n });\n }\n};\n\n/**\n * Register all routes\n */\nexport default (strapi: Core.Strapi) => {\n registerAdminRoutes(strapi);\n registerAPIRoutes(strapi);\n registerPluginRoutes(strapi);\n};\n\n/**\n * Register admin routes\n * @param {import('../../').Strapi} strapi\n */\nconst registerAdminRoutes = (strapi: Core.Strapi) => {\n const generateRouteScope = createRouteScopeGenerator(`admin::`);\n\n _.forEach(strapi.admin?.routes, (router) => {\n router.type = router.type || 'admin';\n router.prefix = router.prefix || `/admin`;\n router.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName: 'admin' };\n });\n strapi.server.routes(router);\n });\n};\n\n/**\n * Register plugin routes\n * @param {import('../../').Strapi} strapi\n */\nconst registerPluginRoutes = (strapi: Core.Strapi) => {\n for (const pluginName of Object.keys(strapi.plugins)) {\n const plugin = strapi.plugins[pluginName];\n\n const generateRouteScope = createRouteScopeGenerator(`plugin::${pluginName}`);\n\n if (Array.isArray(plugin.routes)) {\n plugin.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName };\n });\n\n strapi.server.routes({\n type: 'admin',\n prefix: `/${pluginName}`,\n routes: plugin.routes,\n });\n } else {\n _.forEach(plugin.routes, (router) => {\n router.type = router.type || 'admin';\n router.prefix = router.prefix || `/${pluginName}`;\n router.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName };\n });\n\n strapi.server.routes(router);\n });\n }\n }\n};\n\n/**\n * Register api routes\n */\nconst registerAPIRoutes = (strapi: Core.Strapi) => {\n for (const apiName of Object.keys(strapi.api)) {\n const api = strapi.api[apiName];\n\n const generateRouteScope = createRouteScopeGenerator(`api::${apiName}`);\n\n _.forEach(api.routes, (router) => {\n // TODO: remove once auth setup\n // pass meta down to compose endpoint\n router.type = 'content-api';\n router.routes?.forEach((route) => {\n generateRouteScope(route);\n route.info = { apiName };\n });\n\n return strapi.server.routes(router);\n });\n }\n};\n"],"names":[],"mappings":";AAGA,MAAM,4BAA4B,CAAC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AAE,QAAQ,OAAO,QAAQ,CAAC,WAAW;AAC5B,eAAA,OAAO,OAAO,QAAQ;AAC7B,eAAO,SAAS,OAAO,UAAU,IAAI,UAAU;AACxC,eAAA,OAAO,QAAQ,CAAC,UAAU;AAC/B,6BAAmB,KAAK;AAClB,gBAAA,OAAO,EAAE;QAAW,CAC3B;AAEM,eAAA,OAAO,OAAO,MAAM;AAAA,MAAA,CAC5B;AAAA,IACH;AAAA,EACF;AACF;AAKA,MAAM,oBAAoB,CAAC,WAAwB;AACjD,aAAW,WAAW,OAAO,KAAK,OAAO,GAAG,GAAG;AACvC,UAAA,MAAM,OAAO,IAAI,OAAO;AAE9B,UAAM,qBAAqB,0BAA0B,QAAQ,OAAO,EAAE;AAEtE,MAAE,QAAQ,IAAI,QAAQ,CAAC,WAAW;AAGhC,aAAO,OAAO;AACP,aAAA,QAAQ,QAAQ,CAAC,UAAU;AAChC,2BAAmB,KAAK;AAClB,cAAA,OAAO,EAAE;MAAQ,CACxB;AAEM,aAAA,OAAO,OAAO,OAAO,MAAM;AAAA,IAAA,CACnC;AAAA,EACH;AACF;"}
1
+ {"version":3,"file":"register-routes.mjs","sources":["../../../src/services/server/register-routes.ts"],"sourcesContent":["import _ from 'lodash';\nimport type { Core } from '@strapi/types';\n\nconst createRouteScopeGenerator = (namespace: string) => (route: Core.RouteInput) => {\n const prefix = namespace.endsWith('::') ? namespace : `${namespace}.`;\n\n if (typeof route.handler === 'string') {\n _.defaultsDeep(route, {\n config: {\n auth: {\n scope: [`${route.handler.startsWith(prefix) ? '' : prefix}${route.handler}`],\n },\n },\n });\n }\n};\n\n/**\n * Register all routes\n */\nexport default (strapi: Core.Strapi) => {\n registerAdminRoutes(strapi);\n registerAPIRoutes(strapi);\n registerPluginRoutes(strapi);\n};\n\n/**\n * Register admin routes\n * @param {import('../../').Strapi} strapi\n */\nconst registerAdminRoutes = (strapi: Core.Strapi) => {\n const generateRouteScope = createRouteScopeGenerator(`admin::`);\n\n _.forEach(strapi.admin?.routes, (router) => {\n router.type = router.type || 'admin';\n router.prefix = router.prefix || `/admin`;\n router.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName: 'admin' };\n });\n strapi.server.routes(router);\n });\n};\n\n/**\n * Register plugin routes\n * @param {import('../../').Strapi} strapi\n */\nconst registerPluginRoutes = (strapi: Core.Strapi) => {\n for (const pluginName of Object.keys(strapi.plugins)) {\n const plugin = strapi.plugins[pluginName];\n\n const generateRouteScope = createRouteScopeGenerator(`plugin::${pluginName}`);\n\n if (Array.isArray(plugin.routes)) {\n plugin.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName };\n });\n\n strapi.server.routes({\n type: 'admin',\n prefix: `/${pluginName}`,\n routes: plugin.routes,\n });\n } else {\n _.forEach(plugin.routes, (router) => {\n router.type = router.type || 'admin';\n router.prefix = router.prefix || `/${pluginName}`;\n router.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName };\n });\n\n strapi.server.routes(router);\n });\n }\n }\n};\n\n/**\n * Register api routes\n */\nconst registerAPIRoutes = (strapi: Core.Strapi) => {\n for (const apiName of Object.keys(strapi.apis)) {\n const api = strapi.api(apiName);\n\n const generateRouteScope = createRouteScopeGenerator(`api::${apiName}`);\n\n _.forEach(api.routes, (router) => {\n // TODO: remove once auth setup\n // pass meta down to compose endpoint\n router.type = 'content-api';\n router.routes?.forEach((route) => {\n generateRouteScope(route);\n route.info = { apiName };\n });\n\n return strapi.server.routes(router);\n });\n }\n};\n"],"names":[],"mappings":";AAGA,MAAM,4BAA4B,CAAC,cAAsB,CAAC,UAA2B;AACnF,QAAM,SAAS,UAAU,SAAS,IAAI,IAAI,YAAY,GAAG,SAAS;AAE9D,MAAA,OAAO,MAAM,YAAY,UAAU;AACrC,MAAE,aAAa,OAAO;AAAA,MACpB,QAAQ;AAAA,QACN,MAAM;AAAA,UACJ,OAAO,CAAC,GAAG,MAAM,QAAQ,WAAW,MAAM,IAAI,KAAK,MAAM,GAAG,MAAM,OAAO,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AAAA,EACF;AACF;AAKA,MAAM,oBAAoB,CAAC,WAAwB;AACjD,aAAW,WAAW,OAAO,KAAK,OAAO,IAAI,GAAG;AACxC,UAAA,MAAM,OAAO,IAAI,OAAO;AAE9B,UAAM,qBAAqB,0BAA0B,QAAQ,OAAO,EAAE;AAEtE,MAAE,QAAQ,IAAI,QAAQ,CAAC,WAAW;AAGhC,aAAO,OAAO;AACP,aAAA,QAAQ,QAAQ,CAAC,UAAU;AAChC,2BAAmB,KAAK;AAClB,cAAA,OAAO,EAAE;MAAQ,CACxB;AAEM,aAAA,OAAO,OAAO,OAAO,MAAM;AAAA,IAAA,CACnC;AAAA,EACH;AACF;"}
@@ -1,4 +1,4 @@
1
- import { type Model } from '@strapi/database';
1
+ import { type Model, type Identifiers } from '@strapi/database';
2
2
  import type { Struct, Schema } from '@strapi/types';
3
3
  import { createId } from '@paralleldrive/cuid2';
4
4
  /**
@@ -6,16 +6,21 @@ import { createId } from '@paralleldrive/cuid2';
6
6
  * to a relations format that it recognizes
7
7
  *
8
8
  * Therefore we have to keep an additional set of helpers/extensions to the database naming methods
9
+ *
10
+ * IMPORTANT!
11
+ * If we use short versions of anything, we MUST call getNameFromTokens directly; attempting to shorten them ourselves
12
+ * prevents the unshortened name map from being filled properly, so for example it will think that the short name
13
+ * 'collection4f3a_cmps' maps to the unshortened 'collectionname_cmps' rather than 'collectionname_components'
14
+ * Therefore, we only use the identifiers helpers in cases where we do not do any of our own shortening
9
15
  */
10
- export declare const COMPONENT_JOIN_TABLE_SUFFIX = "components";
11
- export declare const DZ_JOIN_TABLE_SUFFIX = "components";
12
- export declare const COMPONENT_INVERSE_COLUMN_NAME = "component";
13
- export declare const COMPONENT_TYPE_COLUMN = "component_type";
14
- export declare const ENTITY = "entity";
15
- export declare const getComponentJoinTableName: (collectionName: string) => string;
16
- export declare const getDzJoinTableName: (collectionName: string) => string;
16
+ export declare const getComponentJoinTableName: (collectionName: string, identifiers: Identifiers) => string;
17
+ export declare const getDzJoinTableName: (collectionName: string, identifiers: Identifiers) => string;
18
+ export declare const getComponentJoinColumnEntityName: (identifiers: Identifiers) => string;
19
+ export declare const getComponentJoinColumnInverseName: (identifiers: Identifiers) => string;
20
+ export declare const getComponentTypeColumn: (identifiers: Identifiers) => string;
21
+ export declare const getComponentFkIndexName: (contentType: string, identifiers: Identifiers) => string;
17
22
  export type LoadedContentTypeModel = Struct.ContentTypeSchema & Required<Pick<Struct.ContentTypeSchema, 'collectionName' | 'uid' | 'modelName'>>;
18
- export declare const transformAttribute: (name: string, attribute: Schema.Attribute.AnyAttribute, contentType: LoadedContentTypeModel) => (Schema.Attribute.OfType<"biginteger"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxOption<string> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.UniqueOption) | (Schema.Attribute.OfType<"boolean"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<boolean> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"blocks"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"datetime"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<Schema.Attribute.DateTimeValue> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"date"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<Schema.Attribute.DateValue> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"decimal"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<number> & Schema.Attribute.MinMaxOption<number> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.UniqueOption) | (Schema.Attribute.OfType<"email"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"enumeration"> & Schema.Attribute.EnumerationProperties<string[]> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"float"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<number> & Schema.Attribute.MinMaxOption<number> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.UniqueOption) | (Schema.Attribute.OfType<"integer"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<number> & Schema.Attribute.MinMaxOption<number> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.UniqueOption) | (Schema.Attribute.OfType<"json"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.RequiredOption & Schema.Attribute.PrivateOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.DefaultOption<import("@strapi/types/dist/utils").JSONPrimitive>) | (Schema.Attribute.OfType<"password"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"relation"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.PrivateOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.RequiredOption & {
23
+ export declare const transformAttribute: (name: string, attribute: Schema.Attribute.AnyAttribute, contentType: LoadedContentTypeModel, identifiers: Identifiers) => (Schema.Attribute.OfType<"biginteger"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxOption<string> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.UniqueOption) | (Schema.Attribute.OfType<"boolean"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<boolean> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"blocks"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"datetime"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<Schema.Attribute.DateTimeValue> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"date"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<Schema.Attribute.DateValue> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"decimal"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<number> & Schema.Attribute.MinMaxOption<number> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.UniqueOption) | (Schema.Attribute.OfType<"email"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"enumeration"> & Schema.Attribute.EnumerationProperties<string[]> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"float"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<number> & Schema.Attribute.MinMaxOption<number> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.UniqueOption) | (Schema.Attribute.OfType<"integer"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<number> & Schema.Attribute.MinMaxOption<number> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.UniqueOption) | (Schema.Attribute.OfType<"json"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.RequiredOption & Schema.Attribute.PrivateOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.DefaultOption<import("@strapi/types/dist/utils").JSONPrimitive>) | (Schema.Attribute.OfType<"password"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"relation"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.PrivateOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.RequiredOption & {
19
24
  useJoinTable?: boolean | undefined;
20
25
  } & {
21
26
  relation: "morphToOne";
@@ -69,16 +74,16 @@ export declare const transformAttribute: (name: string, attribute: Schema.Attrib
69
74
  name: string;
70
75
  joinColumn: {
71
76
  name: string;
72
- referencedColumn: string;
77
+ referencedColumn: "id";
73
78
  };
74
79
  inverseJoinColumn: {
75
80
  name: string;
76
- referencedColumn: string;
81
+ referencedColumn: "id";
77
82
  };
78
83
  on: {
79
84
  field: string;
80
85
  };
81
- orderColumnName: string;
86
+ orderColumnName: "order";
82
87
  orderBy: {
83
88
  order: string;
84
89
  };
@@ -93,12 +98,12 @@ export declare const transformAttribute: (name: string, attribute: Schema.Attrib
93
98
  name: string;
94
99
  joinColumn: {
95
100
  name: string;
96
- referencedColumn: string;
101
+ referencedColumn: "id";
97
102
  };
98
103
  morphColumn: {
99
104
  idColumn: {
100
105
  name: string;
101
- referencedColumn: string;
106
+ referencedColumn: "id";
102
107
  };
103
108
  typeColumn: {
104
109
  name: string;
@@ -118,10 +123,10 @@ export declare const transformAttribute: (name: string, attribute: Schema.Attrib
118
123
  target?: undefined;
119
124
  morphBy?: undefined;
120
125
  };
121
- export declare const transformAttributes: (contentType: LoadedContentTypeModel) => {};
126
+ export declare const transformAttributes: (contentType: LoadedContentTypeModel, identifiers: Identifiers) => {};
122
127
  export declare const hasComponentsOrDz: (contentType: LoadedContentTypeModel) => contentType is Struct.ContentTypeSchema & Required<Pick<Struct.ContentTypeSchema, "uid" | "collectionName" | "modelName">> & {
123
128
  type: 'dynamiczone' | 'component';
124
129
  };
125
130
  export declare const createDocumentId: typeof createId;
126
- export declare const transformContentTypesToModels: (contentTypes: LoadedContentTypeModel[]) => Model[];
131
+ export declare const transformContentTypesToModels: (contentTypes: LoadedContentTypeModel[], identifiers: Identifiers) => Model[];
127
132
  //# sourceMappingURL=transform-content-types-to-models.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transform-content-types-to-models.d.ts","sourceRoot":"","sources":["../../src/utils/transform-content-types-to-models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAS,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAMhD;;;;;GAKG;AAEH,eAAO,MAAM,2BAA2B,eAAe,CAAC;AACxD,eAAO,MAAM,oBAAoB,eAAe,CAAC;AACjD,eAAO,MAAM,6BAA6B,cAAc,CAAC;AACzD,eAAO,MAAM,qBAAqB,mBAAmB,CAAC;AACtD,eAAO,MAAM,MAAM,WAAW,CAAC;AAE/B,eAAO,MAAM,yBAAyB,mBAAoB,MAAM,WACmB,CAAC;AAEpF,eAAO,MAAM,kBAAkB,mBAAoB,MAAM,WACmB,CAAC;AAI7E,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,iBAAiB,GAC3D,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,gBAAgB,GAAG,KAAK,GAAG,WAAW,CAAC,CAAC,CAAC;AAGnF,eAAO,MAAM,kBAAkB,SACvB,MAAM,aACD,OAAO,SAAS,CAAC,YAAY,eAC3B,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwFpC,CAAC;AAEF,eAAO,MAAM,mBAAmB,gBAAiB,sBAAsB,OAOtE,CAAC;AAEF,eAAO,MAAM,iBAAiB,gBACf,sBAAsB;UACc,aAAa,GAAG,WAAW;CAI7E,CAAC;AAEF,eAAO,MAAM,gBAAgB,iBAAW,CAAC;AA6EzC,eAAO,MAAM,6BAA6B,iBAAkB,sBAAsB,EAAE,KAAG,KAAK,EAiD3F,CAAC"}
1
+ {"version":3,"file":"transform-content-types-to-models.d.ts","sourceRoot":"","sources":["../../src/utils/transform-content-types-to-models.ts"],"names":[],"mappings":"AAAA,OAAO,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"}
@@ -1,22 +1,46 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const database = require("@strapi/database");
4
3
  const cuid2 = require("@paralleldrive/cuid2");
5
4
  const assert = require("node:assert");
6
5
  const _ = require("lodash/fp");
7
6
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
8
7
  const assert__default = /* @__PURE__ */ _interopDefault(assert);
9
8
  const ___default = /* @__PURE__ */ _interopDefault(_);
10
- const { identifiers } = database.utils;
11
- const COMPONENT_JOIN_TABLE_SUFFIX = "components";
12
- const DZ_JOIN_TABLE_SUFFIX = "components";
13
- const COMPONENT_INVERSE_COLUMN_NAME = "component";
14
- const COMPONENT_TYPE_COLUMN = "component_type";
15
- const ENTITY = "entity";
16
- const getComponentJoinTableName = (collectionName) => identifiers.getTableName(collectionName, { suffix: COMPONENT_JOIN_TABLE_SUFFIX });
17
- const getDzJoinTableName = (collectionName) => identifiers.getTableName(collectionName, { suffix: DZ_JOIN_TABLE_SUFFIX });
18
- const { ID_COLUMN: id, FIELD_COLUMN: field, ORDER_COLUMN: order } = identifiers;
19
- const transformAttribute = (name, attribute, contentType) => {
9
+ const getComponentJoinTableName = (collectionName, identifiers) => {
10
+ return identifiers.getNameFromTokens([
11
+ { name: collectionName, compressible: true },
12
+ { name: "components", shortName: "cmps", compressible: false }
13
+ ]);
14
+ };
15
+ const getDzJoinTableName = (collectionName, identifiers) => {
16
+ return identifiers.getNameFromTokens([
17
+ { name: collectionName, compressible: true },
18
+ { name: "components", shortName: "cmps", compressible: false }
19
+ ]);
20
+ };
21
+ const getComponentJoinColumnEntityName = (identifiers) => {
22
+ return identifiers.getNameFromTokens([
23
+ { name: "entity", compressible: false },
24
+ { name: "id", compressible: false }
25
+ ]);
26
+ };
27
+ const getComponentJoinColumnInverseName = (identifiers) => {
28
+ return identifiers.getNameFromTokens([
29
+ { name: "component", shortName: "cmp", compressible: false },
30
+ { name: "id", compressible: false }
31
+ ]);
32
+ };
33
+ const getComponentTypeColumn = (identifiers) => {
34
+ return identifiers.getNameFromTokens([{ name: "component_type", compressible: false }]);
35
+ };
36
+ const getComponentFkIndexName = (contentType, identifiers) => {
37
+ return identifiers.getNameFromTokens([
38
+ { name: contentType, compressible: true },
39
+ { name: "entity", compressible: false },
40
+ { name: "fk", compressible: false }
41
+ ]);
42
+ };
43
+ const transformAttribute = (name, attribute, contentType, identifiers) => {
20
44
  switch (attribute.type) {
21
45
  case "media": {
22
46
  return {
@@ -27,11 +51,10 @@ const transformAttribute = (name, attribute, contentType) => {
27
51
  };
28
52
  }
29
53
  case "component": {
30
- const joinTableName = getComponentJoinTableName(contentType.collectionName);
31
- const joinColumnEntityName = identifiers.getJoinColumnAttributeIdName(ENTITY);
32
- const joinColumnInverseName = identifiers.getJoinColumnAttributeIdName(
33
- COMPONENT_INVERSE_COLUMN_NAME
34
- );
54
+ const joinTableName = getComponentJoinTableName(contentType.collectionName, identifiers);
55
+ const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);
56
+ const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);
57
+ const compTypeColumn = getComponentTypeColumn(identifiers);
35
58
  return {
36
59
  type: "relation",
37
60
  relation: attribute.repeatable === true ? "oneToMany" : "oneToOne",
@@ -42,29 +65,33 @@ const transformAttribute = (name, attribute, contentType) => {
42
65
  name: joinTableName,
43
66
  joinColumn: {
44
67
  name: joinColumnEntityName,
45
- referencedColumn: id
68
+ referencedColumn: identifiers.ID_COLUMN
46
69
  },
47
70
  inverseJoinColumn: {
48
71
  name: joinColumnInverseName,
49
- referencedColumn: id
72
+ referencedColumn: identifiers.ID_COLUMN
50
73
  },
51
74
  on: {
52
75
  field: name
53
76
  },
54
- orderColumnName: order,
77
+ orderColumnName: identifiers.ORDER_COLUMN,
55
78
  orderBy: {
56
79
  order: "asc"
57
80
  },
58
- pivotColumns: [joinColumnEntityName, joinColumnInverseName, field, COMPONENT_TYPE_COLUMN]
81
+ pivotColumns: [
82
+ joinColumnEntityName,
83
+ joinColumnInverseName,
84
+ identifiers.FIELD_COLUMN,
85
+ compTypeColumn
86
+ ]
59
87
  }
60
88
  };
61
89
  }
62
90
  case "dynamiczone": {
63
- const joinTableName = getDzJoinTableName(contentType.collectionName);
64
- const joinColumnEntityName = identifiers.getJoinColumnAttributeIdName(ENTITY);
65
- const joinColumnInverseName = identifiers.getJoinColumnAttributeIdName(
66
- COMPONENT_INVERSE_COLUMN_NAME
67
- );
91
+ const joinTableName = getDzJoinTableName(contentType.collectionName, identifiers);
92
+ const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);
93
+ const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);
94
+ const compTypeColumn = getComponentTypeColumn(identifiers);
68
95
  return {
69
96
  type: "relation",
70
97
  relation: "morphToMany",
@@ -74,15 +101,15 @@ const transformAttribute = (name, attribute, contentType) => {
74
101
  name: joinTableName,
75
102
  joinColumn: {
76
103
  name: joinColumnEntityName,
77
- referencedColumn: id
104
+ referencedColumn: identifiers.ID_COLUMN
78
105
  },
79
106
  morphColumn: {
80
107
  idColumn: {
81
108
  name: joinColumnInverseName,
82
- referencedColumn: id
109
+ referencedColumn: identifiers.ID_COLUMN
83
110
  },
84
111
  typeColumn: {
85
- name: COMPONENT_TYPE_COLUMN
112
+ name: compTypeColumn
86
113
  },
87
114
  typeField: "__component"
88
115
  },
@@ -92,7 +119,12 @@ const transformAttribute = (name, attribute, contentType) => {
92
119
  orderBy: {
93
120
  order: "asc"
94
121
  },
95
- pivotColumns: [joinColumnEntityName, joinColumnInverseName, field, COMPONENT_TYPE_COLUMN]
122
+ pivotColumns: [
123
+ joinColumnEntityName,
124
+ joinColumnInverseName,
125
+ identifiers.FIELD_COLUMN,
126
+ compTypeColumn
127
+ ]
96
128
  }
97
129
  };
98
130
  }
@@ -101,11 +133,16 @@ const transformAttribute = (name, attribute, contentType) => {
101
133
  }
102
134
  }
103
135
  };
104
- const transformAttributes = (contentType) => {
136
+ const transformAttributes = (contentType, identifiers) => {
105
137
  return Object.keys(contentType.attributes || {}).reduce((attrs, attrName) => {
106
138
  return {
107
139
  ...attrs,
108
- [attrName]: transformAttribute(attrName, contentType.attributes[attrName], contentType)
140
+ [attrName]: transformAttribute(
141
+ attrName,
142
+ contentType.attributes[attrName],
143
+ contentType,
144
+ identifiers
145
+ )
109
146
  };
110
147
  }, {});
111
148
  };
@@ -115,18 +152,19 @@ const hasComponentsOrDz = (contentType) => {
115
152
  );
116
153
  };
117
154
  const createDocumentId = cuid2.createId;
118
- const createCompoLinkModel = (contentType) => {
119
- const name = getComponentJoinTableName(contentType.collectionName);
120
- const entityId = identifiers.getJoinColumnAttributeIdName(ENTITY);
121
- const componentId = identifiers.getJoinColumnAttributeIdName(COMPONENT_INVERSE_COLUMN_NAME);
122
- const fkIndex = identifiers.getFkIndexName([contentType.collectionName, ENTITY]);
155
+ const createCompoLinkModel = (contentType, identifiers) => {
156
+ const name = getComponentJoinTableName(contentType.collectionName, identifiers);
157
+ const entityId = getComponentJoinColumnEntityName(identifiers);
158
+ const componentId = getComponentJoinColumnInverseName(identifiers);
159
+ const compTypeColumn = getComponentTypeColumn(identifiers);
160
+ const fkIndex = getComponentFkIndexName(contentType.collectionName, identifiers);
123
161
  return {
124
162
  // TODO: make sure there can't be any conflicts with a prefix
125
163
  singularName: name,
126
164
  uid: name,
127
165
  tableName: name,
128
166
  attributes: {
129
- [id]: {
167
+ [identifiers.ID_COLUMN]: {
130
168
  type: "increments"
131
169
  },
132
170
  [entityId]: {
@@ -141,13 +179,13 @@ const createCompoLinkModel = (contentType) => {
141
179
  unsigned: true
142
180
  }
143
181
  },
144
- [COMPONENT_TYPE_COLUMN]: {
182
+ [compTypeColumn]: {
145
183
  type: "string"
146
184
  },
147
- [field]: {
185
+ [identifiers.FIELD_COLUMN]: {
148
186
  type: "string"
149
187
  },
150
- [order]: {
188
+ [identifiers.ORDER_COLUMN]: {
151
189
  type: "float",
152
190
  column: {
153
191
  unsigned: true,
@@ -157,12 +195,12 @@ const createCompoLinkModel = (contentType) => {
157
195
  },
158
196
  indexes: [
159
197
  {
160
- name: identifiers.getIndexName([contentType.collectionName, field]),
161
- columns: [field]
198
+ name: identifiers.getIndexName([contentType.collectionName, identifiers.FIELD_COLUMN]),
199
+ columns: [identifiers.FIELD_COLUMN]
162
200
  },
163
201
  {
164
- name: identifiers.getIndexName([contentType.collectionName, COMPONENT_TYPE_COLUMN]),
165
- columns: [COMPONENT_TYPE_COLUMN]
202
+ name: identifiers.getIndexName([contentType.collectionName, compTypeColumn]),
203
+ columns: [compTypeColumn]
166
204
  },
167
205
  {
168
206
  name: fkIndex,
@@ -171,7 +209,7 @@ const createCompoLinkModel = (contentType) => {
171
209
  {
172
210
  // NOTE: since we don't include attribute names, we need to be careful not to create another unique index
173
211
  name: identifiers.getUniqueIndexName([contentType.collectionName]),
174
- columns: [entityId, componentId, field, COMPONENT_TYPE_COLUMN],
212
+ columns: [entityId, componentId, identifiers.FIELD_COLUMN, compTypeColumn],
175
213
  type: "unique"
176
214
  }
177
215
  ],
@@ -179,21 +217,21 @@ const createCompoLinkModel = (contentType) => {
179
217
  {
180
218
  name: fkIndex,
181
219
  columns: [entityId],
182
- referencedColumns: [id],
220
+ referencedColumns: [identifiers.ID_COLUMN],
183
221
  referencedTable: identifiers.getTableName(contentType.collectionName),
184
222
  onDelete: "CASCADE"
185
223
  }
186
224
  ]
187
225
  };
188
226
  };
189
- const transformContentTypesToModels = (contentTypes) => {
227
+ const transformContentTypesToModels = (contentTypes, identifiers) => {
190
228
  const models = [];
191
229
  contentTypes.forEach((contentType) => {
192
230
  assert__default.default(contentType.collectionName, 'Content type "collectionName" is required');
193
231
  assert__default.default(contentType.modelName, 'Content type "modelName" is required');
194
232
  assert__default.default(contentType.uid, 'Content type "uid" is required');
195
233
  const documentIdAttribute = contentType.modelType === "contentType" ? { documentId: { type: "string", default: createDocumentId } } : {};
196
- const reservedAttributeNames = ["document_id", id];
234
+ const reservedAttributeNames = ["document_id", identifiers.ID_COLUMN];
197
235
  Object.keys(contentType.attributes || {}).forEach((attributeName) => {
198
236
  const snakeCasedAttributeName = ___default.default.snakeCase(attributeName);
199
237
  if (reservedAttributeNames.includes(snakeCasedAttributeName)) {
@@ -203,32 +241,32 @@ const transformContentTypesToModels = (contentTypes) => {
203
241
  }
204
242
  });
205
243
  if (hasComponentsOrDz(contentType)) {
206
- const compoLinkModel = createCompoLinkModel(contentType);
244
+ const compoLinkModel = createCompoLinkModel(contentType, identifiers);
207
245
  models.push(compoLinkModel);
208
246
  }
209
247
  const model = {
210
248
  uid: contentType.uid,
211
249
  singularName: contentType.modelName,
212
- tableName: identifiers.getTableName(contentType.collectionName),
250
+ tableName: contentType.collectionName,
251
+ // This gets shortened in metadata.loadModels(), so we don't shorten here or it will happen twice
213
252
  attributes: {
214
- [id]: {
253
+ [identifiers.ID_COLUMN]: {
215
254
  type: "increments"
216
255
  },
217
256
  ...documentIdAttribute,
218
- ...transformAttributes(contentType)
257
+ ...transformAttributes(contentType, identifiers)
219
258
  }
220
259
  };
221
260
  models.push(model);
222
261
  });
223
262
  return models;
224
263
  };
225
- exports.COMPONENT_INVERSE_COLUMN_NAME = COMPONENT_INVERSE_COLUMN_NAME;
226
- exports.COMPONENT_JOIN_TABLE_SUFFIX = COMPONENT_JOIN_TABLE_SUFFIX;
227
- exports.COMPONENT_TYPE_COLUMN = COMPONENT_TYPE_COLUMN;
228
- exports.DZ_JOIN_TABLE_SUFFIX = DZ_JOIN_TABLE_SUFFIX;
229
- exports.ENTITY = ENTITY;
230
264
  exports.createDocumentId = createDocumentId;
265
+ exports.getComponentFkIndexName = getComponentFkIndexName;
266
+ exports.getComponentJoinColumnEntityName = getComponentJoinColumnEntityName;
267
+ exports.getComponentJoinColumnInverseName = getComponentJoinColumnInverseName;
231
268
  exports.getComponentJoinTableName = getComponentJoinTableName;
269
+ exports.getComponentTypeColumn = getComponentTypeColumn;
232
270
  exports.getDzJoinTableName = getDzJoinTableName;
233
271
  exports.hasComponentsOrDz = hasComponentsOrDz;
234
272
  exports.transformAttribute = transformAttribute;
@@ -1 +1 @@
1
- {"version":3,"file":"transform-content-types-to-models.js","sources":["../../src/utils/transform-content-types-to-models.ts"],"sourcesContent":["import { type Model, utils } from '@strapi/database';\nimport type { Struct, Schema } from '@strapi/types';\nimport { createId } from '@paralleldrive/cuid2';\nimport assert from 'node:assert';\nimport _ from 'lodash/fp';\n\nconst { identifiers } = utils;\n\n/**\n * Because strapi/database models don't know about things like components or dynamic zones, we use this file to convert them\n * to a relations format that it recognizes\n *\n * Therefore we have to keep an additional set of helpers/extensions to the database naming methods\n */\n\nexport const COMPONENT_JOIN_TABLE_SUFFIX = 'components';\nexport const DZ_JOIN_TABLE_SUFFIX = 'components';\nexport const COMPONENT_INVERSE_COLUMN_NAME = 'component';\nexport const COMPONENT_TYPE_COLUMN = 'component_type';\nexport const ENTITY = 'entity';\n\nexport const getComponentJoinTableName = (collectionName: string) =>\n identifiers.getTableName(collectionName, { suffix: COMPONENT_JOIN_TABLE_SUFFIX });\n\nexport const getDzJoinTableName = (collectionName: string) =>\n identifiers.getTableName(collectionName, { suffix: DZ_JOIN_TABLE_SUFFIX });\n\nconst { ID_COLUMN: id, FIELD_COLUMN: field, ORDER_COLUMN: order } = identifiers;\n\nexport type LoadedContentTypeModel = Struct.ContentTypeSchema &\n Required<Pick<Struct.ContentTypeSchema, 'collectionName' | 'uid' | 'modelName'>>;\n\n// Transforms an attribute (particularly for relation types) into the format that strapi/database accepts\nexport const transformAttribute = (\n name: string,\n attribute: Schema.Attribute.AnyAttribute,\n contentType: LoadedContentTypeModel\n) => {\n switch (attribute.type) {\n case 'media': {\n return {\n type: 'relation',\n relation: attribute.multiple === true ? 'morphMany' : 'morphOne',\n target: 'plugin::upload.file',\n morphBy: 'related',\n };\n }\n case 'component': {\n const joinTableName = getComponentJoinTableName(contentType.collectionName);\n const joinColumnEntityName = identifiers.getJoinColumnAttributeIdName(ENTITY);\n const joinColumnInverseName = identifiers.getJoinColumnAttributeIdName(\n COMPONENT_INVERSE_COLUMN_NAME\n );\n\n return {\n type: 'relation',\n relation: attribute.repeatable === true ? 'oneToMany' : 'oneToOne',\n target: attribute.component,\n\n // We need the join table name to be deterministic,\n // We need to allow passing the join table name as an option\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: id,\n },\n inverseJoinColumn: {\n name: joinColumnInverseName,\n referencedColumn: id,\n },\n on: {\n field: name,\n },\n orderColumnName: order,\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [joinColumnEntityName, joinColumnInverseName, field, COMPONENT_TYPE_COLUMN],\n },\n };\n }\n case 'dynamiczone': {\n const joinTableName = getDzJoinTableName(contentType.collectionName);\n const joinColumnEntityName = identifiers.getJoinColumnAttributeIdName(ENTITY);\n const joinColumnInverseName = identifiers.getJoinColumnAttributeIdName(\n COMPONENT_INVERSE_COLUMN_NAME\n );\n\n return {\n type: 'relation',\n relation: 'morphToMany',\n // TODO: handle restrictions at some point\n // target: attribute.components,\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: id,\n },\n morphColumn: {\n idColumn: {\n name: joinColumnInverseName,\n referencedColumn: id,\n },\n typeColumn: {\n name: COMPONENT_TYPE_COLUMN,\n },\n typeField: '__component',\n },\n on: {\n field: name,\n },\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [joinColumnEntityName, joinColumnInverseName, field, COMPONENT_TYPE_COLUMN],\n },\n };\n }\n default: {\n return attribute;\n }\n }\n};\n\nexport const transformAttributes = (contentType: LoadedContentTypeModel) => {\n return Object.keys(contentType.attributes! || {}).reduce((attrs, attrName) => {\n return {\n ...attrs,\n [attrName]: transformAttribute(attrName, contentType.attributes[attrName]!, contentType),\n };\n }, {});\n};\n\nexport const hasComponentsOrDz = (\n contentType: LoadedContentTypeModel\n): contentType is LoadedContentTypeModel & { type: 'dynamiczone' | 'component' } => {\n return Object.values(contentType.attributes || {}).some(\n ({ type }) => type === 'dynamiczone' || type === 'component'\n );\n};\n\nexport const createDocumentId = createId;\n\n// Creates the\nconst createCompoLinkModel = (contentType: LoadedContentTypeModel): Model => {\n const name = getComponentJoinTableName(contentType.collectionName);\n\n const entityId = identifiers.getJoinColumnAttributeIdName(ENTITY);\n const componentId = identifiers.getJoinColumnAttributeIdName(COMPONENT_INVERSE_COLUMN_NAME);\n const fkIndex = identifiers.getFkIndexName([contentType.collectionName, ENTITY]);\n\n return {\n // TODO: make sure there can't be any conflicts with a prefix\n singularName: name,\n uid: name,\n tableName: name,\n attributes: {\n [id]: {\n type: 'increments',\n },\n [entityId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [componentId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [COMPONENT_TYPE_COLUMN]: {\n type: 'string',\n },\n [field]: {\n type: 'string',\n },\n [order]: {\n type: 'float',\n column: {\n unsigned: true,\n defaultTo: null,\n },\n },\n },\n indexes: [\n {\n name: identifiers.getIndexName([contentType.collectionName, field]),\n columns: [field],\n },\n {\n name: identifiers.getIndexName([contentType.collectionName, COMPONENT_TYPE_COLUMN]),\n columns: [COMPONENT_TYPE_COLUMN],\n },\n {\n name: fkIndex,\n columns: [entityId],\n },\n {\n // NOTE: since we don't include attribute names, we need to be careful not to create another unique index\n name: identifiers.getUniqueIndexName([contentType.collectionName]),\n columns: [entityId, componentId, field, COMPONENT_TYPE_COLUMN],\n type: 'unique',\n },\n ],\n foreignKeys: [\n {\n name: fkIndex,\n columns: [entityId],\n referencedColumns: [id],\n referencedTable: identifiers.getTableName(contentType.collectionName),\n onDelete: 'CASCADE',\n },\n ],\n };\n};\n\nexport const transformContentTypesToModels = (contentTypes: LoadedContentTypeModel[]): Model[] => {\n const models: Model[] = [];\n\n contentTypes.forEach((contentType) => {\n assert(contentType.collectionName, 'Content type \"collectionName\" is required');\n assert(contentType.modelName, 'Content type \"modelName\" is required');\n assert(contentType.uid, 'Content type \"uid\" is required');\n\n // Add document id to content types\n // as it is not documented\n const documentIdAttribute: Record<string, Schema.Attribute.AnyAttribute> =\n contentType.modelType === 'contentType'\n ? { documentId: { type: 'string', default: createDocumentId } }\n : {};\n\n // TODO: this needs to be combined with getReservedNames, we should not be maintaining two lists\n // Prevent user from creating a documentId attribute\n const reservedAttributeNames = ['document_id', id];\n Object.keys(contentType.attributes || {}).forEach((attributeName) => {\n const snakeCasedAttributeName = _.snakeCase(attributeName);\n if (reservedAttributeNames.includes(snakeCasedAttributeName)) {\n throw new Error(\n `The attribute \"${attributeName}\" is reserved and cannot be used in a model. Please rename \"${contentType.modelName}\" attribute \"${attributeName}\" to something else.`\n );\n }\n });\n\n if (hasComponentsOrDz(contentType)) {\n const compoLinkModel = createCompoLinkModel(contentType);\n models.push(compoLinkModel);\n }\n\n const model: Model = {\n uid: contentType.uid,\n singularName: contentType.modelName,\n tableName: identifiers.getTableName(contentType.collectionName),\n attributes: {\n [id]: {\n type: 'increments',\n },\n ...documentIdAttribute,\n ...transformAttributes(contentType),\n },\n };\n\n models.push(model);\n });\n\n return models;\n};\n"],"names":["utils","createId","assert","_"],"mappings":";;;;;;;;;AAMA,MAAM,EAAE,YAAgB,IAAAA;AASjB,MAAM,8BAA8B;AACpC,MAAM,uBAAuB;AAC7B,MAAM,gCAAgC;AACtC,MAAM,wBAAwB;AAC9B,MAAM,SAAS;AAET,MAAA,4BAA4B,CAAC,mBACxC,YAAY,aAAa,gBAAgB,EAAE,QAAQ,6BAA6B;AAErE,MAAA,qBAAqB,CAAC,mBACjC,YAAY,aAAa,gBAAgB,EAAE,QAAQ,sBAAsB;AAE3E,MAAM,EAAE,WAAW,IAAI,cAAc,OAAO,cAAc,MAAU,IAAA;AAM7D,MAAM,qBAAqB,CAChC,MACA,WACA,gBACG;AACH,UAAQ,UAAU,MAAM;AAAA,IACtB,KAAK,SAAS;AACL,aAAA;AAAA,QACL,MAAM;AAAA,QACN,UAAU,UAAU,aAAa,OAAO,cAAc;AAAA,QACtD,QAAQ;AAAA,QACR,SAAS;AAAA,MAA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C1C,WAAA,KAAK,YAAY,cAAc,CAAA,CAAE,EAAE,QAAQ,CAAC,kBAAkB;AAC7D,YAAA,0BAA0BC,WAAAA,QAAE,UAAU,aAAa;AACrD,UAAA,uBAAuB,SAAS,uBAAuB,GAAG;AAC5D,cAAM,IAAI;AAAA,UACR,kBAAkB,aAAa,+DAA+D,YAAY,SAAS,gBAAgB,aAAa;AAAA,QAAA;AAAA,MAEpJ;AAAA,IAAA,CACD;AAEG,QAAA,kBAAkB,WAAW,GAAG;AAC5B,YAAA,iBAAiB,qBAAqB,WAAW;AACvD,aAAO,KAAK,cAAc;AAAA,IAC5B;AAEA,UAAM,QAAe;AAAA,MACnB,KAAK,YAAY;AAAA,MACjB,cAAc,YAAY;AAAA,MAC1B,WAAW,YAAY,aAAa,YAAY,cAAc;AAAA,MAC9D,YAAY;AAAA,QACV,CAAC,EAAE,GAAG;AAAA,UACJ,MAAM;AAAA,QACR;AAAA,QACA,GAAG;AAAA,QACH,GAAG,oBAAoB,WAAW;AAAA,MACpC;AAAA,IAAA;AAGF,WAAO,KAAK,KAAK;AAAA,EAAA,CAClB;AAEM,SAAA;AACT;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"transform-content-types-to-models.js","sources":["../../src/utils/transform-content-types-to-models.ts"],"sourcesContent":["import { type Model, type Identifiers } from '@strapi/database';\nimport type { Struct, Schema } from '@strapi/types';\nimport { createId } from '@paralleldrive/cuid2';\nimport assert from 'node:assert';\nimport _ from 'lodash/fp';\n\n/**\n * Because strapi/database models don't know about things like components or dynamic zones, we use this file to convert them\n * to a relations format that it recognizes\n *\n * Therefore we have to keep an additional set of helpers/extensions to the database naming methods\n *\n * IMPORTANT!\n * If we use short versions of anything, we MUST call getNameFromTokens directly; attempting to shorten them ourselves\n * prevents the unshortened name map from being filled properly, so for example it will think that the short name\n * 'collection4f3a_cmps' maps to the unshortened 'collectionname_cmps' rather than 'collectionname_components'\n * Therefore, we only use the identifiers helpers in cases where we do not do any of our own shortening\n */\n\nexport const getComponentJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getDzJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnEntityName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'entity', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnInverseName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'component', shortName: 'cmp', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentTypeColumn = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([{ name: 'component_type', compressible: false }]);\n};\n\nexport const getComponentFkIndexName = (contentType: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: contentType, compressible: true },\n { name: 'entity', compressible: false },\n { name: 'fk', compressible: false },\n ]);\n};\n\n// const { ID_COLUMN: id, FIELD_COLUMN: field, ORDER_COLUMN: order } = identifiers;\n\nexport type LoadedContentTypeModel = Struct.ContentTypeSchema &\n Required<Pick<Struct.ContentTypeSchema, 'collectionName' | 'uid' | 'modelName'>>;\n\n// Transforms an attribute (particularly for relation types) into the format that strapi/database accepts\nexport const transformAttribute = (\n name: string,\n attribute: Schema.Attribute.AnyAttribute,\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n switch (attribute.type) {\n case 'media': {\n return {\n type: 'relation',\n relation: attribute.multiple === true ? 'morphMany' : 'morphOne',\n target: 'plugin::upload.file',\n morphBy: 'related',\n };\n }\n case 'component': {\n const joinTableName = getComponentJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n return {\n type: 'relation',\n relation: attribute.repeatable === true ? 'oneToMany' : 'oneToOne',\n target: attribute.component,\n\n // We need the join table name to be deterministic,\n // We need to allow passing the join table name as an option\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n inverseJoinColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n on: {\n field: name,\n },\n orderColumnName: identifiers.ORDER_COLUMN,\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n case 'dynamiczone': {\n const joinTableName = getDzJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n\n return {\n type: 'relation',\n relation: 'morphToMany',\n // TODO: handle restrictions at some point\n // target: attribute.components,\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n morphColumn: {\n idColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n typeColumn: {\n name: compTypeColumn,\n },\n typeField: '__component',\n },\n on: {\n field: name,\n },\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n default: {\n return attribute;\n }\n }\n};\n\nexport const transformAttributes = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n return Object.keys(contentType.attributes! || {}).reduce((attrs, attrName) => {\n return {\n ...attrs,\n [attrName]: transformAttribute(\n attrName,\n contentType.attributes[attrName]!,\n contentType,\n identifiers\n ),\n };\n }, {});\n};\n\nexport const hasComponentsOrDz = (\n contentType: LoadedContentTypeModel\n): contentType is LoadedContentTypeModel & { type: 'dynamiczone' | 'component' } => {\n return Object.values(contentType.attributes || {}).some(\n (({ type }: { type: string }) => type === 'dynamiczone' || type === 'component') as any\n );\n};\n\nexport const createDocumentId = createId;\n\nconst createCompoLinkModel = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n): Model => {\n const name = getComponentJoinTableName(contentType.collectionName, identifiers);\n\n const entityId = getComponentJoinColumnEntityName(identifiers);\n const componentId = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n const fkIndex = getComponentFkIndexName(contentType.collectionName, identifiers);\n\n return {\n // TODO: make sure there can't be any conflicts with a prefix\n singularName: name,\n uid: name,\n tableName: name,\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n [entityId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [componentId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [compTypeColumn]: {\n type: 'string',\n },\n [identifiers.FIELD_COLUMN]: {\n type: 'string',\n },\n [identifiers.ORDER_COLUMN]: {\n type: 'float',\n column: {\n unsigned: true,\n defaultTo: null,\n },\n },\n },\n indexes: [\n {\n name: identifiers.getIndexName([contentType.collectionName, identifiers.FIELD_COLUMN]),\n columns: [identifiers.FIELD_COLUMN],\n },\n {\n name: identifiers.getIndexName([contentType.collectionName, compTypeColumn]),\n columns: [compTypeColumn],\n },\n {\n name: fkIndex,\n columns: [entityId],\n },\n {\n // NOTE: since we don't include attribute names, we need to be careful not to create another unique index\n name: identifiers.getUniqueIndexName([contentType.collectionName]),\n columns: [entityId, componentId, identifiers.FIELD_COLUMN, compTypeColumn],\n type: 'unique',\n },\n ],\n foreignKeys: [\n {\n name: fkIndex,\n columns: [entityId],\n referencedColumns: [identifiers.ID_COLUMN],\n referencedTable: identifiers.getTableName(contentType.collectionName),\n onDelete: 'CASCADE',\n },\n ],\n };\n};\n\nexport const transformContentTypesToModels = (\n contentTypes: LoadedContentTypeModel[],\n identifiers: Identifiers\n): Model[] => {\n const models: Model[] = [];\n\n contentTypes.forEach((contentType) => {\n assert(contentType.collectionName, 'Content type \"collectionName\" is required');\n assert(contentType.modelName, 'Content type \"modelName\" is required');\n assert(contentType.uid, 'Content type \"uid\" is required');\n\n // Add document id to content types\n // as it is not documented\n const documentIdAttribute: Record<string, Schema.Attribute.AnyAttribute> =\n contentType.modelType === 'contentType'\n ? { documentId: { type: 'string', default: createDocumentId } }\n : {};\n\n // TODO: this needs to be combined with getReservedNames, we should not be maintaining two lists\n // Prevent user from creating a documentId attribute\n const reservedAttributeNames = ['document_id', identifiers.ID_COLUMN];\n Object.keys(contentType.attributes || {}).forEach((attributeName) => {\n const snakeCasedAttributeName = _.snakeCase(attributeName);\n if (reservedAttributeNames.includes(snakeCasedAttributeName)) {\n throw new Error(\n `The attribute \"${attributeName}\" is reserved and cannot be used in a model. Please rename \"${contentType.modelName}\" attribute \"${attributeName}\" to something else.`\n );\n }\n });\n\n if (hasComponentsOrDz(contentType)) {\n const compoLinkModel = createCompoLinkModel(contentType, identifiers);\n models.push(compoLinkModel);\n }\n\n const model: Model = {\n uid: contentType.uid,\n singularName: contentType.modelName,\n tableName: contentType.collectionName, // This gets shortened in metadata.loadModels(), so we don't shorten here or it will happen twice\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n ...documentIdAttribute,\n ...transformAttributes(contentType, identifiers),\n },\n };\n\n models.push(model);\n });\n\n return models;\n};\n"],"names":["createId","assert","_"],"mappings":";;;;;;;;AAmBa,MAAA,4BAA4B,CAAC,gBAAwB,gBAA6B;AAC7F,SAAO,YAAY,kBAAkB;AAAA,IACnC,EAAE,MAAM,gBAAgB,cAAc,KAAK;AAAA,IAC3C,EAAE,MAAM,cAAc,WAAW,QAAQ,cAAc,MAAM;AAAA,EAAA,CAC9D;AACH;AAEa,MAAA,qBAAqB,CAAC,gBAAwB,gBAA6B;AACtF,SAAO,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