@strapi/core 0.0.0-experimental.a407f3bc8fb79a53cf7975140864526b6ddbac4b → 0.0.0-experimental.fc1ac2acd58c8a5a858679956b6d102ac5ee4011

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 (162) hide show
  1. package/dist/Strapi.d.ts.map +1 -1
  2. package/dist/Strapi.js +4 -1
  3. package/dist/Strapi.js.map +1 -1
  4. package/dist/Strapi.mjs +4 -1
  5. package/dist/Strapi.mjs.map +1 -1
  6. package/dist/configuration/index.d.ts.map +1 -1
  7. package/dist/configuration/index.js +4 -4
  8. package/dist/configuration/index.js.map +1 -1
  9. package/dist/configuration/index.mjs +1 -1
  10. package/dist/configuration/index.mjs.map +1 -1
  11. package/dist/configuration/urls.d.ts +8 -0
  12. package/dist/configuration/urls.d.ts.map +1 -0
  13. package/dist/configuration/urls.js +68 -0
  14. package/dist/configuration/urls.js.map +1 -0
  15. package/dist/configuration/urls.mjs +66 -0
  16. package/dist/configuration/urls.mjs.map +1 -0
  17. package/dist/core-api/controller/index.d.ts.map +1 -1
  18. package/dist/core-api/controller/index.js +6 -1
  19. package/dist/core-api/controller/index.js.map +1 -1
  20. package/dist/core-api/controller/index.mjs +6 -1
  21. package/dist/core-api/controller/index.mjs.map +1 -1
  22. package/dist/core-api/controller/transform.d.ts +8 -7
  23. package/dist/core-api/controller/transform.d.ts.map +1 -1
  24. package/dist/core-api/controller/transform.js +18 -9
  25. package/dist/core-api/controller/transform.js.map +1 -1
  26. package/dist/core-api/controller/transform.mjs +18 -9
  27. package/dist/core-api/controller/transform.mjs.map +1 -1
  28. package/dist/core-api/service/single-type.d.ts +1 -1
  29. package/dist/core-api/service/single-type.d.ts.map +1 -1
  30. package/dist/core-api/service/single-type.js +3 -4
  31. package/dist/core-api/service/single-type.js.map +1 -1
  32. package/dist/core-api/service/single-type.mjs +3 -4
  33. package/dist/core-api/service/single-type.mjs.map +1 -1
  34. package/dist/domain/content-type/index.d.ts.map +1 -1
  35. package/dist/domain/content-type/index.js +3 -0
  36. package/dist/domain/content-type/index.js.map +1 -1
  37. package/dist/domain/content-type/index.mjs +3 -0
  38. package/dist/domain/content-type/index.mjs.map +1 -1
  39. package/dist/domain/content-type/validator.d.ts.map +1 -1
  40. package/dist/domain/content-type/validator.js +1 -1
  41. package/dist/domain/content-type/validator.js.map +1 -1
  42. package/dist/domain/content-type/validator.mjs +2 -2
  43. package/dist/domain/content-type/validator.mjs.map +1 -1
  44. package/dist/domain/module/index.d.ts.map +1 -1
  45. package/dist/domain/module/index.js +2 -3
  46. package/dist/domain/module/index.js.map +1 -1
  47. package/dist/domain/module/index.mjs +2 -3
  48. package/dist/domain/module/index.mjs.map +1 -1
  49. package/dist/loaders/apis.js +1 -1
  50. package/dist/loaders/apis.js.map +1 -1
  51. package/dist/loaders/apis.mjs +2 -2
  52. package/dist/loaders/apis.mjs.map +1 -1
  53. package/dist/loaders/plugins/get-enabled-plugins.js +1 -1
  54. package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
  55. package/dist/loaders/plugins/get-enabled-plugins.mjs +2 -2
  56. package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
  57. package/dist/migrations/draft-publish.d.ts +17 -0
  58. package/dist/migrations/draft-publish.d.ts.map +1 -0
  59. package/dist/migrations/draft-publish.js +59 -0
  60. package/dist/migrations/draft-publish.js.map +1 -0
  61. package/dist/migrations/draft-publish.mjs +59 -0
  62. package/dist/migrations/draft-publish.mjs.map +1 -0
  63. package/dist/registries/config.d.ts +2 -2
  64. package/dist/registries/config.d.ts.map +1 -1
  65. package/dist/registries/config.js +14 -6
  66. package/dist/registries/config.js.map +1 -1
  67. package/dist/registries/config.mjs +15 -5
  68. package/dist/registries/config.mjs.map +1 -1
  69. package/dist/services/document-service/common.d.ts +2 -2
  70. package/dist/services/document-service/common.d.ts.map +1 -1
  71. package/dist/services/document-service/common.js.map +1 -1
  72. package/dist/services/document-service/common.mjs.map +1 -1
  73. package/dist/services/document-service/draft-and-publish.d.ts +9 -23
  74. package/dist/services/document-service/draft-and-publish.d.ts.map +1 -1
  75. package/dist/services/document-service/draft-and-publish.js +37 -9
  76. package/dist/services/document-service/draft-and-publish.js.map +1 -1
  77. package/dist/services/document-service/draft-and-publish.mjs +38 -10
  78. package/dist/services/document-service/draft-and-publish.mjs.map +1 -1
  79. package/dist/services/document-service/index.js +5 -5
  80. package/dist/services/document-service/index.js.map +1 -1
  81. package/dist/services/document-service/index.mjs +1 -1
  82. package/dist/services/document-service/index.mjs.map +1 -1
  83. package/dist/services/document-service/repository.d.ts +3 -0
  84. package/dist/services/document-service/repository.d.ts.map +1 -0
  85. package/dist/services/document-service/repository.js +304 -0
  86. package/dist/services/document-service/repository.js.map +1 -0
  87. package/dist/services/document-service/repository.mjs +304 -0
  88. package/dist/services/document-service/repository.mjs.map +1 -0
  89. package/dist/services/document-service/transform/id-map.d.ts +1 -1
  90. package/dist/services/document-service/transform/id-map.d.ts.map +1 -1
  91. package/dist/services/document-service/transform/id-map.js +15 -9
  92. package/dist/services/document-service/transform/id-map.js.map +1 -1
  93. package/dist/services/document-service/transform/id-map.mjs +16 -10
  94. package/dist/services/document-service/transform/id-map.mjs.map +1 -1
  95. package/dist/services/document-service/transform/id-transform.d.ts +4 -18
  96. package/dist/services/document-service/transform/id-transform.d.ts.map +1 -1
  97. package/dist/services/document-service/transform/id-transform.js +18 -12
  98. package/dist/services/document-service/transform/id-transform.js.map +1 -1
  99. package/dist/services/document-service/transform/id-transform.mjs +18 -12
  100. package/dist/services/document-service/transform/id-transform.mjs.map +1 -1
  101. package/dist/services/document-service/transform/populate.d.ts +5 -2
  102. package/dist/services/document-service/transform/populate.d.ts.map +1 -1
  103. package/dist/services/document-service/transform/populate.js.map +1 -1
  104. package/dist/services/document-service/transform/populate.mjs.map +1 -1
  105. package/dist/services/document-service/transform/relations/extract/data-ids.d.ts +1 -1
  106. package/dist/services/document-service/transform/relations/extract/data-ids.d.ts.map +1 -1
  107. package/dist/services/document-service/transform/relations/extract/data-ids.js +23 -12
  108. package/dist/services/document-service/transform/relations/extract/data-ids.js.map +1 -1
  109. package/dist/services/document-service/transform/relations/extract/data-ids.mjs +23 -12
  110. package/dist/services/document-service/transform/relations/extract/data-ids.mjs.map +1 -1
  111. package/dist/services/document-service/transform/relations/transform/data-ids.d.ts +1 -1
  112. package/dist/services/document-service/transform/relations/transform/data-ids.d.ts.map +1 -1
  113. package/dist/services/document-service/transform/relations/transform/data-ids.js +61 -37
  114. package/dist/services/document-service/transform/relations/transform/data-ids.js.map +1 -1
  115. package/dist/services/document-service/transform/relations/transform/data-ids.mjs +62 -38
  116. package/dist/services/document-service/transform/relations/transform/data-ids.mjs.map +1 -1
  117. package/dist/services/document-service/transform/relations/utils/dp.d.ts +10 -0
  118. package/dist/services/document-service/transform/relations/utils/dp.d.ts.map +1 -0
  119. package/dist/services/document-service/transform/relations/utils/dp.js +25 -0
  120. package/dist/services/document-service/transform/relations/utils/dp.js.map +1 -0
  121. package/dist/services/document-service/transform/relations/utils/dp.mjs +25 -0
  122. package/dist/services/document-service/transform/relations/utils/dp.mjs.map +1 -0
  123. package/dist/services/document-service/transform/relations/utils/types.d.ts +4 -1
  124. package/dist/services/document-service/transform/relations/utils/types.d.ts.map +1 -1
  125. package/dist/services/document-service/transform/types.d.ts +1 -1
  126. package/dist/services/document-service/transform/types.d.ts.map +1 -1
  127. package/dist/services/document-service/utils/populate.js +2 -2
  128. package/dist/services/document-service/utils/populate.js.map +1 -1
  129. package/dist/services/document-service/utils/populate.mjs +2 -2
  130. package/dist/services/document-service/utils/populate.mjs.map +1 -1
  131. package/dist/services/entity-service/components.js +8 -8
  132. package/dist/services/entity-service/components.js.map +1 -1
  133. package/dist/services/entity-service/components.mjs +9 -9
  134. package/dist/services/entity-service/components.mjs.map +1 -1
  135. package/dist/services/entity-service/index.d.ts.map +1 -1
  136. package/dist/services/entity-service/index.js +3 -3
  137. package/dist/services/entity-service/index.js.map +1 -1
  138. package/dist/services/entity-service/index.mjs +3 -3
  139. package/dist/services/entity-service/index.mjs.map +1 -1
  140. package/dist/services/entity-service/params.d.ts +4 -4
  141. package/dist/services/entity-service/params.d.ts.map +1 -1
  142. package/dist/services/entity-service/params.js +1 -1
  143. package/dist/services/entity-service/params.js.map +1 -1
  144. package/dist/services/entity-service/params.mjs +1 -1
  145. package/dist/services/entity-service/params.mjs.map +1 -1
  146. package/dist/utils/load-config-file.js +1 -1
  147. package/dist/utils/load-config-file.js.map +1 -1
  148. package/dist/utils/load-config-file.mjs +2 -2
  149. package/dist/utils/load-config-file.mjs.map +1 -1
  150. package/package.json +14 -14
  151. package/dist/services/document-service/document-engine.d.ts +0 -8
  152. package/dist/services/document-service/document-engine.d.ts.map +0 -1
  153. package/dist/services/document-service/document-engine.js +0 -241
  154. package/dist/services/document-service/document-engine.js.map +0 -1
  155. package/dist/services/document-service/document-engine.mjs +0 -242
  156. package/dist/services/document-service/document-engine.mjs.map +0 -1
  157. package/dist/services/document-service/repositories/content-type.d.ts +0 -3
  158. package/dist/services/document-service/repositories/content-type.d.ts.map +0 -1
  159. package/dist/services/document-service/repositories/content-type.js +0 -139
  160. package/dist/services/document-service/repositories/content-type.js.map +0 -1
  161. package/dist/services/document-service/repositories/content-type.mjs +0 -139
  162. package/dist/services/document-service/repositories/content-type.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"validator.js","sources":["../../../src/domain/content-type/validator.ts"],"sourcesContent":["import _ from 'lodash';\nimport { yup, toRegressedEnumValue } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\n\nconst LIFECYCLES = [\n 'beforeCreate',\n 'afterCreate',\n 'beforeFindOne',\n 'afterFindOne',\n 'beforeFindMany',\n 'afterFindMany',\n 'beforeCount',\n 'afterCount',\n 'beforeCreateMany',\n 'afterCreateMany',\n 'beforeUpdate',\n 'afterUpdate',\n 'beforeUpdateMany',\n 'afterUpdateMany',\n 'beforeDelete',\n 'afterDelete',\n 'beforeDeleteMany',\n 'afterDeleteMany',\n] as const;\n\n/**\n * For enumerations the least common denomiator is GraphQL, where\n * values needs to match the secure name regex:\n * GraphQL Spec https://spec.graphql.org/June2018/#sec-Names\n *\n * Therefore we need to make sure our users only use values, which\n * can be returned by GraphQL, by checking the regressed values\n * agains the GraphQL regex.\n *\n * TODO V5: check if we can avoid this coupling by moving this logic\n * into the GraphQL plugin.\n */\nconst GRAPHQL_ENUM_REGEX = /^[_A-Za-z][_0-9A-Za-z]*$/;\n\nconst lifecyclesShape = _.mapValues(_.keyBy(LIFECYCLES), () => yup.mixed().nullable().isFunction());\n\nconst contentTypeSchemaValidator = yup.object().shape({\n schema: yup.object().shape({\n info: yup\n .object()\n .shape({\n displayName: yup.string().required(),\n singularName: yup.string().isKebabCase().required(),\n pluralName: yup.string().isKebabCase().required(),\n })\n .required(),\n attributes: yup.object().test({\n name: 'valuesCollide',\n message: 'Some values collide when normalized',\n test(attributes: Schema.ContentType['attributes']) {\n for (const attrName of Object.keys(attributes)) {\n const attr = attributes[attrName];\n if (attr.type === 'enumeration') {\n const regressedValues = attr.enum.map(toRegressedEnumValue);\n\n // should match the GraphQL regex\n if (!regressedValues.every((value: string) => GRAPHQL_ENUM_REGEX.test(value))) {\n const message = `Invalid enumeration value. Values should have at least one alphabetical character preceding the first occurence of a number. Update your enumeration '${attrName}'.`;\n\n return this.createError({ message });\n }\n\n // should not contain empty values\n if (regressedValues.some((value: string) => value === '')) {\n return this.createError({\n message: `At least one value of the enumeration '${attrName}' appears to be empty. Only alphanumerical characters are taken into account.`,\n });\n }\n\n // should not collide\n const duplicates = _.uniq(\n regressedValues.filter(\n (value: string, index: number, values: string[]) => values.indexOf(value) !== index\n )\n );\n\n if (duplicates.length) {\n const message = `Some enumeration values of the field '${attrName}' collide when normalized: ${duplicates.join(\n ', '\n )}. Please modify your enumeration.`;\n\n return this.createError({ message });\n }\n }\n }\n\n return true;\n },\n }),\n }),\n actions: yup.object().onlyContainsFunctions(),\n lifecycles: yup.object().shape(lifecyclesShape).noUnknown(),\n});\n\nconst validateContentTypeDefinition = (data: unknown) => {\n return contentTypeSchemaValidator.validateSync(data, { strict: true, abortEarly: false });\n};\n\nexport { validateContentTypeDefinition };\n"],"names":["_","yup","toRegressedEnumValue"],"mappings":";;;;;;AAIA,MAAM,aAAa;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAcA,MAAM,qBAAqB;AAE3B,MAAM,kBAAkBA,WAAAA,QAAE,UAAUA,WAAA,QAAE,MAAM,UAAU,GAAG,MAAMC,YAAAA,IAAI,MAAM,EAAE,SAAS,EAAE,WAAY,CAAA;AAElG,MAAM,6BAA6BA,YAAA,IAAI,OAAO,EAAE,MAAM;AAAA,EACpD,QAAQA,YAAA,IAAI,OAAO,EAAE,MAAM;AAAA,IACzB,MAAMA,YAAA,IACH,OAAO,EACP,MAAM;AAAA,MACL,aAAaA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,MACnC,cAAcA,YAAAA,IAAI,OAAS,EAAA,YAAA,EAAc,SAAS;AAAA,MAClD,YAAYA,YAAAA,IAAI,OAAS,EAAA,YAAA,EAAc,SAAS;AAAA,IACjD,CAAA,EACA,SAAS;AAAA,IACZ,YAAYA,YAAA,IAAI,OAAO,EAAE,KAAK;AAAA,MAC5B,MAAM;AAAA,MACN,SAAS;AAAA,MACT,KAAK,YAA8C;AACjD,mBAAW,YAAY,OAAO,KAAK,UAAU,GAAG;AACxC,gBAAA,OAAO,WAAW,QAAQ;AAC5B,cAAA,KAAK,SAAS,eAAe;AAC/B,kBAAM,kBAAkB,KAAK,KAAK,IAAIC,YAAoB,oBAAA;AAGtD,gBAAA,CAAC,gBAAgB,MAAM,CAAC,UAAkB,mBAAmB,KAAK,KAAK,CAAC,GAAG;AACvE,oBAAA,UAAU,yJAAyJ,QAAQ;AAEjL,qBAAO,KAAK,YAAY,EAAE,QAAS,CAAA;AAAA,YACrC;AAGA,gBAAI,gBAAgB,KAAK,CAAC,UAAkB,UAAU,EAAE,GAAG;AACzD,qBAAO,KAAK,YAAY;AAAA,gBACtB,SAAS,0CAA0C,QAAQ;AAAA,cAAA,CAC5D;AAAA,YACH;AAGA,kBAAM,aAAaF,WAAAA,QAAE;AAAA,cACnB,gBAAgB;AAAA,gBACd,CAAC,OAAe,OAAe,WAAqB,OAAO,QAAQ,KAAK,MAAM;AAAA,cAChF;AAAA,YAAA;AAGF,gBAAI,WAAW,QAAQ;AACrB,oBAAM,UAAU,yCAAyC,QAAQ,8BAA8B,WAAW;AAAA,gBACxG;AAAA,cACD,CAAA;AAED,qBAAO,KAAK,YAAY,EAAE,QAAS,CAAA;AAAA,YACrC;AAAA,UACF;AAAA,QACF;AAEO,eAAA;AAAA,MACT;AAAA,IAAA,CACD;AAAA,EAAA,CACF;AAAA,EACD,SAASC,YAAA,IAAI,OAAO,EAAE,sBAAsB;AAAA,EAC5C,YAAYA,YAAI,IAAA,OAAA,EAAS,MAAM,eAAe,EAAE,UAAU;AAC5D,CAAC;AAEK,MAAA,gCAAgC,CAAC,SAAkB;AAChD,SAAA,2BAA2B,aAAa,MAAM,EAAE,QAAQ,MAAM,YAAY,OAAO;AAC1F;;"}
1
+ {"version":3,"file":"validator.js","sources":["../../../src/domain/content-type/validator.ts"],"sourcesContent":["import _ from 'lodash';\nimport { yup, strings } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\n\nconst LIFECYCLES = [\n 'beforeCreate',\n 'afterCreate',\n 'beforeFindOne',\n 'afterFindOne',\n 'beforeFindMany',\n 'afterFindMany',\n 'beforeCount',\n 'afterCount',\n 'beforeCreateMany',\n 'afterCreateMany',\n 'beforeUpdate',\n 'afterUpdate',\n 'beforeUpdateMany',\n 'afterUpdateMany',\n 'beforeDelete',\n 'afterDelete',\n 'beforeDeleteMany',\n 'afterDeleteMany',\n] as const;\n\n/**\n * For enumerations the least common denomiator is GraphQL, where\n * values needs to match the secure name regex:\n * GraphQL Spec https://spec.graphql.org/June2018/#sec-Names\n *\n * Therefore we need to make sure our users only use values, which\n * can be returned by GraphQL, by checking the regressed values\n * agains the GraphQL regex.\n *\n * TODO V5: check if we can avoid this coupling by moving this logic\n * into the GraphQL plugin.\n */\nconst GRAPHQL_ENUM_REGEX = /^[_A-Za-z][_0-9A-Za-z]*$/;\n\nconst lifecyclesShape = _.mapValues(_.keyBy(LIFECYCLES), () => yup.mixed().nullable().isFunction());\n\nconst contentTypeSchemaValidator = yup.object().shape({\n schema: yup.object().shape({\n info: yup\n .object()\n .shape({\n displayName: yup.string().required(),\n singularName: yup.string().isKebabCase().required(),\n pluralName: yup.string().isKebabCase().required(),\n })\n .required(),\n attributes: yup.object().test({\n name: 'valuesCollide',\n message: 'Some values collide when normalized',\n test(attributes: Schema.ContentType['attributes']) {\n for (const attrName of Object.keys(attributes)) {\n const attr = attributes[attrName];\n if (attr.type === 'enumeration') {\n const regressedValues = attr.enum.map(strings.toRegressedEnumValue);\n\n // should match the GraphQL regex\n if (!regressedValues.every((value: string) => GRAPHQL_ENUM_REGEX.test(value))) {\n const message = `Invalid enumeration value. Values should have at least one alphabetical character preceding the first occurence of a number. Update your enumeration '${attrName}'.`;\n\n return this.createError({ message });\n }\n\n // should not contain empty values\n if (regressedValues.some((value: string) => value === '')) {\n return this.createError({\n message: `At least one value of the enumeration '${attrName}' appears to be empty. Only alphanumerical characters are taken into account.`,\n });\n }\n\n // should not collide\n const duplicates = _.uniq(\n regressedValues.filter(\n (value: string, index: number, values: string[]) => values.indexOf(value) !== index\n )\n );\n\n if (duplicates.length) {\n const message = `Some enumeration values of the field '${attrName}' collide when normalized: ${duplicates.join(\n ', '\n )}. Please modify your enumeration.`;\n\n return this.createError({ message });\n }\n }\n }\n\n return true;\n },\n }),\n }),\n actions: yup.object().onlyContainsFunctions(),\n lifecycles: yup.object().shape(lifecyclesShape).noUnknown(),\n});\n\nconst validateContentTypeDefinition = (data: unknown) => {\n return contentTypeSchemaValidator.validateSync(data, { strict: true, abortEarly: false });\n};\n\nexport { validateContentTypeDefinition };\n"],"names":["_","yup","strings"],"mappings":";;;;;;AAIA,MAAM,aAAa;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAcA,MAAM,qBAAqB;AAE3B,MAAM,kBAAkBA,WAAAA,QAAE,UAAUA,WAAA,QAAE,MAAM,UAAU,GAAG,MAAMC,YAAAA,IAAI,MAAM,EAAE,SAAS,EAAE,WAAY,CAAA;AAElG,MAAM,6BAA6BA,YAAA,IAAI,OAAO,EAAE,MAAM;AAAA,EACpD,QAAQA,YAAA,IAAI,OAAO,EAAE,MAAM;AAAA,IACzB,MAAMA,YAAA,IACH,OAAO,EACP,MAAM;AAAA,MACL,aAAaA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,MACnC,cAAcA,YAAAA,IAAI,OAAS,EAAA,YAAA,EAAc,SAAS;AAAA,MAClD,YAAYA,YAAAA,IAAI,OAAS,EAAA,YAAA,EAAc,SAAS;AAAA,IACjD,CAAA,EACA,SAAS;AAAA,IACZ,YAAYA,YAAA,IAAI,OAAO,EAAE,KAAK;AAAA,MAC5B,MAAM;AAAA,MACN,SAAS;AAAA,MACT,KAAK,YAA8C;AACjD,mBAAW,YAAY,OAAO,KAAK,UAAU,GAAG;AACxC,gBAAA,OAAO,WAAW,QAAQ;AAC5B,cAAA,KAAK,SAAS,eAAe;AAC/B,kBAAM,kBAAkB,KAAK,KAAK,IAAIC,YAAAA,QAAQ,oBAAoB;AAG9D,gBAAA,CAAC,gBAAgB,MAAM,CAAC,UAAkB,mBAAmB,KAAK,KAAK,CAAC,GAAG;AACvE,oBAAA,UAAU,yJAAyJ,QAAQ;AAEjL,qBAAO,KAAK,YAAY,EAAE,QAAS,CAAA;AAAA,YACrC;AAGA,gBAAI,gBAAgB,KAAK,CAAC,UAAkB,UAAU,EAAE,GAAG;AACzD,qBAAO,KAAK,YAAY;AAAA,gBACtB,SAAS,0CAA0C,QAAQ;AAAA,cAAA,CAC5D;AAAA,YACH;AAGA,kBAAM,aAAaF,WAAAA,QAAE;AAAA,cACnB,gBAAgB;AAAA,gBACd,CAAC,OAAe,OAAe,WAAqB,OAAO,QAAQ,KAAK,MAAM;AAAA,cAChF;AAAA,YAAA;AAGF,gBAAI,WAAW,QAAQ;AACrB,oBAAM,UAAU,yCAAyC,QAAQ,8BAA8B,WAAW;AAAA,gBACxG;AAAA,cACD,CAAA;AAED,qBAAO,KAAK,YAAY,EAAE,QAAS,CAAA;AAAA,YACrC;AAAA,UACF;AAAA,QACF;AAEO,eAAA;AAAA,MACT;AAAA,IAAA,CACD;AAAA,EAAA,CACF;AAAA,EACD,SAASC,YAAA,IAAI,OAAO,EAAE,sBAAsB;AAAA,EAC5C,YAAYA,YAAI,IAAA,OAAA,EAAS,MAAM,eAAe,EAAE,UAAU;AAC5D,CAAC;AAEK,MAAA,gCAAgC,CAAC,SAAkB;AAChD,SAAA,2BAA2B,aAAa,MAAM,EAAE,QAAQ,MAAM,YAAY,OAAO;AAC1F;;"}
@@ -1,5 +1,5 @@
1
1
  import _ from "lodash";
2
- import { yup, toRegressedEnumValue } from "@strapi/utils";
2
+ import { yup, strings } from "@strapi/utils";
3
3
  const LIFECYCLES = [
4
4
  "beforeCreate",
5
5
  "afterCreate",
@@ -36,7 +36,7 @@ const contentTypeSchemaValidator = yup.object().shape({
36
36
  for (const attrName of Object.keys(attributes)) {
37
37
  const attr = attributes[attrName];
38
38
  if (attr.type === "enumeration") {
39
- const regressedValues = attr.enum.map(toRegressedEnumValue);
39
+ const regressedValues = attr.enum.map(strings.toRegressedEnumValue);
40
40
  if (!regressedValues.every((value) => GRAPHQL_ENUM_REGEX.test(value))) {
41
41
  const message = `Invalid enumeration value. Values should have at least one alphabetical character preceding the first occurence of a number. Update your enumeration '${attrName}'.`;
42
42
  return this.createError({ message });
@@ -1 +1 @@
1
- {"version":3,"file":"validator.mjs","sources":["../../../src/domain/content-type/validator.ts"],"sourcesContent":["import _ from 'lodash';\nimport { yup, toRegressedEnumValue } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\n\nconst LIFECYCLES = [\n 'beforeCreate',\n 'afterCreate',\n 'beforeFindOne',\n 'afterFindOne',\n 'beforeFindMany',\n 'afterFindMany',\n 'beforeCount',\n 'afterCount',\n 'beforeCreateMany',\n 'afterCreateMany',\n 'beforeUpdate',\n 'afterUpdate',\n 'beforeUpdateMany',\n 'afterUpdateMany',\n 'beforeDelete',\n 'afterDelete',\n 'beforeDeleteMany',\n 'afterDeleteMany',\n] as const;\n\n/**\n * For enumerations the least common denomiator is GraphQL, where\n * values needs to match the secure name regex:\n * GraphQL Spec https://spec.graphql.org/June2018/#sec-Names\n *\n * Therefore we need to make sure our users only use values, which\n * can be returned by GraphQL, by checking the regressed values\n * agains the GraphQL regex.\n *\n * TODO V5: check if we can avoid this coupling by moving this logic\n * into the GraphQL plugin.\n */\nconst GRAPHQL_ENUM_REGEX = /^[_A-Za-z][_0-9A-Za-z]*$/;\n\nconst lifecyclesShape = _.mapValues(_.keyBy(LIFECYCLES), () => yup.mixed().nullable().isFunction());\n\nconst contentTypeSchemaValidator = yup.object().shape({\n schema: yup.object().shape({\n info: yup\n .object()\n .shape({\n displayName: yup.string().required(),\n singularName: yup.string().isKebabCase().required(),\n pluralName: yup.string().isKebabCase().required(),\n })\n .required(),\n attributes: yup.object().test({\n name: 'valuesCollide',\n message: 'Some values collide when normalized',\n test(attributes: Schema.ContentType['attributes']) {\n for (const attrName of Object.keys(attributes)) {\n const attr = attributes[attrName];\n if (attr.type === 'enumeration') {\n const regressedValues = attr.enum.map(toRegressedEnumValue);\n\n // should match the GraphQL regex\n if (!regressedValues.every((value: string) => GRAPHQL_ENUM_REGEX.test(value))) {\n const message = `Invalid enumeration value. Values should have at least one alphabetical character preceding the first occurence of a number. Update your enumeration '${attrName}'.`;\n\n return this.createError({ message });\n }\n\n // should not contain empty values\n if (regressedValues.some((value: string) => value === '')) {\n return this.createError({\n message: `At least one value of the enumeration '${attrName}' appears to be empty. Only alphanumerical characters are taken into account.`,\n });\n }\n\n // should not collide\n const duplicates = _.uniq(\n regressedValues.filter(\n (value: string, index: number, values: string[]) => values.indexOf(value) !== index\n )\n );\n\n if (duplicates.length) {\n const message = `Some enumeration values of the field '${attrName}' collide when normalized: ${duplicates.join(\n ', '\n )}. Please modify your enumeration.`;\n\n return this.createError({ message });\n }\n }\n }\n\n return true;\n },\n }),\n }),\n actions: yup.object().onlyContainsFunctions(),\n lifecycles: yup.object().shape(lifecyclesShape).noUnknown(),\n});\n\nconst validateContentTypeDefinition = (data: unknown) => {\n return contentTypeSchemaValidator.validateSync(data, { strict: true, abortEarly: false });\n};\n\nexport { validateContentTypeDefinition };\n"],"names":[],"mappings":";;AAIA,MAAM,aAAa;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAcA,MAAM,qBAAqB;AAE3B,MAAM,kBAAkB,EAAE,UAAU,EAAE,MAAM,UAAU,GAAG,MAAM,IAAI,MAAM,EAAE,SAAS,EAAE,WAAY,CAAA;AAElG,MAAM,6BAA6B,IAAI,OAAO,EAAE,MAAM;AAAA,EACpD,QAAQ,IAAI,OAAO,EAAE,MAAM;AAAA,IACzB,MAAM,IACH,OAAO,EACP,MAAM;AAAA,MACL,aAAa,IAAI,OAAO,EAAE,SAAS;AAAA,MACnC,cAAc,IAAI,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A2B,aAAa,MAAM,EAAE,QAAQ,MAAM,YAAY,OAAO;AAC1F;"}
1
+ {"version":3,"file":"validator.mjs","sources":["../../../src/domain/content-type/validator.ts"],"sourcesContent":["import _ from 'lodash';\nimport { yup, strings } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\n\nconst LIFECYCLES = [\n 'beforeCreate',\n 'afterCreate',\n 'beforeFindOne',\n 'afterFindOne',\n 'beforeFindMany',\n 'afterFindMany',\n 'beforeCount',\n 'afterCount',\n 'beforeCreateMany',\n 'afterCreateMany',\n 'beforeUpdate',\n 'afterUpdate',\n 'beforeUpdateMany',\n 'afterUpdateMany',\n 'beforeDelete',\n 'afterDelete',\n 'beforeDeleteMany',\n 'afterDeleteMany',\n] as const;\n\n/**\n * For enumerations the least common denomiator is GraphQL, where\n * values needs to match the secure name regex:\n * GraphQL Spec https://spec.graphql.org/June2018/#sec-Names\n *\n * Therefore we need to make sure our users only use values, which\n * can be returned by GraphQL, by checking the regressed values\n * agains the GraphQL regex.\n *\n * TODO V5: check if we can avoid this coupling by moving this logic\n * into the GraphQL plugin.\n */\nconst GRAPHQL_ENUM_REGEX = /^[_A-Za-z][_0-9A-Za-z]*$/;\n\nconst lifecyclesShape = _.mapValues(_.keyBy(LIFECYCLES), () => yup.mixed().nullable().isFunction());\n\nconst contentTypeSchemaValidator = yup.object().shape({\n schema: yup.object().shape({\n info: yup\n .object()\n .shape({\n displayName: yup.string().required(),\n singularName: yup.string().isKebabCase().required(),\n pluralName: yup.string().isKebabCase().required(),\n })\n .required(),\n attributes: yup.object().test({\n name: 'valuesCollide',\n message: 'Some values collide when normalized',\n test(attributes: Schema.ContentType['attributes']) {\n for (const attrName of Object.keys(attributes)) {\n const attr = attributes[attrName];\n if (attr.type === 'enumeration') {\n const regressedValues = attr.enum.map(strings.toRegressedEnumValue);\n\n // should match the GraphQL regex\n if (!regressedValues.every((value: string) => GRAPHQL_ENUM_REGEX.test(value))) {\n const message = `Invalid enumeration value. Values should have at least one alphabetical character preceding the first occurence of a number. Update your enumeration '${attrName}'.`;\n\n return this.createError({ message });\n }\n\n // should not contain empty values\n if (regressedValues.some((value: string) => value === '')) {\n return this.createError({\n message: `At least one value of the enumeration '${attrName}' appears to be empty. Only alphanumerical characters are taken into account.`,\n });\n }\n\n // should not collide\n const duplicates = _.uniq(\n regressedValues.filter(\n (value: string, index: number, values: string[]) => values.indexOf(value) !== index\n )\n );\n\n if (duplicates.length) {\n const message = `Some enumeration values of the field '${attrName}' collide when normalized: ${duplicates.join(\n ', '\n )}. Please modify your enumeration.`;\n\n return this.createError({ message });\n }\n }\n }\n\n return true;\n },\n }),\n }),\n actions: yup.object().onlyContainsFunctions(),\n lifecycles: yup.object().shape(lifecyclesShape).noUnknown(),\n});\n\nconst validateContentTypeDefinition = (data: unknown) => {\n return contentTypeSchemaValidator.validateSync(data, { strict: true, abortEarly: false });\n};\n\nexport { validateContentTypeDefinition };\n"],"names":[],"mappings":";;AAIA,MAAM,aAAa;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAcA,MAAM,qBAAqB;AAE3B,MAAM,kBAAkB,EAAE,UAAU,EAAE,MAAM,UAAU,GAAG,MAAM,IAAI,MAAM,EAAE,SAAS,EAAE,WAAY,CAAA;AAElG,MAAM,6BAA6B,IAAI,OAAO,EAAE,MAAM;AAAA,EACpD,QAAQ,IAAI,OAAO,EAAE,MAAM;AAAA,IACzB,MAAM,IACH,OAAO,EACP,MAAM;AAAA,MACL,aAAa,IAAI,OAAO,EAAE,SAAS;AAAA,MACnC,cAAc,IAAI,OAAS,EAAA,YAAA,EAAc,SAAS;AAAA,MAClD,YAAY,IAAI,OAAS,EAAA,YAAA,EAAc,SAAS;AAAA,IACjD,CAAA,EACA,SA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E,MAAM,CAAC,GAAG,CAAC,WAAW,KAAK,MAAM,CAAC,WAAW,CAAC;IACpE,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IACjD,OAAO,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,GAAG,CAAC,OAAO,KAAK,MAAM,CAAC,OAAO,CAAC;IAC7D,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,EAAE,CAAC,UAAU,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC;IACzD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACxC,UAAU,EAAE,CAAC,cAAc,EAAE,MAAM,CAAC,GAAG,CAAC,UAAU,KAAK,MAAM,CAAC,UAAU,CAAC;IACzE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;IAC/C,UAAU,EAAE,CAAC,cAAc,EAAE,MAAM,CAAC,GAAG,CAAC,UAAU,KAAK,MAAM,CAAC,UAAU,CAAC;IACzE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;CAChD;AAiBD,eAAO,MAAM,YAAY,cAAe,MAAM,aAAa,SAAS,UAAU,MAAM,KAAG,MAoFtF,CAAC"}
@@ -6,7 +6,6 @@ const namespace = require("../../registries/namespace.js");
6
6
  const validation = require("./validation.js");
7
7
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
8
8
  const ___default = /* @__PURE__ */ _interopDefault(_);
9
- const uidToPath = (uid) => uid.replace("::", ".");
10
9
  const removeNamespacedKeys = (map, namespace$1) => {
11
10
  return ___default.default.mapKeys(map, (value, key) => namespace.removeNamespace(key, namespace$1));
12
11
  };
@@ -58,13 +57,13 @@ ${e.errors.join("\n")}`);
58
57
  strapi.get("policies").add(namespace2, rawModule.policies);
59
58
  strapi.get("middlewares").add(namespace2, rawModule.middlewares);
60
59
  strapi.get("controllers").add(namespace2, rawModule.controllers);
61
- strapi.get("config").set(uidToPath(namespace2), rawModule.config);
60
+ strapi.get("config").set(namespace2, rawModule.config);
62
61
  },
63
62
  get routes() {
64
63
  return rawModule.routes ?? {};
65
64
  },
66
65
  config(path, defaultValue) {
67
- return strapi.get("config").get(`${uidToPath(namespace2)}.${path}`, defaultValue);
66
+ return strapi.get("config").get(`${namespace2}.${path}`, defaultValue);
68
67
  },
69
68
  contentType(ctName) {
70
69
  return strapi.get("content-types").get(`${namespace2}.${ctName}`);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/domain/module/index.ts"],"sourcesContent":["import _ from 'lodash';\nimport { yup } from '@strapi/utils';\nimport type { Strapi, Common, Schema } from '@strapi/types';\n\nimport { removeNamespace } from '../../registries/namespace';\nimport { validateModule } from './validation';\n\ninterface LifecyclesState {\n bootstrap?: boolean;\n register?: boolean;\n destroy?: boolean;\n}\n\nexport interface RawModule {\n config?: Record<string, unknown>;\n routes?: Common.Module['routes'];\n controllers?: Common.Module['controllers'];\n services?: Common.Module['services'];\n contentTypes?: Common.Module['contentTypes'];\n policies?: Common.Module['policies'];\n middlewares?: Common.Module['middlewares'];\n bootstrap?: (params: { strapi: Strapi }) => Promise<void>;\n register?: (params: { strapi: Strapi }) => Promise<void>;\n destroy?: (params: { strapi: Strapi }) => Promise<void>;\n}\n\nexport interface Module {\n bootstrap: () => Promise<void>;\n register: () => Promise<void>;\n destroy: () => Promise<void>;\n load: () => void;\n routes: Common.Module['routes'];\n config: (path: string, defaultValue?: unknown) => unknown;\n contentType: (ctName: Common.UID.ContentType) => Schema.ContentType;\n contentTypes: Record<string, Schema.ContentType>;\n service: (serviceName: Common.UID.Service) => Common.Service;\n services: Record<string, Common.Service>;\n policy: (policyName: Common.UID.Policy) => Common.Policy;\n policies: Record<string, Common.Policy>;\n middleware: (middlewareName: Common.UID.Middleware) => Common.Middleware;\n middlewares: Record<string, Common.Middleware>;\n controller: (controllerName: Common.UID.Controller) => Common.Controller;\n controllers: Record<string, Common.Controller>;\n}\n\nconst uidToPath = (uid: string) => uid.replace('::', '.');\n\n// Removes the namespace from a map with keys prefixed with a namespace\nconst removeNamespacedKeys = <T extends Record<string, unknown>>(map: T, namespace: string) => {\n return _.mapKeys(map, (value, key) => removeNamespace(key, namespace));\n};\n\nconst defaultModule = {\n config: {},\n routes: [],\n controllers: {},\n services: {},\n contentTypes: {},\n policies: {},\n middlewares: {},\n};\n\nexport const createModule = (namespace: string, rawModule: RawModule, strapi: Strapi): Module => {\n _.defaults(rawModule, defaultModule);\n\n try {\n validateModule(rawModule);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`strapi-server.js is invalid for '${namespace}'.\\n${e.errors.join('\\n')}`);\n }\n }\n\n const called: LifecyclesState = {};\n return {\n async bootstrap() {\n if (called.bootstrap) {\n throw new Error(`Bootstrap for ${namespace} has already been called`);\n }\n called.bootstrap = true;\n await (rawModule.bootstrap && rawModule.bootstrap({ strapi }));\n },\n async register() {\n if (called.register) {\n throw new Error(`Register for ${namespace} has already been called`);\n }\n called.register = true;\n await (rawModule.register && rawModule.register({ strapi }));\n },\n async destroy() {\n if (called.destroy) {\n throw new Error(`Destroy for ${namespace} has already been called`);\n }\n called.destroy = true;\n await (rawModule.destroy && rawModule.destroy({ strapi }));\n },\n load() {\n strapi.get('content-types').add(namespace, rawModule.contentTypes);\n strapi.get('services').add(namespace, rawModule.services);\n strapi.get('policies').add(namespace, rawModule.policies);\n strapi.get('middlewares').add(namespace, rawModule.middlewares);\n strapi.get('controllers').add(namespace, rawModule.controllers);\n strapi.get('config').set(uidToPath(namespace), rawModule.config);\n },\n get routes() {\n return rawModule.routes ?? {};\n },\n config(path: string, defaultValue: unknown) {\n return strapi.get('config').get(`${uidToPath(namespace)}.${path}`, defaultValue);\n },\n contentType(ctName: Common.UID.ContentType) {\n return strapi.get('content-types').get(`${namespace}.${ctName}`);\n },\n get contentTypes() {\n const contentTypes = strapi.get('content-types').getAll(namespace);\n return removeNamespacedKeys(contentTypes, namespace);\n },\n service(serviceName: Common.UID.Service) {\n return strapi.get('services').get(`${namespace}.${serviceName}`);\n },\n get services() {\n const services = strapi.get('services').getAll(namespace);\n return removeNamespacedKeys(services, namespace);\n },\n policy(policyName: Common.UID.Policy) {\n return strapi.get('policies').get(`${namespace}.${policyName}`);\n },\n get policies() {\n const policies = strapi.get('policies').getAll(namespace);\n return removeNamespacedKeys(policies, namespace);\n },\n middleware(middlewareName: Common.UID.Middleware) {\n return strapi.get('middlewares').get(`${namespace}.${middlewareName}`);\n },\n get middlewares() {\n const middlewares = strapi.get('middlewares').getAll(namespace);\n return removeNamespacedKeys(middlewares, namespace);\n },\n controller(controllerName: Common.UID.Controller) {\n return strapi.get('controllers').get(`${namespace}.${controllerName}`);\n },\n get controllers() {\n const controllers = strapi.get('controllers').getAll(namespace);\n return removeNamespacedKeys(controllers, namespace);\n },\n };\n};\n"],"names":["namespace","_","removeNamespace","validateModule","yup"],"mappings":";;;;;;;;AA6CA,MAAM,YAAY,CAAC,QAAgB,IAAI,QAAQ,MAAM,GAAG;AAGxD,MAAM,uBAAuB,CAAoC,KAAQA,gBAAsB;AACtF,SAAAC,WAAA,QAAE,QAAQ,KAAK,CAAC,OAAO,QAAQC,0BAAgB,KAAKF,WAAS,CAAC;AACvE;AAEA,MAAM,gBAAgB;AAAA,EACpB,QAAQ,CAAC;AAAA,EACT,QAAQ,CAAC;AAAA,EACT,aAAa,CAAC;AAAA,EACd,UAAU,CAAC;AAAA,EACX,cAAc,CAAC;AAAA,EACf,UAAU,CAAC;AAAA,EACX,aAAa,CAAC;AAChB;AAEO,MAAM,eAAe,CAACA,YAAmB,WAAsB,WAA2B;AAC7FC,aAAAA,QAAA,SAAS,WAAW,aAAa;AAE/B,MAAA;AACFE,eAAA,eAAe,SAAS;AAAA,WACjB,GAAG;AACN,QAAA,aA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,UAAS;AAAA,IACpD;AAAA,EAAA;AAEJ;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/domain/module/index.ts"],"sourcesContent":["import _ from 'lodash';\nimport { yup } from '@strapi/utils';\nimport type { Strapi, Common, Schema } from '@strapi/types';\n\nimport { removeNamespace } from '../../registries/namespace';\nimport { validateModule } from './validation';\n\ninterface LifecyclesState {\n bootstrap?: boolean;\n register?: boolean;\n destroy?: boolean;\n}\n\nexport interface RawModule {\n config?: Record<string, unknown>;\n routes?: Common.Module['routes'];\n controllers?: Common.Module['controllers'];\n services?: Common.Module['services'];\n contentTypes?: Common.Module['contentTypes'];\n policies?: Common.Module['policies'];\n middlewares?: Common.Module['middlewares'];\n bootstrap?: (params: { strapi: Strapi }) => Promise<void>;\n register?: (params: { strapi: Strapi }) => Promise<void>;\n destroy?: (params: { strapi: Strapi }) => Promise<void>;\n}\n\nexport interface Module {\n bootstrap: () => Promise<void>;\n register: () => Promise<void>;\n destroy: () => Promise<void>;\n load: () => void;\n routes: Common.Module['routes'];\n config: (path: string, defaultValue?: unknown) => unknown;\n contentType: (ctName: Common.UID.ContentType) => Schema.ContentType;\n contentTypes: Record<string, Schema.ContentType>;\n service: (serviceName: Common.UID.Service) => Common.Service;\n services: Record<string, Common.Service>;\n policy: (policyName: Common.UID.Policy) => Common.Policy;\n policies: Record<string, Common.Policy>;\n middleware: (middlewareName: Common.UID.Middleware) => Common.Middleware;\n middlewares: Record<string, Common.Middleware>;\n controller: (controllerName: Common.UID.Controller) => Common.Controller;\n controllers: Record<string, Common.Controller>;\n}\n\n// Removes the namespace from a map with keys prefixed with a namespace\nconst removeNamespacedKeys = <T extends Record<string, unknown>>(map: T, namespace: string) => {\n return _.mapKeys(map, (value, key) => removeNamespace(key, namespace));\n};\n\nconst defaultModule = {\n config: {},\n routes: [],\n controllers: {},\n services: {},\n contentTypes: {},\n policies: {},\n middlewares: {},\n};\n\nexport const createModule = (namespace: string, rawModule: RawModule, strapi: Strapi): Module => {\n _.defaults(rawModule, defaultModule);\n\n try {\n validateModule(rawModule);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`strapi-server.js is invalid for '${namespace}'.\\n${e.errors.join('\\n')}`);\n }\n }\n\n const called: LifecyclesState = {};\n return {\n async bootstrap() {\n if (called.bootstrap) {\n throw new Error(`Bootstrap for ${namespace} has already been called`);\n }\n called.bootstrap = true;\n await (rawModule.bootstrap && rawModule.bootstrap({ strapi }));\n },\n async register() {\n if (called.register) {\n throw new Error(`Register for ${namespace} has already been called`);\n }\n called.register = true;\n await (rawModule.register && rawModule.register({ strapi }));\n },\n async destroy() {\n if (called.destroy) {\n throw new Error(`Destroy for ${namespace} has already been called`);\n }\n called.destroy = true;\n await (rawModule.destroy && rawModule.destroy({ strapi }));\n },\n load() {\n strapi.get('content-types').add(namespace, rawModule.contentTypes);\n strapi.get('services').add(namespace, rawModule.services);\n strapi.get('policies').add(namespace, rawModule.policies);\n strapi.get('middlewares').add(namespace, rawModule.middlewares);\n strapi.get('controllers').add(namespace, rawModule.controllers);\n strapi.get('config').set(namespace, rawModule.config);\n },\n get routes() {\n return rawModule.routes ?? {};\n },\n config(path: string, defaultValue: unknown) {\n return strapi.get('config').get(`${namespace}.${path}`, defaultValue);\n },\n contentType(ctName: Common.UID.ContentType) {\n return strapi.get('content-types').get(`${namespace}.${ctName}`);\n },\n get contentTypes() {\n const contentTypes = strapi.get('content-types').getAll(namespace);\n return removeNamespacedKeys(contentTypes, namespace);\n },\n service(serviceName: Common.UID.Service) {\n return strapi.get('services').get(`${namespace}.${serviceName}`);\n },\n get services() {\n const services = strapi.get('services').getAll(namespace);\n return removeNamespacedKeys(services, namespace);\n },\n policy(policyName: Common.UID.Policy) {\n return strapi.get('policies').get(`${namespace}.${policyName}`);\n },\n get policies() {\n const policies = strapi.get('policies').getAll(namespace);\n return removeNamespacedKeys(policies, namespace);\n },\n middleware(middlewareName: Common.UID.Middleware) {\n return strapi.get('middlewares').get(`${namespace}.${middlewareName}`);\n },\n get middlewares() {\n const middlewares = strapi.get('middlewares').getAll(namespace);\n return removeNamespacedKeys(middlewares, namespace);\n },\n controller(controllerName: Common.UID.Controller) {\n return strapi.get('controllers').get(`${namespace}.${controllerName}`);\n },\n get controllers() {\n const controllers = strapi.get('controllers').getAll(namespace);\n return removeNamespacedKeys(controllers, namespace);\n },\n };\n};\n"],"names":["namespace","_","removeNamespace","validateModule","yup"],"mappings":";;;;;;;;AA8CA,MAAM,uBAAuB,CAAoC,KAAQA,gBAAsB;AACtF,SAAAC,WAAA,QAAE,QAAQ,KAAK,CAAC,OAAO,QAAQC,0BAAgB,KAAKF,WAAS,CAAC;AACvE;AAEA,MAAM,gBAAgB;AAAA,EACpB,QAAQ,CAAC;AAAA,EACT,QAAQ,CAAC;AAAA,EACT,aAAa,CAAC;AAAA,EACd,UAAU,CAAC;AAAA,EACX,cAAc,CAAC;AAAA,EACf,UAAU,CAAC;AAAA,EACX,aAAa,CAAC;AAChB;AAEO,MAAM,eAAe,CAACA,YAAmB,WAAsB,WAA2B;AAC7FC,aAAAA,QAAA,SAAS,WAAW,aAAa;AAE/B,MAAA;AACFE,eAAA,eAAe,SAAS;AAAA,WACjB,GAAG;AACN,QAAA,aAAaC,gBAAI,iBAAiB;AAC9B,YAAA,IAAI,MAAM,oCAAoCJ,UAAS;AAAA,EAAO,EAAE,OAAO,KAAK,IAAI,CAAC,EAAE;AAAA,IAC3F;AAAA,EACF;AAEA,QAAM,SAA0B,CAAA;AACzB,SAAA;AAAA,IACL,MAAM,YAAY;AAChB,UAAI,OAAO,WAAW;AACpB,cAAM,IAAI,MAAM,iBAAiBA,UAAS,0BAA0B;AAAA,MACtE;AACA,aAAO,YAAY;AACnB,aAAO,UAAU,aAAa,UAAU,UAAU,EAAE,OAAQ,CAAA;AAAA,IAC9D;AAAA,IACA,MAAM,WAAW;AACf,UAAI,OAAO,UAAU;AACnB,cAAM,IAAI,MAAM,gBAAgBA,UAAS,0BAA0B;AAAA,MACrE;AACA,aAAO,W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D,aAAA,qBAAqB,UAAUA,UAAS;AAAA,IACjD;AAAA,IACA,OAAO,YAA+B;AAC7B,aAAA,OAAO,IAAI,UAAU,EAAE,IAAI,GAAGA,UAAS,IAAI,UAAU,EAAE;AAAA,IAChE;AAAA,IACA,IAAI,WAAW;AACb,YAAM,WAAW,OAAO,IAAI,UAAU,EAAE,OAAOA,UAAS;AACjD,aAAA,qBAAqB,UAAUA,UAAS;AAAA,IACjD;AAAA,IACA,WAAW,gBAAuC;AACzC,aAAA,OAAO,IAAI,aAAa,EAAE,IAAI,GAAGA,UAAS,IAAI,cAAc,EAAE;AAAA,IACvE;AAAA,IACA,IAAI,cAAc;AAChB,YAAM,cAAc,OAAO,IAAI,aAAa,EAAE,OAAOA,UAAS;AACvD,aAAA,qBAAqB,aAAaA,UAAS;AAAA,IACpD;AAAA,IACA,WAAW,gBAAuC;AACzC,aAAA,OAAO,IAAI,aAAa,EAAE,IAAI,GAAGA,UAAS,IAAI,cAAc,EAAE;AAAA,IACvE;AAAA,IACA,IAAI,cAAc;AAChB,YAAM,cAAc,OAAO,IAAI,aAAa,EAAE,OAAOA,UAAS;AACvD,aAAA,qBAAqB,aAAaA,UAAS;AAAA,IACpD;AAAA,EAAA;AAEJ;;"}
@@ -2,7 +2,6 @@ import _ from "lodash";
2
2
  import { yup } from "@strapi/utils";
3
3
  import { removeNamespace } from "../../registries/namespace.mjs";
4
4
  import { validateModule } from "./validation.mjs";
5
- const uidToPath = (uid) => uid.replace("::", ".");
6
5
  const removeNamespacedKeys = (map, namespace) => {
7
6
  return _.mapKeys(map, (value, key) => removeNamespace(key, namespace));
8
7
  };
@@ -54,13 +53,13 @@ ${e.errors.join("\n")}`);
54
53
  strapi.get("policies").add(namespace, rawModule.policies);
55
54
  strapi.get("middlewares").add(namespace, rawModule.middlewares);
56
55
  strapi.get("controllers").add(namespace, rawModule.controllers);
57
- strapi.get("config").set(uidToPath(namespace), rawModule.config);
56
+ strapi.get("config").set(namespace, rawModule.config);
58
57
  },
59
58
  get routes() {
60
59
  return rawModule.routes ?? {};
61
60
  },
62
61
  config(path, defaultValue) {
63
- return strapi.get("config").get(`${uidToPath(namespace)}.${path}`, defaultValue);
62
+ return strapi.get("config").get(`${namespace}.${path}`, defaultValue);
64
63
  },
65
64
  contentType(ctName) {
66
65
  return strapi.get("content-types").get(`${namespace}.${ctName}`);
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../src/domain/module/index.ts"],"sourcesContent":["import _ from 'lodash';\nimport { yup } from '@strapi/utils';\nimport type { Strapi, Common, Schema } from '@strapi/types';\n\nimport { removeNamespace } from '../../registries/namespace';\nimport { validateModule } from './validation';\n\ninterface LifecyclesState {\n bootstrap?: boolean;\n register?: boolean;\n destroy?: boolean;\n}\n\nexport interface RawModule {\n config?: Record<string, unknown>;\n routes?: Common.Module['routes'];\n controllers?: Common.Module['controllers'];\n services?: Common.Module['services'];\n contentTypes?: Common.Module['contentTypes'];\n policies?: Common.Module['policies'];\n middlewares?: Common.Module['middlewares'];\n bootstrap?: (params: { strapi: Strapi }) => Promise<void>;\n register?: (params: { strapi: Strapi }) => Promise<void>;\n destroy?: (params: { strapi: Strapi }) => Promise<void>;\n}\n\nexport interface Module {\n bootstrap: () => Promise<void>;\n register: () => Promise<void>;\n destroy: () => Promise<void>;\n load: () => void;\n routes: Common.Module['routes'];\n config: (path: string, defaultValue?: unknown) => unknown;\n contentType: (ctName: Common.UID.ContentType) => Schema.ContentType;\n contentTypes: Record<string, Schema.ContentType>;\n service: (serviceName: Common.UID.Service) => Common.Service;\n services: Record<string, Common.Service>;\n policy: (policyName: Common.UID.Policy) => Common.Policy;\n policies: Record<string, Common.Policy>;\n middleware: (middlewareName: Common.UID.Middleware) => Common.Middleware;\n middlewares: Record<string, Common.Middleware>;\n controller: (controllerName: Common.UID.Controller) => Common.Controller;\n controllers: Record<string, Common.Controller>;\n}\n\nconst uidToPath = (uid: string) => uid.replace('::', '.');\n\n// Removes the namespace from a map with keys prefixed with a namespace\nconst removeNamespacedKeys = <T extends Record<string, unknown>>(map: T, namespace: string) => {\n return _.mapKeys(map, (value, key) => removeNamespace(key, namespace));\n};\n\nconst defaultModule = {\n config: {},\n routes: [],\n controllers: {},\n services: {},\n contentTypes: {},\n policies: {},\n middlewares: {},\n};\n\nexport const createModule = (namespace: string, rawModule: RawModule, strapi: Strapi): Module => {\n _.defaults(rawModule, defaultModule);\n\n try {\n validateModule(rawModule);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`strapi-server.js is invalid for '${namespace}'.\\n${e.errors.join('\\n')}`);\n }\n }\n\n const called: LifecyclesState = {};\n return {\n async bootstrap() {\n if (called.bootstrap) {\n throw new Error(`Bootstrap for ${namespace} has already been called`);\n }\n called.bootstrap = true;\n await (rawModule.bootstrap && rawModule.bootstrap({ strapi }));\n },\n async register() {\n if (called.register) {\n throw new Error(`Register for ${namespace} has already been called`);\n }\n called.register = true;\n await (rawModule.register && rawModule.register({ strapi }));\n },\n async destroy() {\n if (called.destroy) {\n throw new Error(`Destroy for ${namespace} has already been called`);\n }\n called.destroy = true;\n await (rawModule.destroy && rawModule.destroy({ strapi }));\n },\n load() {\n strapi.get('content-types').add(namespace, rawModule.contentTypes);\n strapi.get('services').add(namespace, rawModule.services);\n strapi.get('policies').add(namespace, rawModule.policies);\n strapi.get('middlewares').add(namespace, rawModule.middlewares);\n strapi.get('controllers').add(namespace, rawModule.controllers);\n strapi.get('config').set(uidToPath(namespace), rawModule.config);\n },\n get routes() {\n return rawModule.routes ?? {};\n },\n config(path: string, defaultValue: unknown) {\n return strapi.get('config').get(`${uidToPath(namespace)}.${path}`, defaultValue);\n },\n contentType(ctName: Common.UID.ContentType) {\n return strapi.get('content-types').get(`${namespace}.${ctName}`);\n },\n get contentTypes() {\n const contentTypes = strapi.get('content-types').getAll(namespace);\n return removeNamespacedKeys(contentTypes, namespace);\n },\n service(serviceName: Common.UID.Service) {\n return strapi.get('services').get(`${namespace}.${serviceName}`);\n },\n get services() {\n const services = strapi.get('services').getAll(namespace);\n return removeNamespacedKeys(services, namespace);\n },\n policy(policyName: Common.UID.Policy) {\n return strapi.get('policies').get(`${namespace}.${policyName}`);\n },\n get policies() {\n const policies = strapi.get('policies').getAll(namespace);\n return removeNamespacedKeys(policies, namespace);\n },\n middleware(middlewareName: Common.UID.Middleware) {\n return strapi.get('middlewares').get(`${namespace}.${middlewareName}`);\n },\n get middlewares() {\n const middlewares = strapi.get('middlewares').getAll(namespace);\n return removeNamespacedKeys(middlewares, namespace);\n },\n controller(controllerName: Common.UID.Controller) {\n return strapi.get('controllers').get(`${namespace}.${controllerName}`);\n },\n get controllers() {\n const controllers = strapi.get('controllers').getAll(namespace);\n return removeNamespacedKeys(controllers, namespace);\n },\n };\n};\n"],"names":[],"mappings":";;;;AA6CA,MAAM,YAAY,CAAC,QAAgB,IAAI,QAAQ,MAAM,GAAG;AAGxD,MAAM,uBAAuB,CAAoC,KAAQ,cAAsB;AACtF,SAAA,EAAE,QAAQ,KAAK,CAAC,OAAO,QAAQ,gBAAgB,KAAK,SAAS,CAAC;AACvE;AAEA,MAAM,gBAAgB;AAAA,EACpB,QAAQ,CAAC;AAAA,EACT,QAAQ,CAAC;AAAA,EACT,aAAa,CAAC;AAAA,EACd,UAAU,CAAC;AAAA,EACX,cAAc,CAAC;AAAA,EACf,UAAU,CAAC;AAAA,EACX,aAAa,CAAC;AAChB;AAEO,MAAM,eAAe,CAAC,WAAmB,WAAsB,WAA2B;AAC7F,IAAA,SAAS,WAAW,aAAa;AAE/B,MAAA;AACF,mBAAe,SAAS;AAAA,WACjB,GAAG;AACN,QAAA,aAAa,IAAI,iBAAiB;AAC9B,YAAA,IAAI,MAAM,oCAAoC,SAAS;AAAA,EAAO,EAAE,OAAO,KAAK,IAAI,CAAC,EAAE;AAAA,IAC3F;AAAA,EACF;AAEA,QAAM,SAA0B,CAAA;AACzB,SAAA;AAAA,IACL,MAAM,YAAY;AAChB,UAAI,OAAO,WAAW;AACpB,cAAM,IAAI,M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AE,OAAO,SAAS;AAC1D,aAAA,qBAAqB,cAAc,SAAS;AAAA,IACrD;AAAA,IACA,QAAQ,aAAiC;AAChC,aAAA,OAAO,IAAI,UAAU,EAAE,IAAI,GAAG,SAAS,IAAI,WAAW,EAAE;AAAA,IACjE;AAAA,IACA,IAAI,WAAW;AACb,YAAM,WAAW,OAAO,IAAI,UAAU,EAAE,OAAO,SAAS;AACjD,aAAA,qBAAqB,UAAU,SAAS;AAAA,IACjD;AAAA,IACA,OAAO,YAA+B;AAC7B,aAAA,OAAO,IAAI,UAAU,EAAE,IAAI,GAAG,SAAS,IAAI,UAAU,EAAE;AAAA,IAChE;AAAA,IACA,IAAI,WAAW;AACb,YAAM,WAAW,OAAO,IAAI,UAAU,EAAE,OAAO,SAAS;AACjD,aAAA,qBAAqB,UAAU,SAAS;AAAA,IACjD;AAAA,IACA,WAAW,gBAAuC;AACzC,aAAA,OAAO,IAAI,aAAa,EAAE,IAAI,GAAG,SAAS,IAAI,cAAc,EAAE;AAAA,IACvE;AAAA,IACA,IAAI,cAAc;AAChB,YAAM,cAAc,OAAO,IAAI,aAAa,EAAE,OAAO,SAAS;AACvD,aAAA,qBAAqB,aAAa,SAAS;AAAA,IACpD;AAAA,IACA,WAAW,gBAAuC;AACzC,aAAA,OAAO,IAAI,aAAa,EAAE,IAAI,GAAG,SAAS,IAAI,cAAc,EAAE;AAAA,IACvE;AAAA,IACA,IAAI,cAAc;AAChB,YAAM,cAAc,OAAO,IAAI,aAAa,EAAE,OAAO,SAAS;AACvD,aAAA,qBAAqB,aAAa,SAAS;AAAA,IACpD;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../src/domain/module/index.ts"],"sourcesContent":["import _ from 'lodash';\nimport { yup } from '@strapi/utils';\nimport type { Strapi, Common, Schema } from '@strapi/types';\n\nimport { removeNamespace } from '../../registries/namespace';\nimport { validateModule } from './validation';\n\ninterface LifecyclesState {\n bootstrap?: boolean;\n register?: boolean;\n destroy?: boolean;\n}\n\nexport interface RawModule {\n config?: Record<string, unknown>;\n routes?: Common.Module['routes'];\n controllers?: Common.Module['controllers'];\n services?: Common.Module['services'];\n contentTypes?: Common.Module['contentTypes'];\n policies?: Common.Module['policies'];\n middlewares?: Common.Module['middlewares'];\n bootstrap?: (params: { strapi: Strapi }) => Promise<void>;\n register?: (params: { strapi: Strapi }) => Promise<void>;\n destroy?: (params: { strapi: Strapi }) => Promise<void>;\n}\n\nexport interface Module {\n bootstrap: () => Promise<void>;\n register: () => Promise<void>;\n destroy: () => Promise<void>;\n load: () => void;\n routes: Common.Module['routes'];\n config: (path: string, defaultValue?: unknown) => unknown;\n contentType: (ctName: Common.UID.ContentType) => Schema.ContentType;\n contentTypes: Record<string, Schema.ContentType>;\n service: (serviceName: Common.UID.Service) => Common.Service;\n services: Record<string, Common.Service>;\n policy: (policyName: Common.UID.Policy) => Common.Policy;\n policies: Record<string, Common.Policy>;\n middleware: (middlewareName: Common.UID.Middleware) => Common.Middleware;\n middlewares: Record<string, Common.Middleware>;\n controller: (controllerName: Common.UID.Controller) => Common.Controller;\n controllers: Record<string, Common.Controller>;\n}\n\n// Removes the namespace from a map with keys prefixed with a namespace\nconst removeNamespacedKeys = <T extends Record<string, unknown>>(map: T, namespace: string) => {\n return _.mapKeys(map, (value, key) => removeNamespace(key, namespace));\n};\n\nconst defaultModule = {\n config: {},\n routes: [],\n controllers: {},\n services: {},\n contentTypes: {},\n policies: {},\n middlewares: {},\n};\n\nexport const createModule = (namespace: string, rawModule: RawModule, strapi: Strapi): Module => {\n _.defaults(rawModule, defaultModule);\n\n try {\n validateModule(rawModule);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`strapi-server.js is invalid for '${namespace}'.\\n${e.errors.join('\\n')}`);\n }\n }\n\n const called: LifecyclesState = {};\n return {\n async bootstrap() {\n if (called.bootstrap) {\n throw new Error(`Bootstrap for ${namespace} has already been called`);\n }\n called.bootstrap = true;\n await (rawModule.bootstrap && rawModule.bootstrap({ strapi }));\n },\n async register() {\n if (called.register) {\n throw new Error(`Register for ${namespace} has already been called`);\n }\n called.register = true;\n await (rawModule.register && rawModule.register({ strapi }));\n },\n async destroy() {\n if (called.destroy) {\n throw new Error(`Destroy for ${namespace} has already been called`);\n }\n called.destroy = true;\n await (rawModule.destroy && rawModule.destroy({ strapi }));\n },\n load() {\n strapi.get('content-types').add(namespace, rawModule.contentTypes);\n strapi.get('services').add(namespace, rawModule.services);\n strapi.get('policies').add(namespace, rawModule.policies);\n strapi.get('middlewares').add(namespace, rawModule.middlewares);\n strapi.get('controllers').add(namespace, rawModule.controllers);\n strapi.get('config').set(namespace, rawModule.config);\n },\n get routes() {\n return rawModule.routes ?? {};\n },\n config(path: string, defaultValue: unknown) {\n return strapi.get('config').get(`${namespace}.${path}`, defaultValue);\n },\n contentType(ctName: Common.UID.ContentType) {\n return strapi.get('content-types').get(`${namespace}.${ctName}`);\n },\n get contentTypes() {\n const contentTypes = strapi.get('content-types').getAll(namespace);\n return removeNamespacedKeys(contentTypes, namespace);\n },\n service(serviceName: Common.UID.Service) {\n return strapi.get('services').get(`${namespace}.${serviceName}`);\n },\n get services() {\n const services = strapi.get('services').getAll(namespace);\n return removeNamespacedKeys(services, namespace);\n },\n policy(policyName: Common.UID.Policy) {\n return strapi.get('policies').get(`${namespace}.${policyName}`);\n },\n get policies() {\n const policies = strapi.get('policies').getAll(namespace);\n return removeNamespacedKeys(policies, namespace);\n },\n middleware(middlewareName: Common.UID.Middleware) {\n return strapi.get('middlewares').get(`${namespace}.${middlewareName}`);\n },\n get middlewares() {\n const middlewares = strapi.get('middlewares').getAll(namespace);\n return removeNamespacedKeys(middlewares, namespace);\n },\n controller(controllerName: Common.UID.Controller) {\n return strapi.get('controllers').get(`${namespace}.${controllerName}`);\n },\n get controllers() {\n const controllers = strapi.get('controllers').getAll(namespace);\n return removeNamespacedKeys(controllers, namespace);\n },\n };\n};\n"],"names":[],"mappings":";;;;AA8CA,MAAM,uBAAuB,CAAoC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SAAS,IAAI,cAAc,EAAE;AAAA,IACvE;AAAA,IACA,IAAI,cAAc;AAChB,YAAM,cAAc,OAAO,IAAI,aAAa,EAAE,OAAO,SAAS;AACvD,aAAA,qBAAqB,aAAa,SAAS;AAAA,IACpD;AAAA,IACA,WAAW,gBAAuC;AACzC,aAAA,OAAO,IAAI,aAAa,EAAE,IAAI,GAAG,SAAS,IAAI,cAAc,EAAE;AAAA,IACvE;AAAA,IACA,IAAI,cAAc;AAChB,YAAM,cAAc,OAAO,IAAI,aAAa,EAAE,OAAO,SAAS;AACvD,aAAA,qBAAqB,aAAa,SAAS;AAAA,IACpD;AAAA,EAAA;AAEJ;"}
@@ -13,7 +13,7 @@ const DEFAULT_CONTENT_TYPE = {
13
13
  actions: {},
14
14
  lifecycles: {}
15
15
  };
16
- const normalizeName = (name) => strapiUtils.isKebabCase(name) ? name : ___default.default.kebabCase(name);
16
+ const normalizeName = (name) => strapiUtils.strings.isKebabCase(name) ? name : ___default.default.kebabCase(name);
17
17
  const isDirectory = (fd) => fd.isDirectory();
18
18
  const isDotFile = (fd) => fd.name.startsWith(".");
19
19
  async function loadAPIs(strapi) {
@@ -1 +1 @@
1
- {"version":3,"file":"apis.js","sources":["../../src/loaders/apis.ts"],"sourcesContent":["import { join, extname, basename } from 'path';\nimport fse, { existsSync } from 'fs-extra';\nimport _ from 'lodash';\nimport { isKebabCase, importDefault } from '@strapi/utils';\nimport { isEmpty } from 'lodash/fp';\nimport type { Strapi, Common, Schema } from '@strapi/types';\nimport { getGlobalId, type ContentTypeDefinition } from '../domain/content-type';\n\ninterface API {\n bootstrap: () => void | Promise<void>;\n destroy: () => void | Promise<void>;\n register: () => void | Promise<void>;\n config: Record<string, unknown>;\n routes: Record<string, Common.Router>;\n controllers: Record<string, Common.Controller>;\n services: Record<string, Common.Service>;\n policies: Record<string, Common.Policy>;\n middlewares: Record<string, Common.Middleware>;\n contentTypes: Record<string, { schema: Schema.ContentType }>;\n}\n\ninterface APIs {\n [key: string]: API;\n}\n\nconst DEFAULT_CONTENT_TYPE = {\n schema: {},\n actions: {},\n lifecycles: {},\n};\n\n// to handle names with numbers in it we first check if it is already in kebabCase\nconst normalizeName = (name: string) => (isKebabCase(name) ? name : _.kebabCase(name));\n\nconst isDirectory = (fd: fse.Dirent) => fd.isDirectory();\nconst isDotFile = (fd: fse.Dirent) => fd.name.startsWith('.');\n\nexport default async function loadAPIs(strapi: Strapi) {\n if (!existsSync(strapi.dirs.dist.api)) {\n return;\n }\n\n const apisFDs = await (await fse.readdir(strapi.dirs.dist.api, { withFileTypes: true }))\n .filter(isDirectory)\n .filter(_.negate(isDotFile));\n\n const apis: APIs = {};\n\n // only load folders\n for (const apiFD of apisFDs) {\n const apiName = normalizeName(apiFD.name);\n const api = await loadAPI(apiName, join(strapi.dirs.dist.api, apiFD.name));\n\n apis[apiName] = api;\n }\n\n validateContentTypesUnicity(apis);\n\n for (const apiName of Object.keys(apis)) {\n strapi.get('apis').add(apiName, apis[apiName]);\n }\n}\n\nconst validateContentTypesUnicity = (apis: APIs) => {\n const allApisSchemas = Object.values(apis).flatMap((api) => Object.values(api.contentTypes));\n\n const names: string[] = [];\n allApisSchemas.forEach(({ schema }) => {\n if (schema.info.singularName) {\n const singularName = _.kebabCase(schema.info.singularName);\n if (names.includes(singularName)) {\n throw new Error(`The singular name \"${schema.info.singularName}\" should be unique`);\n }\n names.push(singularName);\n }\n\n if (schema.info.pluralName) {\n const pluralName = _.kebabCase(schema.info.pluralName);\n if (names.includes(pluralName)) {\n throw new Error(`The plural name \"${schema.info.pluralName}\" should be unique`);\n }\n names.push(pluralName);\n }\n });\n};\n\nconst loadAPI = async (apiName: string, dir: string) => {\n const [index, config, routes, controllers, services, policies, middlewares, contentTypes] =\n await Promise.all([\n loadIndex(dir),\n loadDir(join(dir, 'config')),\n loadDir(join(dir, 'routes')),\n loadDir(join(dir, 'controllers')),\n loadDir(join(dir, 'services')),\n loadDir(join(dir, 'policies')),\n loadDir(join(dir, 'middlewares')),\n loadContentTypes(apiName, join(dir, 'content-types')),\n ]);\n\n return {\n ...(index || {}),\n config: config || {},\n routes: routes || [],\n controllers: controllers || {},\n services: services || {},\n policies: policies || {},\n middlewares: middlewares || {},\n contentTypes: contentTypes || {},\n };\n};\n\nconst loadIndex = async (dir: string) => {\n if (await fse.pathExists(join(dir, 'index.js'))) {\n return loadFile(join(dir, 'index.js'));\n }\n};\n\nconst loadContentTypes = async (apiName: string, dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n const contentTypes: API['contentTypes'] = {};\n\n // only load folders\n for (const fd of fds) {\n if (fd.isFile()) {\n continue;\n }\n\n const contentTypeName = normalizeName(fd.name);\n const loadedContentType = await loadDir(join(dir, fd.name));\n\n if (isEmpty(loadedContentType) || isEmpty(loadedContentType.schema)) {\n throw new Error(`Could not load content type found at ${dir}`);\n }\n\n const contentType = {\n ...DEFAULT_CONTENT_TYPE,\n ...loadedContentType,\n } as ContentTypeDefinition;\n\n Object.assign(contentType.schema, {\n apiName,\n collectionName: contentType.schema.collectionName || contentType.schema.info.singularName,\n globalId: getGlobalId(contentType.schema),\n });\n\n contentTypes[normalizeName(contentTypeName)] = contentType;\n }\n\n return contentTypes;\n};\n\nconst loadDir = async (dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n\n const root: Record<string, unknown> = {};\n for (const fd of fds) {\n if (!fd.isFile() || extname(fd.name) === '.map') {\n continue;\n }\n\n const key = basename(fd.name, extname(fd.name));\n\n root[normalizeName(key)] = await loadFile(join(dir, fd.name));\n }\n\n return root;\n};\n\nconst loadFile = (file: string) => {\n const ext = extname(file);\n\n switch (ext) {\n case '.js':\n return importDefault(file);\n case '.json':\n return fse.readJSON(file);\n default:\n return {};\n }\n};\n"],"names":["isKebabCase","_","existsSync","fse","join","index","isEmpty","getGlobalId","extname","basename","importDefault"],"mappings":";;;;;;;;;;AAyBA,M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M,MAAMC,KAAS,SAAA,GAAG,MAAMD,KAAAA,QAAQ,GAAG,IAAI,CAAC;AAEzC,SAAA,cAAc,GAAG,CAAC,IAAI,MAAM,SAASJ,KAAK,KAAA,KAAK,GAAG,IAAI,CAAC;AAAA,EAC9D;AAEO,SAAA;AACT;AAEA,MAAM,WAAW,CAAC,SAAiB;AAC3B,QAAA,MAAMI,aAAQ,IAAI;AAExB,UAAQ,KAAK;AAAA,IACX,KAAK;AACH,aAAOE,YAAAA,cAAc,IAAI;AAAA,IAC3B,KAAK;AACI,aAAAP,aAAA,QAAI,SAAS,IAAI;AAAA,IAC1B;AACE,aAAO;EACX;AACF;;"}
1
+ {"version":3,"file":"apis.js","sources":["../../src/loaders/apis.ts"],"sourcesContent":["import { join, extname, basename } from 'path';\nimport fse, { existsSync } from 'fs-extra';\nimport _ from 'lodash';\nimport { strings, importDefault } from '@strapi/utils';\nimport { isEmpty } from 'lodash/fp';\nimport type { Strapi, Common, Schema } from '@strapi/types';\nimport { getGlobalId, type ContentTypeDefinition } from '../domain/content-type';\n\ninterface API {\n bootstrap: () => void | Promise<void>;\n destroy: () => void | Promise<void>;\n register: () => void | Promise<void>;\n config: Record<string, unknown>;\n routes: Record<string, Common.Router>;\n controllers: Record<string, Common.Controller>;\n services: Record<string, Common.Service>;\n policies: Record<string, Common.Policy>;\n middlewares: Record<string, Common.Middleware>;\n contentTypes: Record<string, { schema: Schema.ContentType }>;\n}\n\ninterface APIs {\n [key: string]: API;\n}\n\nconst DEFAULT_CONTENT_TYPE = {\n schema: {},\n actions: {},\n lifecycles: {},\n};\n\n// to handle names with numbers in it we first check if it is already in kebabCase\nconst normalizeName = (name: string) => (strings.isKebabCase(name) ? name : _.kebabCase(name));\n\nconst isDirectory = (fd: fse.Dirent) => fd.isDirectory();\nconst isDotFile = (fd: fse.Dirent) => fd.name.startsWith('.');\n\nexport default async function loadAPIs(strapi: Strapi) {\n if (!existsSync(strapi.dirs.dist.api)) {\n return;\n }\n\n const apisFDs = await (await fse.readdir(strapi.dirs.dist.api, { withFileTypes: true }))\n .filter(isDirectory)\n .filter(_.negate(isDotFile));\n\n const apis: APIs = {};\n\n // only load folders\n for (const apiFD of apisFDs) {\n const apiName = normalizeName(apiFD.name);\n const api = await loadAPI(apiName, join(strapi.dirs.dist.api, apiFD.name));\n\n apis[apiName] = api;\n }\n\n validateContentTypesUnicity(apis);\n\n for (const apiName of Object.keys(apis)) {\n strapi.get('apis').add(apiName, apis[apiName]);\n }\n}\n\nconst validateContentTypesUnicity = (apis: APIs) => {\n const allApisSchemas = Object.values(apis).flatMap((api) => Object.values(api.contentTypes));\n\n const names: string[] = [];\n allApisSchemas.forEach(({ schema }) => {\n if (schema.info.singularName) {\n const singularName = _.kebabCase(schema.info.singularName);\n if (names.includes(singularName)) {\n throw new Error(`The singular name \"${schema.info.singularName}\" should be unique`);\n }\n names.push(singularName);\n }\n\n if (schema.info.pluralName) {\n const pluralName = _.kebabCase(schema.info.pluralName);\n if (names.includes(pluralName)) {\n throw new Error(`The plural name \"${schema.info.pluralName}\" should be unique`);\n }\n names.push(pluralName);\n }\n });\n};\n\nconst loadAPI = async (apiName: string, dir: string) => {\n const [index, config, routes, controllers, services, policies, middlewares, contentTypes] =\n await Promise.all([\n loadIndex(dir),\n loadDir(join(dir, 'config')),\n loadDir(join(dir, 'routes')),\n loadDir(join(dir, 'controllers')),\n loadDir(join(dir, 'services')),\n loadDir(join(dir, 'policies')),\n loadDir(join(dir, 'middlewares')),\n loadContentTypes(apiName, join(dir, 'content-types')),\n ]);\n\n return {\n ...(index || {}),\n config: config || {},\n routes: routes || [],\n controllers: controllers || {},\n services: services || {},\n policies: policies || {},\n middlewares: middlewares || {},\n contentTypes: contentTypes || {},\n };\n};\n\nconst loadIndex = async (dir: string) => {\n if (await fse.pathExists(join(dir, 'index.js'))) {\n return loadFile(join(dir, 'index.js'));\n }\n};\n\nconst loadContentTypes = async (apiName: string, dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n const contentTypes: API['contentTypes'] = {};\n\n // only load folders\n for (const fd of fds) {\n if (fd.isFile()) {\n continue;\n }\n\n const contentTypeName = normalizeName(fd.name);\n const loadedContentType = await loadDir(join(dir, fd.name));\n\n if (isEmpty(loadedContentType) || isEmpty(loadedContentType.schema)) {\n throw new Error(`Could not load content type found at ${dir}`);\n }\n\n const contentType = {\n ...DEFAULT_CONTENT_TYPE,\n ...loadedContentType,\n } as ContentTypeDefinition;\n\n Object.assign(contentType.schema, {\n apiName,\n collectionName: contentType.schema.collectionName || contentType.schema.info.singularName,\n globalId: getGlobalId(contentType.schema),\n });\n\n contentTypes[normalizeName(contentTypeName)] = contentType;\n }\n\n return contentTypes;\n};\n\nconst loadDir = async (dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n\n const root: Record<string, unknown> = {};\n for (const fd of fds) {\n if (!fd.isFile() || extname(fd.name) === '.map') {\n continue;\n }\n\n const key = basename(fd.name, extname(fd.name));\n\n root[normalizeName(key)] = await loadFile(join(dir, fd.name));\n }\n\n return root;\n};\n\nconst loadFile = (file: string) => {\n const ext = extname(file);\n\n switch (ext) {\n case '.js':\n return importDefault(file);\n case '.json':\n return fse.readJSON(file);\n default:\n return {};\n }\n};\n"],"names":["strings","_","existsSync","fse","join","index","isEmpty","getGlobalId","extname","basename","importDefault"],"mappings":";;;;;;;;;;AAyBA,MAAM,uBAAuB;AAAA,EAC3B,QAAQ,CAAC;AAAA,EACT,SAAS,CAAC;AAAA,EACV,YAAY,CAAC;AACf;AAGA,MAAM,gBAAgB,CAAC,SAAkBA,YAAQ,QAAA,YAAY,IAAI,IAAI,OAAOC,WAAE,QAAA,UAAU,IAAI;AAE5F,MAAM,cAAc,CAAC,OAAmB,GAAG,YAAY;AACvD,MAAM,YAAY,CAAC,OAAmB,GAAG,KAAK,WAAW,GAAG;AAE5D,eAA8B,SAAS,QAAgB;AACr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AI;AAAA,IAC3B,KAAK;AACI,aAAAP,aAAA,QAAI,SAAS,IAAI;AAAA,IAC1B;AACE,aAAO;EACX;AACF;;"}
@@ -1,7 +1,7 @@
1
1
  import { join, extname, basename } from "path";
2
2
  import fse, { existsSync } from "fs-extra";
3
3
  import _ from "lodash";
4
- import { isKebabCase, importDefault } from "@strapi/utils";
4
+ import { strings, importDefault } from "@strapi/utils";
5
5
  import { isEmpty } from "lodash/fp";
6
6
  import { getGlobalId } from "../domain/content-type/index.mjs";
7
7
  const DEFAULT_CONTENT_TYPE = {
@@ -9,7 +9,7 @@ const DEFAULT_CONTENT_TYPE = {
9
9
  actions: {},
10
10
  lifecycles: {}
11
11
  };
12
- const normalizeName = (name) => isKebabCase(name) ? name : _.kebabCase(name);
12
+ const normalizeName = (name) => strings.isKebabCase(name) ? name : _.kebabCase(name);
13
13
  const isDirectory = (fd) => fd.isDirectory();
14
14
  const isDotFile = (fd) => fd.name.startsWith(".");
15
15
  async function loadAPIs(strapi) {
@@ -1 +1 @@
1
- {"version":3,"file":"apis.mjs","sources":["../../src/loaders/apis.ts"],"sourcesContent":["import { join, extname, basename } from 'path';\nimport fse, { existsSync } from 'fs-extra';\nimport _ from 'lodash';\nimport { isKebabCase, importDefault } from '@strapi/utils';\nimport { isEmpty } from 'lodash/fp';\nimport type { Strapi, Common, Schema } from '@strapi/types';\nimport { getGlobalId, type ContentTypeDefinition } from '../domain/content-type';\n\ninterface API {\n bootstrap: () => void | Promise<void>;\n destroy: () => void | Promise<void>;\n register: () => void | Promise<void>;\n config: Record<string, unknown>;\n routes: Record<string, Common.Router>;\n controllers: Record<string, Common.Controller>;\n services: Record<string, Common.Service>;\n policies: Record<string, Common.Policy>;\n middlewares: Record<string, Common.Middleware>;\n contentTypes: Record<string, { schema: Schema.ContentType }>;\n}\n\ninterface APIs {\n [key: string]: API;\n}\n\nconst DEFAULT_CONTENT_TYPE = {\n schema: {},\n actions: {},\n lifecycles: {},\n};\n\n// to handle names with numbers in it we first check if it is already in kebabCase\nconst normalizeName = (name: string) => (isKebabCase(name) ? name : _.kebabCase(name));\n\nconst isDirectory = (fd: fse.Dirent) => fd.isDirectory();\nconst isDotFile = (fd: fse.Dirent) => fd.name.startsWith('.');\n\nexport default async function loadAPIs(strapi: Strapi) {\n if (!existsSync(strapi.dirs.dist.api)) {\n return;\n }\n\n const apisFDs = await (await fse.readdir(strapi.dirs.dist.api, { withFileTypes: true }))\n .filter(isDirectory)\n .filter(_.negate(isDotFile));\n\n const apis: APIs = {};\n\n // only load folders\n for (const apiFD of apisFDs) {\n const apiName = normalizeName(apiFD.name);\n const api = await loadAPI(apiName, join(strapi.dirs.dist.api, apiFD.name));\n\n apis[apiName] = api;\n }\n\n validateContentTypesUnicity(apis);\n\n for (const apiName of Object.keys(apis)) {\n strapi.get('apis').add(apiName, apis[apiName]);\n }\n}\n\nconst validateContentTypesUnicity = (apis: APIs) => {\n const allApisSchemas = Object.values(apis).flatMap((api) => Object.values(api.contentTypes));\n\n const names: string[] = [];\n allApisSchemas.forEach(({ schema }) => {\n if (schema.info.singularName) {\n const singularName = _.kebabCase(schema.info.singularName);\n if (names.includes(singularName)) {\n throw new Error(`The singular name \"${schema.info.singularName}\" should be unique`);\n }\n names.push(singularName);\n }\n\n if (schema.info.pluralName) {\n const pluralName = _.kebabCase(schema.info.pluralName);\n if (names.includes(pluralName)) {\n throw new Error(`The plural name \"${schema.info.pluralName}\" should be unique`);\n }\n names.push(pluralName);\n }\n });\n};\n\nconst loadAPI = async (apiName: string, dir: string) => {\n const [index, config, routes, controllers, services, policies, middlewares, contentTypes] =\n await Promise.all([\n loadIndex(dir),\n loadDir(join(dir, 'config')),\n loadDir(join(dir, 'routes')),\n loadDir(join(dir, 'controllers')),\n loadDir(join(dir, 'services')),\n loadDir(join(dir, 'policies')),\n loadDir(join(dir, 'middlewares')),\n loadContentTypes(apiName, join(dir, 'content-types')),\n ]);\n\n return {\n ...(index || {}),\n config: config || {},\n routes: routes || [],\n controllers: controllers || {},\n services: services || {},\n policies: policies || {},\n middlewares: middlewares || {},\n contentTypes: contentTypes || {},\n };\n};\n\nconst loadIndex = async (dir: string) => {\n if (await fse.pathExists(join(dir, 'index.js'))) {\n return loadFile(join(dir, 'index.js'));\n }\n};\n\nconst loadContentTypes = async (apiName: string, dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n const contentTypes: API['contentTypes'] = {};\n\n // only load folders\n for (const fd of fds) {\n if (fd.isFile()) {\n continue;\n }\n\n const contentTypeName = normalizeName(fd.name);\n const loadedContentType = await loadDir(join(dir, fd.name));\n\n if (isEmpty(loadedContentType) || isEmpty(loadedContentType.schema)) {\n throw new Error(`Could not load content type found at ${dir}`);\n }\n\n const contentType = {\n ...DEFAULT_CONTENT_TYPE,\n ...loadedContentType,\n } as ContentTypeDefinition;\n\n Object.assign(contentType.schema, {\n apiName,\n collectionName: contentType.schema.collectionName || contentType.schema.info.singularName,\n globalId: getGlobalId(contentType.schema),\n });\n\n contentTypes[normalizeName(contentTypeName)] = contentType;\n }\n\n return contentTypes;\n};\n\nconst loadDir = async (dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n\n const root: Record<string, unknown> = {};\n for (const fd of fds) {\n if (!fd.isFile() || extname(fd.name) === '.map') {\n continue;\n }\n\n const key = basename(fd.name, extname(fd.name));\n\n root[normalizeName(key)] = await loadFile(join(dir, fd.name));\n }\n\n return root;\n};\n\nconst loadFile = (file: string) => {\n const ext = extname(file);\n\n switch (ext) {\n case '.js':\n return importDefault(file);\n case '.json':\n return fse.readJSON(file);\n default:\n return {};\n }\n};\n"],"names":[],"mappings":";;;;;;AAyBA,MAAM,uBAAuB;AAAA,EAC3B,QAAQ,CAAC;AAAA,EACT,SAAS,CAAC;AAAA,EACV,YAAY,CAAC;AACf;AAGA,MAAM,gBAAgB,CAAC,SAAkB,YAAY,IAAI,IAAI,OAAO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AI;AAAA,IAC1B;AACE,aAAO;EACX;AACF;"}
1
+ {"version":3,"file":"apis.mjs","sources":["../../src/loaders/apis.ts"],"sourcesContent":["import { join, extname, basename } from 'path';\nimport fse, { existsSync } from 'fs-extra';\nimport _ from 'lodash';\nimport { strings, importDefault } from '@strapi/utils';\nimport { isEmpty } from 'lodash/fp';\nimport type { Strapi, Common, Schema } from '@strapi/types';\nimport { getGlobalId, type ContentTypeDefinition } from '../domain/content-type';\n\ninterface API {\n bootstrap: () => void | Promise<void>;\n destroy: () => void | Promise<void>;\n register: () => void | Promise<void>;\n config: Record<string, unknown>;\n routes: Record<string, Common.Router>;\n controllers: Record<string, Common.Controller>;\n services: Record<string, Common.Service>;\n policies: Record<string, Common.Policy>;\n middlewares: Record<string, Common.Middleware>;\n contentTypes: Record<string, { schema: Schema.ContentType }>;\n}\n\ninterface APIs {\n [key: string]: API;\n}\n\nconst DEFAULT_CONTENT_TYPE = {\n schema: {},\n actions: {},\n lifecycles: {},\n};\n\n// to handle names with numbers in it we first check if it is already in kebabCase\nconst normalizeName = (name: string) => (strings.isKebabCase(name) ? name : _.kebabCase(name));\n\nconst isDirectory = (fd: fse.Dirent) => fd.isDirectory();\nconst isDotFile = (fd: fse.Dirent) => fd.name.startsWith('.');\n\nexport default async function loadAPIs(strapi: Strapi) {\n if (!existsSync(strapi.dirs.dist.api)) {\n return;\n }\n\n const apisFDs = await (await fse.readdir(strapi.dirs.dist.api, { withFileTypes: true }))\n .filter(isDirectory)\n .filter(_.negate(isDotFile));\n\n const apis: APIs = {};\n\n // only load folders\n for (const apiFD of apisFDs) {\n const apiName = normalizeName(apiFD.name);\n const api = await loadAPI(apiName, join(strapi.dirs.dist.api, apiFD.name));\n\n apis[apiName] = api;\n }\n\n validateContentTypesUnicity(apis);\n\n for (const apiName of Object.keys(apis)) {\n strapi.get('apis').add(apiName, apis[apiName]);\n }\n}\n\nconst validateContentTypesUnicity = (apis: APIs) => {\n const allApisSchemas = Object.values(apis).flatMap((api) => Object.values(api.contentTypes));\n\n const names: string[] = [];\n allApisSchemas.forEach(({ schema }) => {\n if (schema.info.singularName) {\n const singularName = _.kebabCase(schema.info.singularName);\n if (names.includes(singularName)) {\n throw new Error(`The singular name \"${schema.info.singularName}\" should be unique`);\n }\n names.push(singularName);\n }\n\n if (schema.info.pluralName) {\n const pluralName = _.kebabCase(schema.info.pluralName);\n if (names.includes(pluralName)) {\n throw new Error(`The plural name \"${schema.info.pluralName}\" should be unique`);\n }\n names.push(pluralName);\n }\n });\n};\n\nconst loadAPI = async (apiName: string, dir: string) => {\n const [index, config, routes, controllers, services, policies, middlewares, contentTypes] =\n await Promise.all([\n loadIndex(dir),\n loadDir(join(dir, 'config')),\n loadDir(join(dir, 'routes')),\n loadDir(join(dir, 'controllers')),\n loadDir(join(dir, 'services')),\n loadDir(join(dir, 'policies')),\n loadDir(join(dir, 'middlewares')),\n loadContentTypes(apiName, join(dir, 'content-types')),\n ]);\n\n return {\n ...(index || {}),\n config: config || {},\n routes: routes || [],\n controllers: controllers || {},\n services: services || {},\n policies: policies || {},\n middlewares: middlewares || {},\n contentTypes: contentTypes || {},\n };\n};\n\nconst loadIndex = async (dir: string) => {\n if (await fse.pathExists(join(dir, 'index.js'))) {\n return loadFile(join(dir, 'index.js'));\n }\n};\n\nconst loadContentTypes = async (apiName: string, dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n const contentTypes: API['contentTypes'] = {};\n\n // only load folders\n for (const fd of fds) {\n if (fd.isFile()) {\n continue;\n }\n\n const contentTypeName = normalizeName(fd.name);\n const loadedContentType = await loadDir(join(dir, fd.name));\n\n if (isEmpty(loadedContentType) || isEmpty(loadedContentType.schema)) {\n throw new Error(`Could not load content type found at ${dir}`);\n }\n\n const contentType = {\n ...DEFAULT_CONTENT_TYPE,\n ...loadedContentType,\n } as ContentTypeDefinition;\n\n Object.assign(contentType.schema, {\n apiName,\n collectionName: contentType.schema.collectionName || contentType.schema.info.singularName,\n globalId: getGlobalId(contentType.schema),\n });\n\n contentTypes[normalizeName(contentTypeName)] = contentType;\n }\n\n return contentTypes;\n};\n\nconst loadDir = async (dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n\n const root: Record<string, unknown> = {};\n for (const fd of fds) {\n if (!fd.isFile() || extname(fd.name) === '.map') {\n continue;\n }\n\n const key = basename(fd.name, extname(fd.name));\n\n root[normalizeName(key)] = await loadFile(join(dir, fd.name));\n }\n\n return root;\n};\n\nconst loadFile = (file: string) => {\n const ext = extname(file);\n\n switch (ext) {\n case '.js':\n return importDefault(file);\n case '.json':\n return fse.readJSON(file);\n default:\n return {};\n }\n};\n"],"names":[],"mappings":";;;;;;AAyBA,MAAM,uBAAuB;AAAA,EAC3B,QAAQ,CAAC;AAAA,EACT,SAAS,CAAC;AAAA,EACV,YAAY,CAAC;AACf;AAGA,MAAM,gBAAgB,CAAC,SAAkB,QAAQ,YAAY,IAAI,IAAI,OAAO,EAAE,UAAU,IAAI;AAE5F,MAAM,cAAc,CAAC,OAAmB,GAAG,YAAY;AACvD,MAAM,YAAY,CAAC,OAAmB,GAAG,KAAK,WAAW,GAAG;AAE5D,eAA8B,SAAS,QAAgB;AACrD,MAAI,CAAC,WAAW,OAAO,KAAK,KAAK,GAAG,GAAG;AACrC;AAAA,EACF;AAEM,QAAA,UAAU,OAAO,MAAM,IAAI,QAAQ,OAAO,KAAK,KAAK,KAAK,EAAE,eAAe,KAAM,CAAA,GACnF,OAAO,WAAW,EAClB,OAAO,EAAE,OAAO,SAAS,CAAC;AAE7B,QAAM,OAAa,CAAA;AAGnB,aAAW,SAAS,SAAS;AACrB,UAAA,UAAU,cAAc,MAAM,IAAI;AAClC,UAAA,MAAM,MAAM,QAAQ,SAAS,KAAK,OAAO,KAAK,KAAK,KAAK,MAAM,IAAI,CAAC;AAEzE,SAAK,OAAO,IAAI;AAAA,EAClB;AAEA,8BAA4B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O,SAAA;AACT;AAEA,MAAM,UAAU,OAAO,QAAgB;AACrC,MAAI,CAAE,MAAM,IAAI,WAAW,GAAG,GAAI;AAChC;AAAA,EACF;AAEM,QAAA,MAAM,MAAM,IAAI,QAAQ,KAAK,EAAE,eAAe,MAAM;AAE1D,QAAM,OAAgC,CAAA;AACtC,aAAW,MAAM,KAAK;AAChB,QAAA,CAAC,GAAG,OAAO,KAAK,QAAQ,GAAG,IAAI,MAAM,QAAQ;AAC/C;AAAA,IACF;AAEA,UAAM,MAAM,SAAS,GAAG,MAAM,QAAQ,GAAG,IAAI,CAAC;AAEzC,SAAA,cAAc,GAAG,CAAC,IAAI,MAAM,SAAS,KAAK,KAAK,GAAG,IAAI,CAAC;AAAA,EAC9D;AAEO,SAAA;AACT;AAEA,MAAM,WAAW,CAAC,SAAiB;AAC3B,QAAA,MAAM,QAAQ,IAAI;AAExB,UAAQ,KAAK;AAAA,IACX,KAAK;AACH,aAAO,cAAc,IAAI;AAAA,IAC3B,KAAK;AACI,aAAA,IAAI,SAAS,IAAI;AAAA,IAC1B;AACE,aAAO;EACX;AACF;"}
@@ -17,7 +17,7 @@ const INTERNAL_PLUGINS = [
17
17
  ];
18
18
  const isStrapiPlugin = (info) => _$1.get("strapi.kind", info) === "plugin";
19
19
  const validatePluginName = (pluginName) => {
20
- if (!strapiUtils.isKebabCase(pluginName)) {
20
+ if (!strapiUtils.strings.isKebabCase(pluginName)) {
21
21
  throw new Error(`Plugin name "${pluginName}" is not in kebab (an-example-of-kebab-case)`);
22
22
  }
23
23
  };
@@ -1 +1 @@
1
- {"version":3,"file":"get-enabled-plugins.js","sources":["../../../src/loaders/plugins/get-enabled-plugins.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { dirname, join, resolve } from 'path';\nimport { statSync, existsSync } from 'fs';\nimport _ from 'lodash';\nimport { get, pickBy, defaultsDeep, map, prop, pipe } from 'lodash/fp';\nimport { isKebabCase } from '@strapi/utils';\nimport type { Strapi } from '@strapi/types';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\n\ninterface PluginMeta {\n enabled: boolean;\n pathToPlugin?: string;\n info: Record<string, unknown>;\n}\n\ntype PluginMetas = Record<string, PluginMeta>;\n\ninterface PluginInfo {\n name: string;\n kind: string;\n}\n\ninterface PluginDeclaration {\n enabled: boolean;\n resolve: string;\n isModule: boolean;\n}\n\n/**\n * otherwise known as \"core features\"\n */\nconst INTERNAL_PLUGINS = [\n '@strapi/plugin-content-manager',\n '@strapi/plugin-content-type-builder',\n '@strapi/plugin-email',\n '@strapi/plugin-upload',\n '@strapi/content-releases',\n];\n\nconst isStrapiPlugin = (info: PluginInfo) => get('strapi.kind', info) === 'plugin';\n\nconst validatePluginName = (pluginName: string) => {\n if (!isKebabCase(pluginName)) {\n throw new Error(`Plugin name \"${pluginName}\" is not in kebab (an-example-of-kebab-case)`);\n }\n};\n\nconst toDetailedDeclaration = (declaration: boolean | PluginDeclaration) => {\n if (typeof declaration === 'boolean') {\n return { enabled: declaration };\n }\n\n const detailedDeclaration: { enabled: boolean; pathToPlugin?: string } = {\n enabled: declaration.enabled,\n };\n\n if (declaration?.resolve) {\n let pathToPlugin = '';\n\n if (declaration.isModule) {\n /**\n * we only want the node_module here, not the package.json\n */\n pathToPlugin = join(declaration.resolve, '..');\n } else {\n try {\n pathToPlugin = dirname(require.resolve(declaration.resolve));\n } catch (e) {\n pathToPlugin = resolve(strapi.dirs.app.root, declaration.resolve);\n\n if (!existsSync(pathToPlugin) || !statSync(pathToPlugin).isDirectory()) {\n throw new Error(`${declaration.resolve} couldn't be resolved`);\n }\n }\n }\n\n detailedDeclaration.pathToPlugin = pathToPlugin;\n }\n\n return detailedDeclaration;\n};\n\nexport const getEnabledPlugins = async (strapi: Strapi, { client } = { client: false }) => {\n const internalPlugins: PluginMetas = {};\n\n for (const dep of INTERNAL_PLUGINS) {\n const packagePath = join(dep, 'package.json');\n const packageInfo = require(packagePath);\n\n validatePluginName(packageInfo.strapi.name);\n internalPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: packageInfo.strapi,\n };\n }\n\n const installedPlugins: PluginMetas = {};\n const dependencies = strapi.config.get('info.dependencies', {});\n\n for (const dep of Object.keys(dependencies)) {\n const packagePath = join(dep, 'package.json');\n let packageInfo;\n try {\n packageInfo = require(packagePath);\n } catch {\n continue;\n }\n\n if (isStrapiPlugin(packageInfo)) {\n validatePluginName(packageInfo.strapi.name);\n installedPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: {\n ...packageInfo.strapi,\n packageName: packageInfo.name,\n },\n };\n }\n }\n\n const declaredPlugins: PluginMetas = {};\n const userPluginsConfig = await getUserPluginsConfig();\n\n _.forEach(userPluginsConfig, (declaration, pluginName) => {\n validatePluginName(pluginName);\n\n declaredPlugins[pluginName] = {\n ...toDetailedDeclaration(declaration),\n info: {},\n };\n\n const { pathToPlugin } = declaredPlugins[pluginName];\n\n // for manually resolved plugins\n if (pathToPlugin) {\n const packagePath = join(pathToPlugin, 'package.json');\n const packageInfo = require(packagePath);\n\n if (isStrapiPlugin(packageInfo)) {\n declaredPlugins[pluginName].info = packageInfo.strapi || {};\n }\n }\n });\n\n const declaredPluginsResolves = map(prop('pathToPlugin'), declaredPlugins);\n const installedPluginsNotAlreadyUsed = pickBy(\n (p) => !declaredPluginsResolves.includes(p.pathToPlugin),\n installedPlugins\n );\n\n const enabledPlugins = pipe(\n defaultsDeep(declaredPlugins),\n defaultsDeep(installedPluginsNotAlreadyUsed),\n pickBy((p: PluginMeta) => p.enabled)\n )(internalPlugins);\n\n return enabledPlugins;\n};\n"],"names":["get","isKebabCase","join","dirname","resolve","existsSync","statSync","strapi","getUserPluginsConfig","_","map","prop","pickBy","pipe","defaultsDeep"],"mappings":";;;;;;;;;;AA+BA,MAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;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AAA,EAAA;AAGF,QAAM,iBAAiBC,IAAA;AAAA,IACrBC,IAAAA,aAAa,eAAe;AAAA,IAC5BA,IAAAA,aAAa,8BAA8B;AAAA,IAC3CF,IAAAA,OAAO,CAAC,MAAkB,EAAE,OAAO;AAAA,IACnC,eAAe;AAEV,SAAA;AACT;;"}
1
+ {"version":3,"file":"get-enabled-plugins.js","sources":["../../../src/loaders/plugins/get-enabled-plugins.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { dirname, join, resolve } from 'path';\nimport { statSync, existsSync } from 'fs';\nimport _ from 'lodash';\nimport { get, pickBy, defaultsDeep, map, prop, pipe } from 'lodash/fp';\nimport { strings } from '@strapi/utils';\nimport type { Strapi } from '@strapi/types';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\n\ninterface PluginMeta {\n enabled: boolean;\n pathToPlugin?: string;\n info: Record<string, unknown>;\n}\n\ntype PluginMetas = Record<string, PluginMeta>;\n\ninterface PluginInfo {\n name: string;\n kind: string;\n}\n\ninterface PluginDeclaration {\n enabled: boolean;\n resolve: string;\n isModule: boolean;\n}\n\n/**\n * otherwise known as \"core features\"\n */\nconst INTERNAL_PLUGINS = [\n '@strapi/plugin-content-manager',\n '@strapi/plugin-content-type-builder',\n '@strapi/plugin-email',\n '@strapi/plugin-upload',\n '@strapi/content-releases',\n];\n\nconst isStrapiPlugin = (info: PluginInfo) => get('strapi.kind', info) === 'plugin';\n\nconst validatePluginName = (pluginName: string) => {\n if (!strings.isKebabCase(pluginName)) {\n throw new Error(`Plugin name \"${pluginName}\" is not in kebab (an-example-of-kebab-case)`);\n }\n};\n\nconst toDetailedDeclaration = (declaration: boolean | PluginDeclaration) => {\n if (typeof declaration === 'boolean') {\n return { enabled: declaration };\n }\n\n const detailedDeclaration: { enabled: boolean; pathToPlugin?: string } = {\n enabled: declaration.enabled,\n };\n\n if (declaration?.resolve) {\n let pathToPlugin = '';\n\n if (declaration.isModule) {\n /**\n * we only want the node_module here, not the package.json\n */\n pathToPlugin = join(declaration.resolve, '..');\n } else {\n try {\n pathToPlugin = dirname(require.resolve(declaration.resolve));\n } catch (e) {\n pathToPlugin = resolve(strapi.dirs.app.root, declaration.resolve);\n\n if (!existsSync(pathToPlugin) || !statSync(pathToPlugin).isDirectory()) {\n throw new Error(`${declaration.resolve} couldn't be resolved`);\n }\n }\n }\n\n detailedDeclaration.pathToPlugin = pathToPlugin;\n }\n\n return detailedDeclaration;\n};\n\nexport const getEnabledPlugins = async (strapi: Strapi, { client } = { client: false }) => {\n const internalPlugins: PluginMetas = {};\n\n for (const dep of INTERNAL_PLUGINS) {\n const packagePath = join(dep, 'package.json');\n const packageInfo = require(packagePath);\n\n validatePluginName(packageInfo.strapi.name);\n internalPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: packageInfo.strapi,\n };\n }\n\n const installedPlugins: PluginMetas = {};\n const dependencies = strapi.config.get('info.dependencies', {});\n\n for (const dep of Object.keys(dependencies)) {\n const packagePath = join(dep, 'package.json');\n let packageInfo;\n try {\n packageInfo = require(packagePath);\n } catch {\n continue;\n }\n\n if (isStrapiPlugin(packageInfo)) {\n validatePluginName(packageInfo.strapi.name);\n installedPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: {\n ...packageInfo.strapi,\n packageName: packageInfo.name,\n },\n };\n }\n }\n\n const declaredPlugins: PluginMetas = {};\n const userPluginsConfig = await getUserPluginsConfig();\n\n _.forEach(userPluginsConfig, (declaration, pluginName) => {\n validatePluginName(pluginName);\n\n declaredPlugins[pluginName] = {\n ...toDetailedDeclaration(declaration),\n info: {},\n };\n\n const { pathToPlugin } = declaredPlugins[pluginName];\n\n // for manually resolved plugins\n if (pathToPlugin) {\n const packagePath = join(pathToPlugin, 'package.json');\n const packageInfo = require(packagePath);\n\n if (isStrapiPlugin(packageInfo)) {\n declaredPlugins[pluginName].info = packageInfo.strapi || {};\n }\n }\n });\n\n const declaredPluginsResolves = map(prop('pathToPlugin'), declaredPlugins);\n const installedPluginsNotAlreadyUsed = pickBy(\n (p) => !declaredPluginsResolves.includes(p.pathToPlugin),\n installedPlugins\n );\n\n const enabledPlugins = pipe(\n defaultsDeep(declaredPlugins),\n defaultsDeep(installedPluginsNotAlreadyUsed),\n pickBy((p: PluginMeta) => p.enabled)\n )(internalPlugins);\n\n return enabledPlugins;\n};\n"],"names":["get","strings","join","dirname","resolve","existsSync","statSync","strapi","getUserPluginsConfig","_","map","prop","pickBy","pipe","defaultsDeep"],"mappings":";;;;;;;;;;AA+BA,MAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,iBAAiB,CAAC,SAAqBA,IAAAA,IAAI,eAAe,IAAI,MAAM;AAE1E,MAAM,qBAAqB,CAAC,eAAuB;AACjD,MAAI,CAACC,YAAA,QAAQ,YAAY,UAAU,GAAG;AACpC,UAAM,IAAI,MAAM,gBAAgB,UAAU,8CAA8C;AAAA,EAC1F;AACF;AAEA,MAAM,wBAAwB,CAAC,gBAA6C;AACtE,MAAA,OAAO,gBAAgB,WAAW;AAC7B,WAAA,EAAE,SAAS;EACpB;AAEA,QAAM,sBAAmE;AAAA,IACvE,SAAS,YAAY;AAAA,EAAA;AAGvB,MAAI,aAAa,SAAS;AACxB,QAAI,eAAe;AAEnB,QAAI,YAAY,UAAU;AAIT,qBAAAC,KAAAA,KAAK,YAAY,SAAS,IAAI;AAAA,IAAA,OACxC;AACD,UAAA;AACF,uBAAeC,KAAQ,QAAA,QAAQ,QAAQ,YAAY,OAAO,CAAC;AAAA,eACpD,GAAG;AACV,uBAAeC,KAAAA,QAAQ,OAAO,KAAK,IAAI,MAAM,YAAY,OAAO;AAE5D,YAAA,CAACC,cAAW,YAAY,KAAK,CAACC,GAAAA,SAAS,YAAY,EAAE,eAAe;AACtE,gBAAM,IAAI,MAAM,GAAG,YAAY,OAAO,u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pC,MAAM,CAAC;AAAA,IAAA;AAGT,UAAM,EAAE,aAAA,IAAiB,gBAAgB,UAAU;AAGnD,QAAI,cAAc;AACV,YAAA,cAAcP,KAAAA,KAAK,cAAc,cAAc;AAC/C,YAAA,cAAc,QAAQ,WAAW;AAEnC,UAAA,eAAe,WAAW,GAAG;AAC/B,wBAAgB,UAAU,EAAE,OAAO,YAAY,UAAU,CAAA;AAAA,MAC3D;AAAA,IACF;AAAA,EAAA,CACD;AAED,QAAM,0BAA0BQ,IAAAA,IAAIC,IAAAA,KAAK,cAAc,GAAG,eAAe;AACzE,QAAM,iCAAiCC,IAAA;AAAA,IACrC,CAAC,MAAM,CAAC,wBAAwB,SAAS,EAAE,YAAY;AAAA,IACvD;AAAA,EAAA;AAGF,QAAM,iBAAiBC,IAAA;AAAA,IACrBC,IAAAA,aAAa,eAAe;AAAA,IAC5BA,IAAAA,aAAa,8BAA8B;AAAA,IAC3CF,IAAAA,OAAO,CAAC,MAAkB,EAAE,OAAO;AAAA,IACnC,eAAe;AAEV,SAAA;AACT;;"}
@@ -2,7 +2,7 @@ import { join, dirname, resolve } from "path";
2
2
  import { existsSync, statSync } from "fs";
3
3
  import _ from "lodash";
4
4
  import { map, prop, pickBy, pipe, defaultsDeep, get } from "lodash/fp";
5
- import { isKebabCase } from "@strapi/utils";
5
+ import { strings } from "@strapi/utils";
6
6
  import { getUserPluginsConfig } from "./get-user-plugins-config.mjs";
7
7
  const INTERNAL_PLUGINS = [
8
8
  "@strapi/plugin-content-manager",
@@ -13,7 +13,7 @@ const INTERNAL_PLUGINS = [
13
13
  ];
14
14
  const isStrapiPlugin = (info) => get("strapi.kind", info) === "plugin";
15
15
  const validatePluginName = (pluginName) => {
16
- if (!isKebabCase(pluginName)) {
16
+ if (!strings.isKebabCase(pluginName)) {
17
17
  throw new Error(`Plugin name "${pluginName}" is not in kebab (an-example-of-kebab-case)`);
18
18
  }
19
19
  };
@@ -1 +1 @@
1
- {"version":3,"file":"get-enabled-plugins.mjs","sources":["../../../src/loaders/plugins/get-enabled-plugins.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { dirname, join, resolve } from 'path';\nimport { statSync, existsSync } from 'fs';\nimport _ from 'lodash';\nimport { get, pickBy, defaultsDeep, map, prop, pipe } from 'lodash/fp';\nimport { isKebabCase } from '@strapi/utils';\nimport type { Strapi } from '@strapi/types';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\n\ninterface PluginMeta {\n enabled: boolean;\n pathToPlugin?: string;\n info: Record<string, unknown>;\n}\n\ntype PluginMetas = Record<string, PluginMeta>;\n\ninterface PluginInfo {\n name: string;\n kind: string;\n}\n\ninterface PluginDeclaration {\n enabled: boolean;\n resolve: string;\n isModule: boolean;\n}\n\n/**\n * otherwise known as \"core features\"\n */\nconst INTERNAL_PLUGINS = [\n '@strapi/plugin-content-manager',\n '@strapi/plugin-content-type-builder',\n '@strapi/plugin-email',\n '@strapi/plugin-upload',\n '@strapi/content-releases',\n];\n\nconst isStrapiPlugin = (info: PluginInfo) => get('strapi.kind', info) === 'plugin';\n\nconst validatePluginName = (pluginName: string) => {\n if (!isKebabCase(pluginName)) {\n throw new Error(`Plugin name \"${pluginName}\" is not in kebab (an-example-of-kebab-case)`);\n }\n};\n\nconst toDetailedDeclaration = (declaration: boolean | PluginDeclaration) => {\n if (typeof declaration === 'boolean') {\n return { enabled: declaration };\n }\n\n const detailedDeclaration: { enabled: boolean; pathToPlugin?: string } = {\n enabled: declaration.enabled,\n };\n\n if (declaration?.resolve) {\n let pathToPlugin = '';\n\n if (declaration.isModule) {\n /**\n * we only want the node_module here, not the package.json\n */\n pathToPlugin = join(declaration.resolve, '..');\n } else {\n try {\n pathToPlugin = dirname(require.resolve(declaration.resolve));\n } catch (e) {\n pathToPlugin = resolve(strapi.dirs.app.root, declaration.resolve);\n\n if (!existsSync(pathToPlugin) || !statSync(pathToPlugin).isDirectory()) {\n throw new Error(`${declaration.resolve} couldn't be resolved`);\n }\n }\n }\n\n detailedDeclaration.pathToPlugin = pathToPlugin;\n }\n\n return detailedDeclaration;\n};\n\nexport const getEnabledPlugins = async (strapi: Strapi, { client } = { client: false }) => {\n const internalPlugins: PluginMetas = {};\n\n for (const dep of INTERNAL_PLUGINS) {\n const packagePath = join(dep, 'package.json');\n const packageInfo = require(packagePath);\n\n validatePluginName(packageInfo.strapi.name);\n internalPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: packageInfo.strapi,\n };\n }\n\n const installedPlugins: PluginMetas = {};\n const dependencies = strapi.config.get('info.dependencies', {});\n\n for (const dep of Object.keys(dependencies)) {\n const packagePath = join(dep, 'package.json');\n let packageInfo;\n try {\n packageInfo = require(packagePath);\n } catch {\n continue;\n }\n\n if (isStrapiPlugin(packageInfo)) {\n validatePluginName(packageInfo.strapi.name);\n installedPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: {\n ...packageInfo.strapi,\n packageName: packageInfo.name,\n },\n };\n }\n }\n\n const declaredPlugins: PluginMetas = {};\n const userPluginsConfig = await getUserPluginsConfig();\n\n _.forEach(userPluginsConfig, (declaration, pluginName) => {\n validatePluginName(pluginName);\n\n declaredPlugins[pluginName] = {\n ...toDetailedDeclaration(declaration),\n info: {},\n };\n\n const { pathToPlugin } = declaredPlugins[pluginName];\n\n // for manually resolved plugins\n if (pathToPlugin) {\n const packagePath = join(pathToPlugin, 'package.json');\n const packageInfo = require(packagePath);\n\n if (isStrapiPlugin(packageInfo)) {\n declaredPlugins[pluginName].info = packageInfo.strapi || {};\n }\n }\n });\n\n const declaredPluginsResolves = map(prop('pathToPlugin'), declaredPlugins);\n const installedPluginsNotAlreadyUsed = pickBy(\n (p) => !declaredPluginsResolves.includes(p.pathToPlugin),\n installedPlugins\n );\n\n const enabledPlugins = pipe(\n defaultsDeep(declaredPlugins),\n defaultsDeep(installedPluginsNotAlreadyUsed),\n pickBy((p: PluginM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wB,SAAS,EAAE,YAAY;AAAA,IACvD;AAAA,EAAA;AAGF,QAAM,iBAAiB;AAAA,IACrB,aAAa,eAAe;AAAA,IAC5B,aAAa,8BAA8B;AAAA,IAC3C,OAAO,CAAC,MAAkB,EAAE,OAAO;AAAA,IACnC,eAAe;AAEV,SAAA;AACT;"}
1
+ {"version":3,"file":"get-enabled-plugins.mjs","sources":["../../../src/loaders/plugins/get-enabled-plugins.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { dirname, join, resolve } from 'path';\nimport { statSync, existsSync } from 'fs';\nimport _ from 'lodash';\nimport { get, pickBy, defaultsDeep, map, prop, pipe } from 'lodash/fp';\nimport { strings } from '@strapi/utils';\nimport type { Strapi } from '@strapi/types';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\n\ninterface PluginMeta {\n enabled: boolean;\n pathToPlugin?: string;\n info: Record<string, unknown>;\n}\n\ntype PluginMetas = Record<string, PluginMeta>;\n\ninterface PluginInfo {\n name: string;\n kind: string;\n}\n\ninterface PluginDeclaration {\n enabled: boolean;\n resolve: string;\n isModule: boolean;\n}\n\n/**\n * otherwise known as \"core features\"\n */\nconst INTERNAL_PLUGINS = [\n '@strapi/plugin-content-manager',\n '@strapi/plugin-content-type-builder',\n '@strapi/plugin-email',\n '@strapi/plugin-upload',\n '@strapi/content-releases',\n];\n\nconst isStrapiPlugin = (info: PluginInfo) => get('strapi.kind', info) === 'plugin';\n\nconst validatePluginName = (pluginName: string) => {\n if (!strings.isKebabCase(pluginName)) {\n throw new Error(`Plugin name \"${pluginName}\" is not in kebab (an-example-of-kebab-case)`);\n }\n};\n\nconst toDetailedDeclaration = (declaration: boolean | PluginDeclaration) => {\n if (typeof declaration === 'boolean') {\n return { enabled: declaration };\n }\n\n const detailedDeclaration: { enabled: boolean; pathToPlugin?: string } = {\n enabled: declaration.enabled,\n };\n\n if (declaration?.resolve) {\n let pathToPlugin = '';\n\n if (declaration.isModule) {\n /**\n * we only want the node_module here, not the package.json\n */\n pathToPlugin = join(declaration.resolve, '..');\n } else {\n try {\n pathToPlugin = dirname(require.resolve(declaration.resolve));\n } catch (e) {\n pathToPlugin = resolve(strapi.dirs.app.root, declaration.resolve);\n\n if (!existsSync(pathToPlugin) || !statSync(pathToPlugin).isDirectory()) {\n throw new Error(`${declaration.resolve} couldn't be resolved`);\n }\n }\n }\n\n detailedDeclaration.pathToPlugin = pathToPlugin;\n }\n\n return detailedDeclaration;\n};\n\nexport const getEnabledPlugins = async (strapi: Strapi, { client } = { client: false }) => {\n const internalPlugins: PluginMetas = {};\n\n for (const dep of INTERNAL_PLUGINS) {\n const packagePath = join(dep, 'package.json');\n const packageInfo = require(packagePath);\n\n validatePluginName(packageInfo.strapi.name);\n internalPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: packageInfo.strapi,\n };\n }\n\n const installedPlugins: PluginMetas = {};\n const dependencies = strapi.config.get('info.dependencies', {});\n\n for (const dep of Object.keys(dependencies)) {\n const packagePath = join(dep, 'package.json');\n let packageInfo;\n try {\n packageInfo = require(packagePath);\n } catch {\n continue;\n }\n\n if (isStrapiPlugin(packageInfo)) {\n validatePluginName(packageInfo.strapi.name);\n installedPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: {\n ...packageInfo.strapi,\n packageName: packageInfo.name,\n },\n };\n }\n }\n\n const declaredPlugins: PluginMetas = {};\n const userPluginsConfig = await getUserPluginsConfig();\n\n _.forEach(userPluginsConfig, (declaration, pluginName) => {\n validatePluginName(pluginName);\n\n declaredPlugins[pluginName] = {\n ...toDetailedDeclaration(declaration),\n info: {},\n };\n\n const { pathToPlugin } = declaredPlugins[pluginName];\n\n // for manually resolved plugins\n if (pathToPlugin) {\n const packagePath = join(pathToPlugin, 'package.json');\n const packageInfo = require(packagePath);\n\n if (isStrapiPlugin(packageInfo)) {\n declaredPlugins[pluginName].info = packageInfo.strapi || {};\n }\n }\n });\n\n const declaredPluginsResolves = map(prop('pathToPlugin'), declaredPlugins);\n const installedPluginsNotAlreadyUsed = pickBy(\n (p) => !declaredPluginsResolves.includes(p.pathToPlugin),\n installedPlugins\n );\n\n const enabledPlugins = pipe(\n defaultsDeep(declaredPlugins),\n defaultsDeep(installedPluginsNotAlreadyUsed),\n pickBy((p: PluginMeta) => p.enabled)\n )(internalPlugins);\n\n return enabledPlugins;\n};\n"],"names":["strapi"],"mappings":";;;;;;AA+BA,MAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,iBAAiB,CAAC,SAAqB,IAAI,eAAe,IAAI,MAAM;AAE1E,MAAM,qBAAqB,CAAC,eAAuB;AACjD,MAAI,CAAC,QAAQ,YAAY,UAAU,GAAG;AACpC,UAAM,IAAI,MAAM,gBAAgB,UAAU,8CAA8C;AAAA,EAC1F;AACF;AAEA,MAAM,wBAAwB,CAAC,gBAA6C;AACtE,MAAA,OAAO,gBAAgB,WAAW;AAC7B,WAAA,EAAE,SAAS;EACpB;AAEA,QAAM,sBAAmE;AAAA,IACvE,SAAS,YAAY;AAAA,EAAA;AAGvB,MAAI,aAAa,SAAS;AACxB,QAAI,eAAe;AAEnB,QAAI,YAAY,UAAU;AAIT,qBAAA,KAAK,YAAY,SAAS,IAAI;AAAA,IAAA,OACxC;AACD,UAAA;AACF,uBAAe,QAAQ,QAAQ,QAAQ,YAAY,OAAO,CAAC;AAAA,eACpD,GAAG;AACV,uBAAe,QAAQ,OAAO,KAAK,IAAI,MAAM,YAAY,OAAO;AAE5D,YAAA,CAAC,WAAW,YAAY,KAAK,CAAC,SAAS,YAAY,EAAE,eAAe;AACtE,gBAAM,IAAI,MAAM,GAAG,YAAY,OAAO,uBAAuB;AAAA,QAC/D;AAAA,MACF;AAAA,IACF;AAEA,wBAAoB,eAAe;AAAA,EACrC;AAEO,SAAA;AACT;AAEa,MAAA,oBAAoB,OAAOA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,WAAW;AAEnC,UAAA,eAAe,WAAW,GAAG;AAC/B,wBAAgB,UAAU,EAAE,OAAO,YAAY,UAAU,CAAA;AAAA,MAC3D;AAAA,IACF;AAAA,EAAA,CACD;AAED,QAAM,0BAA0B,IAAI,KAAK,cAAc,GAAG,eAAe;AACzE,QAAM,iCAAiC;AAAA,IACrC,CAAC,MAAM,CAAC,wBAAwB,SAAS,EAAE,YAAY;AAAA,IACvD;AAAA,EAAA;AAGF,QAAM,iBAAiB;AAAA,IACrB,aAAa,eAAe;AAAA,IAC5B,aAAa,8BAA8B;AAAA,IAC3C,OAAO,CAAC,MAAkB,EAAE,OAAO;AAAA,IACnC,eAAe;AAEV,SAAA;AACT;"}
@@ -0,0 +1,17 @@
1
+ import { Schema } from '@strapi/types';
2
+ interface Input {
3
+ oldContentTypes: Record<string, Schema.ContentType>;
4
+ contentTypes: Record<string, Schema.ContentType>;
5
+ }
6
+ /**
7
+ * Enable draft and publish for content types.
8
+ *
9
+ * Draft and publish disabled content types will have their entries published,
10
+ * this migration clones those entries as drafts.
11
+ *
12
+ * TODO: Clone components, dynamic zones and relations
13
+ */
14
+ declare const enableDraftAndPublish: ({ oldContentTypes, contentTypes }: Input) => Promise<void>;
15
+ declare const disableDraftAndPublish: ({ oldContentTypes, contentTypes }: Input) => Promise<void>;
16
+ export { enableDraftAndPublish as enable, disableDraftAndPublish as disable };
17
+ //# sourceMappingURL=draft-publish.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"draft-publish.d.ts","sourceRoot":"","sources":["../../src/migrations/draft-publish.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,UAAU,KAAK;IACb,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IACpD,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;CAClD;AAED;;;;;;;GAOG;AACH,QAAA,MAAM,qBAAqB,sCAA6C,KAAK,kBAqE5E,CAAC;AAEF,QAAA,MAAM,sBAAsB,sCAA6C,KAAK,kBAqB7E,CAAC;AAEF,OAAO,EAAE,qBAAqB,IAAI,MAAM,EAAE,sBAAsB,IAAI,OAAO,EAAE,CAAC"}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const strapiUtils = require("@strapi/utils");
4
+ const enableDraftAndPublish = async ({ oldContentTypes, contentTypes }) => {
5
+ if (!oldContentTypes) {
6
+ return;
7
+ }
8
+ for (const uid in contentTypes) {
9
+ if (!oldContentTypes[uid]) {
10
+ continue;
11
+ }
12
+ const oldContentType = oldContentTypes[uid];
13
+ const contentType = contentTypes[uid];
14
+ if (!strapiUtils.contentTypes.hasDraftAndPublish(oldContentType) && strapiUtils.contentTypes.hasDraftAndPublish(contentType)) {
15
+ const metadata = strapi.db.metadata.get(uid);
16
+ const attributes = Object.values(metadata.attributes).reduce((acc, attribute) => {
17
+ if (["id"].includes(attribute.columnName)) {
18
+ return acc;
19
+ }
20
+ if (strapiUtils.contentTypes.isScalarAttribute(attribute)) {
21
+ acc.push(attribute.columnName);
22
+ }
23
+ return acc;
24
+ }, []);
25
+ const qb = strapi.db?.getConnection();
26
+ await qb.into(qb.raw(`${metadata.tableName} (${attributes.join(", ")})`)).insert((subQb) => {
27
+ subQb.select(
28
+ ...attributes.map((att) => {
29
+ if (att === "published_at") {
30
+ return qb.raw("NULL as published_at");
31
+ }
32
+ if (att === "updated_at") {
33
+ return qb.raw(`?? as updated_at`, [qb.fn.now()]);
34
+ }
35
+ return att;
36
+ })
37
+ ).from(metadata.tableName).whereNotNull("published_at");
38
+ });
39
+ }
40
+ }
41
+ };
42
+ const disableDraftAndPublish = async ({ oldContentTypes, contentTypes }) => {
43
+ if (!oldContentTypes) {
44
+ return;
45
+ }
46
+ for (const uid in contentTypes) {
47
+ if (!oldContentTypes[uid]) {
48
+ continue;
49
+ }
50
+ const oldContentType = oldContentTypes[uid];
51
+ const contentType = contentTypes[uid];
52
+ if (strapiUtils.contentTypes.hasDraftAndPublish(oldContentType) && !strapiUtils.contentTypes.hasDraftAndPublish(contentType)) {
53
+ await strapi.db?.queryBuilder(uid).delete().where({ published_at: null }).execute();
54
+ }
55
+ }
56
+ };
57
+ exports.disable = disableDraftAndPublish;
58
+ exports.enable = enableDraftAndPublish;
59
+ //# sourceMappingURL=draft-publish.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"draft-publish.js","sources":["../../src/migrations/draft-publish.ts"],"sourcesContent":["import { contentTypes as contentTypesUtils } from '@strapi/utils';\nimport { Schema } from '@strapi/types';\n\ninterface Input {\n oldContentTypes: Record<string, Schema.ContentType>;\n contentTypes: Record<string, Schema.ContentType>;\n}\n\n/**\n * Enable draft and publish for content types.\n *\n * Draft and publish disabled content types will have their entries published,\n * this migration clones those entries as drafts.\n *\n * TODO: Clone components, dynamic zones and relations\n */\nconst enableDraftAndPublish = async ({ oldContentTypes, contentTypes }: Input) => {\n if (!oldContentTypes) {\n return;\n }\n\n // run the after content types migrations\n\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n // if d&p was enabled set publishedAt to eq createdAt\n if (\n !contentTypesUtils.hasDraftAndPublish(oldContentType) &&\n contentTypesUtils.hasDraftAndPublish(contentType)\n ) {\n const metadata = strapi.db.metadata.get(uid);\n\n // Extract all scalar attributes to use in the insert query\n const attributes = Object.values(metadata.attributes).reduce((acc, attribute: any) => {\n if (['id'].includes(attribute.columnName)) {\n return acc;\n }\n\n if (contentTypesUtils.isScalarAttribute(attribute)) {\n acc.push(attribute.columnName);\n }\n\n return acc;\n }, [] as string[]);\n\n /**\n * INSERT INTO tableName (columnName1, columnName2, columnName3, ...)\n * SELECT columnName1, columnName2, columnName3, ...\n * FROM tableName\n */\n const qb = strapi.db?.getConnection();\n await qb\n // INSERT INTO tableName (columnName1, columnName2, columnName3, ...)\n .into(qb.raw(`${metadata.tableName} (${attributes.join(', ')})`))\n .insert((subQb: typeof qb) => {\n // SELECT columnName1, columnName2, columnName3, ...\n subQb\n .select(\n ...attributes.map((att) => {\n // Override 'publishedAt' and 'updatedAt' attributes\n if (att === 'published_at') {\n return qb.raw('NULL as published_at');\n }\n\n // TODO: Find a way to insert a date using the correct format\n // Before: 1710240975246\n // With qb.fn.now(): 2021-10-24 09:52:46\n if (att === 'updated_at') {\n return qb.raw(`?? as updated_at`, [qb.fn.now()]);\n }\n\n return att;\n })\n )\n .from(metadata.tableName)\n .whereNotNull('published_at');\n });\n }\n }\n};\n\nconst disableDraftAndPublish = async ({ oldContentTypes, contentTypes }: Input) => {\n if (!oldContentTypes) {\n return;\n }\n\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n // if d&p was disabled remove unpublish content before sync\n if (\n contentTypesUtils.hasDraftAndPublish(oldContentType) &&\n !contentTypesUtils.hasDraftAndPublish(contentType)\n ) {\n await strapi.db?.queryBuilder(uid).delete().where({ published_at: null }).execute();\n }\n }\n};\n\nexport { enableDraftAndPublish as enable, disableDraftAndPublish as disable };\n"],"names":["contentTypesUtils"],"mappings":";;;AAgBA,MAAM,wBAAwB,OAAO,EAAE,iBAAiB,mBAA0B;AAChF,MAAI,CAAC,iBAAiB;AACpB;AAAA,EACF;AAIA,aAAW,OAAO,cAAc;AAC1B,QAAA,CAAC,gBAAgB,GAAG,GAAG;AACzB;AAAA,IACF;AAEM,UAAA,iBAAiB,gBAAgB,GAAG;AACpC,UAAA,cAAc,aAAa,GAAG;AAIlC,QAAA,CAACA,yBAAkB,mBAAmB,cAAc,KACpDA,yBAAkB,mBAAmB,WAAW,GAChD;AACA,YAAM,WAAW,OAAO,GAAG,SAAS,IAAI,GAAG;AAGrC,YAAA,aAAa,OAAO,OAAO,SAAS,UAAU,EA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