@strapi/core 5.0.0-beta.4 → 5.0.0-beta.6

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 (42) hide show
  1. package/dist/core-api/service/collection-type.d.ts.map +1 -1
  2. package/dist/core-api/service/collection-type.js +2 -1
  3. package/dist/core-api/service/collection-type.js.map +1 -1
  4. package/dist/core-api/service/collection-type.mjs +2 -1
  5. package/dist/core-api/service/collection-type.mjs.map +1 -1
  6. package/dist/core-api/service/single-type.d.ts.map +1 -1
  7. package/dist/core-api/service/single-type.js +2 -1
  8. package/dist/core-api/service/single-type.js.map +1 -1
  9. package/dist/core-api/service/single-type.mjs +2 -1
  10. package/dist/core-api/service/single-type.mjs.map +1 -1
  11. package/dist/loaders/apis.d.ts.map +1 -1
  12. package/dist/loaders/apis.js +10 -10
  13. package/dist/loaders/apis.js.map +1 -1
  14. package/dist/loaders/apis.mjs +10 -10
  15. package/dist/loaders/apis.mjs.map +1 -1
  16. package/dist/loaders/plugins/get-enabled-plugins.js +5 -5
  17. package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
  18. package/dist/loaders/plugins/get-enabled-plugins.mjs +5 -5
  19. package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
  20. package/dist/migrations/database/5.0.0-discard-drafts.d.ts +12 -0
  21. package/dist/migrations/database/5.0.0-discard-drafts.d.ts.map +1 -0
  22. package/dist/migrations/database/5.0.0-discard-drafts.js +49 -0
  23. package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -0
  24. package/dist/migrations/database/5.0.0-discard-drafts.mjs +49 -0
  25. package/dist/migrations/database/5.0.0-discard-drafts.mjs.map +1 -0
  26. package/dist/providers/registries.d.ts.map +1 -1
  27. package/dist/providers/registries.js +2 -0
  28. package/dist/providers/registries.js.map +1 -1
  29. package/dist/providers/registries.mjs +2 -0
  30. package/dist/providers/registries.mjs.map +1 -1
  31. package/dist/services/document-service/repository.js +9 -9
  32. package/dist/services/document-service/repository.js.map +1 -1
  33. package/dist/services/document-service/repository.mjs +9 -9
  34. package/dist/services/document-service/repository.mjs.map +1 -1
  35. package/dist/services/server/koa.d.ts.map +1 -1
  36. package/dist/services/server/koa.js +1 -1
  37. package/dist/services/server/koa.js.map +1 -1
  38. package/dist/services/server/koa.mjs +1 -1
  39. package/dist/services/server/koa.mjs.map +1 -1
  40. package/package.json +19 -17
  41. package/dist/services/document-service/document-engine.d.ts +0 -1
  42. package/dist/services/document-service/document-engine.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"collection-type.d.ts","sourceRoot":"","sources":["../../../src/core-api/service/collection-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAI3D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,qBAAa,qBACX,SAAQ,WACR,YAAW,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc;IAE9C,OAAO,CAAC,WAAW,CAA8B;gBAErC,WAAW,EAAE,MAAM,CAAC,oBAAoB;IAM9C,IAAI,CAAC,MAAM,KAAK;;;;;;;;;;IA+BtB,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,KAAK;IAS/C,MAAM,CAAC,MAAM;;KAAe;IAMlC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM;;KAAe;IASxD,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,KAAK;;;CAQ3D;AAED;;;GAGG;AAEH,QAAA,MAAM,2BAA2B,gBAClB,OAAO,oBAAoB,KACvC,KAAK,OAAO,CAAC,OAAO,CAAC,cAEvB,CAAC;AAEF,OAAO,EAAE,2BAA2B,EAAE,CAAC"}
1
+ {"version":3,"file":"collection-type.d.ts","sourceRoot":"","sources":["../../../src/core-api/service/collection-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAI3D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,qBAAa,qBACX,SAAQ,WACR,YAAW,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc;IAE9C,OAAO,CAAC,WAAW,CAA8B;gBAErC,WAAW,EAAE,MAAM,CAAC,oBAAoB;IAM9C,IAAI,CAAC,MAAM,KAAK;;;;;;;;;;IA+BtB,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,KAAK;IAS/C,MAAM,CAAC,MAAM;;KAAe;IAMlC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM;;KAAe;IASxD,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,KAAK;;;CAU3D;AAED;;;GAGG;AAEH,QAAA,MAAM,2BAA2B,gBAClB,OAAO,oBAAoB,KACvC,KAAK,OAAO,CAAC,OAAO,CAAC,cAEvB,CAAC;AAEF,OAAO,EAAE,2BAA2B,EAAE,CAAC"}
@@ -51,10 +51,11 @@ class CollectionTypeService extends coreService.CoreService {
51
51
  }
52
52
  async delete(documentId, params = {}) {
53
53
  const { uid } = this.contentType;
54
- return strapi.documents(uid).delete({
54
+ const { entries } = await strapi.documents(uid).delete({
55
55
  ...this.getFetchParams(params),
56
56
  documentId
57
57
  });
58
+ return { deletedEntries: entries.length };
58
59
  }
59
60
  }
60
61
  const createCollectionTypeService = (contentType) => {
@@ -1 +1 @@
1
- {"version":3,"file":"collection-type.js","sources":["../../../src/core-api/service/collection-type.ts"],"sourcesContent":["import type { Core, Struct, Modules } from '@strapi/types';\n\nimport { getPaginationInfo, shouldCount, transformPaginationResponse } from './pagination';\n\nimport { CoreService } from './core-service';\n\nexport class CollectionTypeService\n extends CoreService\n implements Core.CoreAPI.Service.CollectionType\n{\n private contentType: Struct.CollectionTypeSchema;\n\n constructor(contentType: Struct.CollectionTypeSchema) {\n super();\n\n this.contentType = contentType;\n }\n\n async find(params = {}) {\n const { uid } = this.contentType;\n\n const fetchParams = this.getFetchParams(params);\n\n const paginationInfo = getPaginationInfo(fetchParams);\n\n const results = await strapi.documents(uid).findMany({\n ...fetchParams,\n ...paginationInfo,\n });\n\n if (shouldCount(fetchParams)) {\n const count = await strapi.documents(uid).count({ ...fetchParams, ...paginationInfo });\n\n if (typeof count !== 'number') {\n throw new Error('Count should be a number');\n }\n\n return {\n results,\n pagination: transformPaginationResponse(paginationInfo, count),\n };\n }\n\n return {\n results,\n pagination: paginationInfo,\n };\n }\n\n findOne(documentId: Modules.Documents.ID, params = {}) {\n const { uid } = this.contentType;\n\n return strapi.documents(uid).findOne({\n ...this.getFetchParams(params),\n documentId,\n });\n }\n\n async create(params = { data: {} }) {\n const { uid } = this.contentType;\n\n return strapi.documents(uid).create(this.getFetchParams(params));\n }\n\n update(documentId: Modules.Documents.ID, params = { data: {} }) {\n const { uid } = this.contentType;\n\n return strapi.documents(uid).update({\n ...this.getFetchParams(params),\n documentId,\n });\n }\n\n async delete(documentId: Modules.Documents.ID, params = {}) {\n const { uid } = this.contentType;\n\n return strapi.documents(uid).delete({\n ...this.getFetchParams(params),\n documentId,\n });\n }\n}\n\n/**\n *\n * Returns a collection type service to handle default core-api actions\n */\n\nconst createCollectionTypeService = (\n contentType: Struct.CollectionTypeSchema\n): Core.CoreAPI.Service.CollectionType => {\n return new CollectionTypeService(contentType);\n};\n\nexport { createCollectionTypeService };\n"],"names":["CoreService","getPaginationInfo","shouldCount","transformPaginationResponse"],"mappings":";;;;AAMO,MAAM,8BACHA,YAAAA,YAEV;AAAA,EACU;AAAA,EAER,YAAY,aAA0C;AAC9C;AAEN,SAAK,cAAc;AAAA,EACrB;AAAA,EAEA,MAAM,KAAK,SAAS,IAAI;AAChB,U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AO,OAAO,UAAU,GAAG,EAAE,OAAO;AAAA,MAClC,GAAG,KAAK,eAAe,MAAM;AAAA,MAC7B;AAAA,IAAA,CACD;AAAA,EACH;AACF;AAOM,MAAA,8BAA8B,CAClC,gBACwC;AACjC,SAAA,IAAI,sBAAsB,WAAW;AAC9C;;;"}
1
+ {"version":3,"file":"collection-type.js","sources":["../../../src/core-api/service/collection-type.ts"],"sourcesContent":["import type { Core, Struct, Modules } from '@strapi/types';\n\nimport { getPaginationInfo, shouldCount, transformPaginationResponse } from './pagination';\n\nimport { CoreService } from './core-service';\n\nexport class CollectionTypeService\n extends CoreService\n implements Core.CoreAPI.Service.CollectionType\n{\n private contentType: Struct.CollectionTypeSchema;\n\n constructor(contentType: Struct.CollectionTypeSchema) {\n super();\n\n this.contentType = contentType;\n }\n\n async find(params = {}) {\n const { uid } = this.contentType;\n\n const fetchParams = this.getFetchParams(params);\n\n const paginationInfo = getPaginationInfo(fetchParams);\n\n const results = await strapi.documents(uid).findMany({\n ...fetchParams,\n ...paginationInfo,\n });\n\n if (shouldCount(fetchParams)) {\n const count = await strapi.documents(uid).count({ ...fetchParams, ...paginationInfo });\n\n if (typeof count !== 'number') {\n throw new Error('Count should be a number');\n }\n\n return {\n results,\n pagination: transformPaginationResponse(paginationInfo, count),\n };\n }\n\n return {\n results,\n pagination: paginationInfo,\n };\n }\n\n findOne(documentId: Modules.Documents.ID, params = {}) {\n const { uid } = this.contentType;\n\n return strapi.documents(uid).findOne({\n ...this.getFetchParams(params),\n documentId,\n });\n }\n\n async create(params = { data: {} }) {\n const { uid } = this.contentType;\n\n return strapi.documents(uid).create(this.getFetchParams(params));\n }\n\n update(documentId: Modules.Documents.ID, params = { data: {} }) {\n const { uid } = this.contentType;\n\n return strapi.documents(uid).update({\n ...this.getFetchParams(params),\n documentId,\n });\n }\n\n async delete(documentId: Modules.Documents.ID, params = {}) {\n const { uid } = this.contentType;\n\n const { entries } = await strapi.documents(uid).delete({\n ...this.getFetchParams(params),\n documentId,\n });\n\n return { deletedEntries: entries.length };\n }\n}\n\n/**\n *\n * Returns a collection type service to handle default core-api actions\n */\n\nconst createCollectionTypeService = (\n contentType: Struct.CollectionTypeSchema\n): Core.CoreAPI.Service.CollectionType => {\n return new CollectionTypeService(contentType);\n};\n\nexport { createCollectionTypeService };\n"],"names":["CoreService","getPaginationInfo","shouldCount","transformPaginationResponse"],"mappings":";;;;AAMO,MAAM,8BACHA,YAAAA,YAEV;AAAA,EACU;AAAA,EAER,YAAY,aAA0C;AAC9C;AAEN,SAAK,cAAc;AAAA,EACrB;AAAA,EAEA,MAAM,KAAK,SAAS,IAAI;AAChB,UAAA,EAAE,IAAI,IAAI,KAAK;AAEf,UAAA,cAAc,KAAK,eAAe,MAAM;AAExC,UAAA,iBAAiBC,6BAAkB,WAAW;AAEpD,UAAM,UAAU,MAAM,OAAO,UAAU,GAAG,EAAE,SAAS;AAAA,MACnD,GAAG;AAAA,MACH,GAAG;AAAA,IAAA,CACJ;AAEG,QAAAC,WAAAA,YAAY,WAAW,GAAG;AAC5B,YAAM,QAAQ,MAAM,OAAO,UAAU,GAAG,EAAE,MAAM,EAAE,GAAG,aAAa,GAAG,eAAgB,CAAA;AAEjF,UAAA,OAAO,UAAU,UAAU;AACvB,cAAA,IAAI,MAAM,0BAA0B;AAAA,MAC5C;AAEO,aAAA;AAAA,QACL;AAAA,QACA,YAAYC,WAAAA,4BAA4B,gBAAgB,KAAK;AAAA,MAAA;AAAA,IAEjE;AAEO,WAAA;AAAA,MACL;AAAA,MACA,YAAY;AAAA,IAAA;AAAA,EAEhB;AAAA,EAEA,QAAQ,YAAkC,SAAS,IAAI;AAC/C,UAAA,EAAE,IAAI,IAAI,KAAK;AAErB,WAAO,OAAO,UAAU,GAAG,EAAE,QAAQ;AAAA,MACnC,GAAG,KAAK,eAAe,MAAM;AAAA,MAC7B;AAAA,IAAA,CACD;AAAA,EACH;AAAA,EAEA,MAAM,OAAO,SAAS,EAAE,MAAM,MAAM;AAC5B,UAAA,EAAE,IAAI,IAAI,KAAK;AAEd,WAAA,OAAO,UAAU,GAAG,EAAE,OAAO,KAAK,eAAe,MAAM,CAAC;AAAA,EACjE;AAAA,EAEA,OAAO,YAAkC,SAAS,EAAE,MAAM,MAAM;AACxD,UAAA,EAAE,IAAI,IAAI,KAAK;AAErB,WAAO,OAAO,UAAU,GAAG,EAAE,OAAO;AAAA,MAClC,GAAG,KAAK,eAAe,MAAM;AAAA,MAC7B;AAAA,IAAA,CACD;AAAA,EACH;AAAA,EAEA,MAAM,OAAO,YAAkC,SAAS,IAAI;AACpD,UAAA,EAAE,IAAI,IAAI,KAAK;AAEf,UAAA,EAAE,YAAY,MAAM,OAAO,UAAU,GAAG,EAAE,OAAO;AAAA,MACrD,GAAG,KAAK,eAAe,MAAM;AAAA,MAC7B;AAAA,IAAA,CACD;AAEM,WAAA,EAAE,gBAAgB,QAAQ;EACnC;AACF;AAOM,MAAA,8BAA8B,CAClC,gBACwC;AACjC,SAAA,IAAI,sBAAsB,WAAW;AAC9C;;;"}
@@ -49,10 +49,11 @@ class CollectionTypeService extends CoreService {
49
49
  }
50
50
  async delete(documentId, params = {}) {
51
51
  const { uid } = this.contentType;
52
- return strapi.documents(uid).delete({
52
+ const { entries } = await strapi.documents(uid).delete({
53
53
  ...this.getFetchParams(params),
54
54
  documentId
55
55
  });
56
+ return { deletedEntries: entries.length };
56
57
  }
57
58
  }
58
59
  const createCollectionTypeService = (contentType) => {
@@ -1 +1 @@
1
- {"version":3,"file":"collection-type.mjs","sources":["../../../src/core-api/service/collection-type.ts"],"sourcesContent":["import type { Core, Struct, Modules } from '@strapi/types';\n\nimport { getPaginationInfo, shouldCount, transformPaginationResponse } from './pagination';\n\nimport { CoreService } from './core-service';\n\nexport class CollectionTypeService\n extends CoreService\n implements Core.CoreAPI.Service.CollectionType\n{\n private contentType: Struct.CollectionTypeSchema;\n\n constructor(contentType: Struct.CollectionTypeSchema) {\n super();\n\n this.contentType = contentType;\n }\n\n async find(params = {}) {\n const { uid } = this.contentType;\n\n const fetchParams = this.getFetchParams(params);\n\n const paginationInfo = getPaginationInfo(fetchParams);\n\n const results = await strapi.documents(uid).findMany({\n ...fetchParams,\n ...paginationInfo,\n });\n\n if (shouldCount(fetchParams)) {\n const count = await strapi.documents(uid).count({ ...fetchParams, ...paginationInfo });\n\n if (typeof count !== 'number') {\n throw new Error('Count should be a number');\n }\n\n return {\n results,\n pagination: transformPaginationResponse(paginationInfo, count),\n };\n }\n\n return {\n results,\n pagination: paginationInfo,\n };\n }\n\n findOne(documentId: Modules.Documents.ID, params = {}) {\n const { uid } = this.contentType;\n\n return strapi.documents(uid).findOne({\n ...this.getFetchParams(params),\n documentId,\n });\n }\n\n async create(params = { data: {} }) {\n const { uid } = this.contentType;\n\n return strapi.documents(uid).create(this.getFetchParams(params));\n }\n\n update(documentId: Modules.Documents.ID, params = { data: {} }) {\n const { uid } = this.contentType;\n\n return strapi.documents(uid).update({\n ...this.getFetchParams(params),\n documentId,\n });\n }\n\n async delete(documentId: Modules.Documents.ID, params = {}) {\n const { uid } = this.contentType;\n\n return strapi.documents(uid).delete({\n ...this.getFetchParams(params),\n documentId,\n });\n }\n}\n\n/**\n *\n * Returns a collection type service to handle default core-api actions\n */\n\nconst createCollectionTypeService = (\n contentType: Struct.CollectionTypeSchema\n): Core.CoreAPI.Service.CollectionType => {\n return new CollectionTypeService(contentType);\n};\n\nexport { createCollectionTypeService };\n"],"names":[],"mappings":";;AAMO,MAAM,8BACH,YAEV;AAAA,EACU;AAAA,EAER,YAAY,aAA0C;AAC9C;AAEN,SAAK,cAAc;AAAA,EACrB;AAAA,EAEA,MAAM,KAAK,SAAS,IAAI;AAChB,UAAA,EAAE,IAAI,IAAI,KAAK;AAEf,UAAA,cAAc,KAAK,eAAe,MAAM;AAExC,UAAA,iBAAiB,kBAAkB,WAAW;AAEpD,UAAM,UAAU,MAAM,OAAO,UAAU,GAAG,EAAE,SAAS;AAAA,MACnD,GAAG;AAAA,MACH,GAAG;AAAA,IAA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s","sources":["../../../src/core-api/service/collection-type.ts"],"sourcesContent":["import type { Core, Struct, Modules } from '@strapi/types';\n\nimport { getPaginationInfo, shouldCount, transformPaginationResponse } from './pagination';\n\nimport { CoreService } from './core-service';\n\nexport class CollectionTypeService\n extends CoreService\n implements Core.CoreAPI.Service.CollectionType\n{\n private contentType: Struct.CollectionTypeSchema;\n\n constructor(contentType: Struct.CollectionTypeSchema) {\n super();\n\n this.contentType = contentType;\n }\n\n async find(params = {}) {\n const { uid } = this.contentType;\n\n const fetchParams = this.getFetchParams(params);\n\n const paginationInfo = getPaginationInfo(fetchParams);\n\n const results = await strapi.documents(uid).findMany({\n ...fetchParams,\n ...paginationInfo,\n });\n\n if (shouldCount(fetchParams)) {\n const count = await strapi.documents(uid).count({ ...fetchParams, ...paginationInfo });\n\n if (typeof count !== 'number') {\n throw new Error('Count should be a number');\n }\n\n return {\n results,\n pagination: transformPaginationResponse(paginationInfo, count),\n };\n }\n\n return {\n results,\n pagination: paginationInfo,\n };\n }\n\n findOne(documentId: Modules.Documents.ID, params = {}) {\n const { uid } = this.contentType;\n\n return strapi.documents(uid).findOne({\n ...this.getFetchParams(params),\n documentId,\n });\n }\n\n async create(params = { data: {} }) {\n const { uid } = this.contentType;\n\n return strapi.documents(uid).create(this.getFetchParams(params));\n }\n\n update(documentId: Modules.Documents.ID, params = { data: {} }) {\n const { uid } = this.contentType;\n\n return strapi.documents(uid).update({\n ...this.getFetchParams(params),\n documentId,\n });\n }\n\n async delete(documentId: Modules.Documents.ID, params = {}) {\n const { uid } = this.contentType;\n\n const { entries } = await strapi.documents(uid).delete({\n ...this.getFetchParams(params),\n documentId,\n });\n\n return { deletedEntries: entries.length };\n }\n}\n\n/**\n *\n * Returns a collection type service to handle default core-api actions\n */\n\nconst createCollectionTypeService = (\n contentType: Struct.CollectionTypeSchema\n): Core.CoreAPI.Service.CollectionType => {\n return new CollectionTypeService(contentType);\n};\n\nexport { createCollectionTypeService };\n"],"names":[],"mappings":";;AAMO,MAA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A,IAAA,CACD;AAAA,EACH;AAAA,EAEA,MAAM,OAAO,YAAkC,SAAS,IAAI;AACpD,UAAA,EAAE,IAAI,IAAI,KAAK;AAEf,UAAA,EAAE,YAAY,MAAM,OAAO,UAAU,GAAG,EAAE,OAAO;AAAA,MACrD,GAAG,KAAK,eAAe,MAAM;AAAA,MAC7B;AAAA,IAAA,CACD;AAEM,WAAA,EAAE,gBAAgB,QAAQ;EACnC;AACF;AAOM,MAAA,8BAA8B,CAClC,gBACwC;AACjC,SAAA,IAAI,sBAAsB,WAAW;AAC9C;"}
@@ -1 +1 @@
1
- {"version":3,"file":"single-type.d.ts","sourceRoot":"","sources":["../../../src/core-api/service/single-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,qBAAa,iBAAkB,SAAQ,WAAY,YAAW,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU;IAC3F,OAAO,CAAC,WAAW,CAA0B;gBAEjC,WAAW,EAAE,MAAM,CAAC,gBAAgB;IAM1C,aAAa;IASb,IAAI,CAAC,MAAM,KAAK;IAMhB,cAAc,CAAC,MAAM,KAAK;IAe1B,MAAM,CAAC,MAAM,KAAK;;;CAWzB;AAED,QAAA,MAAM,uBAAuB,gBACd,OAAO,gBAAgB,KACnC,KAAK,OAAO,CAAC,OAAO,CAAC,UAEvB,CAAC;AAEF,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
1
+ {"version":3,"file":"single-type.d.ts","sourceRoot":"","sources":["../../../src/core-api/service/single-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,qBAAa,iBAAkB,SAAQ,WAAY,YAAW,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU;IAC3F,OAAO,CAAC,WAAW,CAA0B;gBAEjC,WAAW,EAAE,MAAM,CAAC,gBAAgB;IAM1C,aAAa;IASb,IAAI,CAAC,MAAM,KAAK;IAMhB,cAAc,CAAC,MAAM,KAAK;IAe1B,MAAM,CAAC,MAAM,KAAK;;;CAazB;AAED,QAAA,MAAM,uBAAuB,gBACd,OAAO,gBAAgB,KACnC,KAAK,OAAO,CAAC,OAAO,CAAC,UAEvB,CAAC;AAEF,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
@@ -31,10 +31,11 @@ class SingleTypeService extends coreService.CoreService {
31
31
  const documentId = await this.getDocumentId();
32
32
  if (!documentId)
33
33
  return { deletedEntries: 0 };
34
- return strapi.documents(uid).delete({
34
+ const { entries } = await strapi.documents(uid).delete({
35
35
  ...this.getFetchParams(params),
36
36
  documentId
37
37
  });
38
+ return { deletedEntries: entries.length };
38
39
  }
39
40
  }
40
41
  const createSingleTypeService = (contentType) => {
@@ -1 +1 @@
1
- {"version":3,"file":"single-type.js","sources":["../../../src/core-api/service/single-type.ts"],"sourcesContent":["import type { Struct, Core } from '@strapi/types';\nimport { CoreService } from './core-service';\n\nexport class SingleTypeService extends CoreService implements Core.CoreAPI.Service.SingleType {\n private contentType: Struct.SingleTypeSchema;\n\n constructor(contentType: Struct.SingleTypeSchema) {\n super();\n\n this.contentType = contentType;\n }\n\n async getDocumentId() {\n const { uid } = this.contentType;\n\n return strapi.db\n .query(uid)\n .findOne()\n .then((document) => document?.documentId as string);\n }\n\n async find(params = {}) {\n const { uid } = this.contentType;\n\n return strapi.documents(uid).findFirst(this.getFetchParams(params));\n }\n\n async createOrUpdate(params = {}) {\n const { uid } = this.contentType;\n\n const documentId = await this.getDocumentId();\n\n if (documentId) {\n return strapi.documents(uid).update({\n ...this.getFetchParams(params),\n documentId,\n });\n }\n\n return strapi.documents(uid).create(this.getFetchParams(params));\n }\n\n async delete(params = {}) {\n const { uid } = this.contentType;\n\n const documentId = await this.getDocumentId();\n if (!documentId) return { deletedEntries: 0 };\n\n return strapi.documents(uid).delete({\n ...this.getFetchParams(params),\n documentId,\n });\n }\n}\n\nconst createSingleTypeService = (\n contentType: Struct.SingleTypeSchema\n): Core.CoreAPI.Service.SingleType => {\n return new SingleTypeService(contentType);\n};\n\nexport { createSingleTypeService };\n"],"names":["CoreService"],"mappings":";;;AAGO,MAAM,0BAA0BA,YAAAA,YAAuD;AAAA,EACpF;AAAA,EAER,YAAY,aAAsC;AAC1C;AAEN,SAAK,cAAc;AAAA,EACrB;AAAA,EAEA,MAAM,gBAAgB;AACd,UAAA,EAAE,IAAI,IAAI,KAAK;AAEd,WAAA,OAAO,GACX,MAAM,GAAG,EACT,UACA,KAAK,CAAC,aAAa,UAAU,UAAoB;AAAA,EACtD;AAAA,EAEA,MAAM,KAAK,SAAS,IAAI;AAChB,UAAA,EAAE,IAAI,IAAI,KAAK;AAEd,WAAA,OAAO,UAAU,GAAG,EAAE,UAAU,KAAK,eAAe,MAAM,CAAC;AAAA,EACpE;AAAA,EAEA,MAAM,eAAe,SAAS,IAAI;AAC1B,UAAA,EAAE,IAAI,IAAI,KAAK;AAEf,UAAA,aAAa,MAAM,KAAK;AAE9B,QAAI,YAAY;AACd,aAAO,OAAO,UAAU,GAAG,EAAE,OAAO;AAAA,QAClC,GAAG,KAAK,eAAe,MAAM;AAAA,QAC7B;AAAA,MAAA,CACD;AAAA,IACH;AAEO,WAAA,OAAO,UAAU,GAAG,EAAE,OAAO,KAAK,eAAe,MAAM,CAAC;AAAA,EACjE;AAAA,EAEA,MAAM,OAAO,SAAS,IAAI;AAClB,UAAA,EAAE,IAAI,IAAI,KAAK;AAEf,UAAA,aAAa,MAAM,KAAK;AAC9B,QAAI,CAAC;AAAmB,aAAA,EAAE,gBAAgB;AAE1C,WAAO,OAAO,UAAU,GAAG,EAAE,OAAO;AAAA,MAClC,GAAG,KAAK,eAAe,MAAM;AAAA,MAC7B;AAAA,IAAA,CACD;AAAA,EACH;AACF;AAEM,MAAA,0BAA0B,CAC9B,gBACoC;AAC7B,SAAA,IAAI,kBAAkB,WAAW;AAC1C;;;"}
1
+ {"version":3,"file":"single-type.js","sources":["../../../src/core-api/service/single-type.ts"],"sourcesContent":["import type { Struct, Core } from '@strapi/types';\nimport { CoreService } from './core-service';\n\nexport class SingleTypeService extends CoreService implements Core.CoreAPI.Service.SingleType {\n private contentType: Struct.SingleTypeSchema;\n\n constructor(contentType: Struct.SingleTypeSchema) {\n super();\n\n this.contentType = contentType;\n }\n\n async getDocumentId() {\n const { uid } = this.contentType;\n\n return strapi.db\n .query(uid)\n .findOne()\n .then((document) => document?.documentId as string);\n }\n\n async find(params = {}) {\n const { uid } = this.contentType;\n\n return strapi.documents(uid).findFirst(this.getFetchParams(params));\n }\n\n async createOrUpdate(params = {}) {\n const { uid } = this.contentType;\n\n const documentId = await this.getDocumentId();\n\n if (documentId) {\n return strapi.documents(uid).update({\n ...this.getFetchParams(params),\n documentId,\n });\n }\n\n return strapi.documents(uid).create(this.getFetchParams(params));\n }\n\n async delete(params = {}) {\n const { uid } = this.contentType;\n\n const documentId = await this.getDocumentId();\n if (!documentId) return { deletedEntries: 0 };\n\n const { entries } = await strapi.documents(uid).delete({\n ...this.getFetchParams(params),\n documentId,\n });\n\n return { deletedEntries: entries.length };\n }\n}\n\nconst createSingleTypeService = (\n contentType: Struct.SingleTypeSchema\n): Core.CoreAPI.Service.SingleType => {\n return new SingleTypeService(contentType);\n};\n\nexport { createSingleTypeService };\n"],"names":["CoreService"],"mappings":";;;AAGO,MAAM,0BAA0BA,YAAAA,YAAuD;AAAA,EACpF;AAAA,EAER,YAAY,aAAsC;AAC1C;AAEN,SAAK,cAAc;AAAA,EACrB;AAAA,EAEA,MAAM,gBAAgB;AACd,UAAA,EAAE,IAAI,IAAI,KAAK;AAEd,WAAA,OAAO,GACX,MAAM,GAAG,EACT,UACA,KAAK,CAAC,aAAa,UAAU,UAAoB;AAAA,EACtD;AAAA,EAEA,MAAM,KAAK,SAAS,IAAI;AAChB,UAAA,EAAE,IAAI,IAAI,KAAK;AAEd,WAAA,OAAO,UAAU,GAAG,EAAE,UAAU,KAAK,eAAe,MAAM,CAAC;AAAA,EACpE;AAAA,EAEA,MAAM,eAAe,SAAS,IAAI;AAC1B,UAAA,EAAE,IAAI,IAAI,KAAK;AAEf,UAAA,aAAa,MAAM,KAAK;AAE9B,QAAI,YAAY;AACd,aAAO,OAAO,UAAU,GAAG,EAAE,OAAO;AAAA,QAClC,GAAG,KAAK,eAAe,MAAM;AAAA,QAC7B;AAAA,MAAA,CACD;AAAA,IACH;AAEO,WAAA,OAAO,UAAU,GAAG,EAAE,OAAO,KAAK,eAAe,MAAM,CAAC;AAAA,EACjE;AAAA,EAEA,MAAM,OAAO,SAAS,IAAI;AAClB,UAAA,EAAE,IAAI,IAAI,KAAK;AAEf,UAAA,aAAa,MAAM,KAAK;AAC9B,QAAI,CAAC;AAAmB,aAAA,EAAE,gBAAgB;AAEpC,UAAA,EAAE,YAAY,MAAM,OAAO,UAAU,GAAG,EAAE,OAAO;AAAA,MACrD,GAAG,KAAK,eAAe,MAAM;AAAA,MAC7B;AAAA,IAAA,CACD;AAEM,WAAA,EAAE,gBAAgB,QAAQ;EACnC;AACF;AAEM,MAAA,0BAA0B,CAC9B,gBACoC;AAC7B,SAAA,IAAI,kBAAkB,WAAW;AAC1C;;;"}
@@ -29,10 +29,11 @@ class SingleTypeService extends CoreService {
29
29
  const documentId = await this.getDocumentId();
30
30
  if (!documentId)
31
31
  return { deletedEntries: 0 };
32
- return strapi.documents(uid).delete({
32
+ const { entries } = await strapi.documents(uid).delete({
33
33
  ...this.getFetchParams(params),
34
34
  documentId
35
35
  });
36
+ return { deletedEntries: entries.length };
36
37
  }
37
38
  }
38
39
  const createSingleTypeService = (contentType) => {
@@ -1 +1 @@
1
- {"version":3,"file":"single-type.mjs","sources":["../../../src/core-api/service/single-type.ts"],"sourcesContent":["import type { Struct, Core } from '@strapi/types';\nimport { CoreService } from './core-service';\n\nexport class SingleTypeService extends CoreService implements Core.CoreAPI.Service.SingleType {\n private contentType: Struct.SingleTypeSchema;\n\n constructor(contentType: Struct.SingleTypeSchema) {\n super();\n\n this.contentType = contentType;\n }\n\n async getDocumentId() {\n const { uid } = this.contentType;\n\n return strapi.db\n .query(uid)\n .findOne()\n .then((document) => document?.documentId as string);\n }\n\n async find(params = {}) {\n const { uid } = this.contentType;\n\n return strapi.documents(uid).findFirst(this.getFetchParams(params));\n }\n\n async createOrUpdate(params = {}) {\n const { uid } = this.contentType;\n\n const documentId = await this.getDocumentId();\n\n if (documentId) {\n return strapi.documents(uid).update({\n ...this.getFetchParams(params),\n documentId,\n });\n }\n\n return strapi.documents(uid).create(this.getFetchParams(params));\n }\n\n async delete(params = {}) {\n const { uid } = this.contentType;\n\n const documentId = await this.getDocumentId();\n if (!documentId) return { deletedEntries: 0 };\n\n return strapi.documents(uid).delete({\n ...this.getFetchParams(params),\n documentId,\n });\n }\n}\n\nconst createSingleTypeService = (\n contentType: Struct.SingleTypeSchema\n): Core.CoreAPI.Service.SingleType => {\n return new SingleTypeService(contentType);\n};\n\nexport { createSingleTypeService };\n"],"names":[],"mappings":";AAGO,MAAM,0BAA0B,YAAuD;AAAA,EACpF;AAAA,EAER,YAAY,aAAsC;AAC1C;AAEN,SAAK,cAAc;AAAA,EACrB;AAAA,EAEA,MAAM,gBAAgB;AACd,UAAA,EAAE,IAAI,IAAI,KAAK;AAEd,WAAA,OAAO,GACX,MAAM,GAAG,EACT,UACA,KAAK,CAAC,aAAa,UAAU,UAAoB;AAAA,EACtD;AAAA,EAEA,MAAM,KAAK,SAAS,IAAI;AAChB,UAAA,EAAE,IAAI,IAAI,KAAK;AAEd,WAAA,OAAO,UAAU,GAAG,EAAE,UAAU,KAAK,eAAe,MAAM,CAAC;AAAA,EACpE;AAAA,EAEA,MAAM,eAAe,SAAS,IAAI;AAC1B,UAAA,EAAE,IAAI,IAAI,KAAK;AAEf,UAAA,aAAa,MAAM,KAAK;AAE9B,QAAI,YAAY;AACd,aAAO,OAAO,UAAU,GAAG,EAAE,OAAO;AAAA,QAClC,GAAG,KAAK,eAAe,MAAM;AAAA,QAC7B;AAAA,MAAA,CACD;AAAA,IACH;AAEO,WAAA,OAAO,UAAU,GAAG,EAAE,OAAO,KAAK,eAAe,MAAM,CAAC;AAAA,EACjE;AAAA,EAEA,MAAM,OAAO,SAAS,IAAI;AAClB,UAAA,EAAE,IAAI,IAAI,KAAK;AAEf,UAAA,aAAa,MAAM,KAAK;AAC9B,QAAI,CAAC;AAAmB,aAAA,EAAE,gBAAgB;AAE1C,WAAO,OAAO,UAAU,GAAG,EAAE,OAAO;AAAA,MAClC,GAAG,KAAK,eAAe,MAAM;AAAA,MAC7B;AAAA,IAAA,CACD;AAAA,EACH;AACF;AAEM,MAAA,0BAA0B,CAC9B,gBACoC;AAC7B,SAAA,IAAI,kBAAkB,WAAW;AAC1C;"}
1
+ {"version":3,"file":"single-type.mjs","sources":["../../../src/core-api/service/single-type.ts"],"sourcesContent":["import type { Struct, Core } from '@strapi/types';\nimport { CoreService } from './core-service';\n\nexport class SingleTypeService extends CoreService implements Core.CoreAPI.Service.SingleType {\n private contentType: Struct.SingleTypeSchema;\n\n constructor(contentType: Struct.SingleTypeSchema) {\n super();\n\n this.contentType = contentType;\n }\n\n async getDocumentId() {\n const { uid } = this.contentType;\n\n return strapi.db\n .query(uid)\n .findOne()\n .then((document) => document?.documentId as string);\n }\n\n async find(params = {}) {\n const { uid } = this.contentType;\n\n return strapi.documents(uid).findFirst(this.getFetchParams(params));\n }\n\n async createOrUpdate(params = {}) {\n const { uid } = this.contentType;\n\n const documentId = await this.getDocumentId();\n\n if (documentId) {\n return strapi.documents(uid).update({\n ...this.getFetchParams(params),\n documentId,\n });\n }\n\n return strapi.documents(uid).create(this.getFetchParams(params));\n }\n\n async delete(params = {}) {\n const { uid } = this.contentType;\n\n const documentId = await this.getDocumentId();\n if (!documentId) return { deletedEntries: 0 };\n\n const { entries } = await strapi.documents(uid).delete({\n ...this.getFetchParams(params),\n documentId,\n });\n\n return { deletedEntries: entries.length };\n }\n}\n\nconst createSingleTypeService = (\n contentType: Struct.SingleTypeSchema\n): Core.CoreAPI.Service.SingleType => {\n return new SingleTypeService(contentType);\n};\n\nexport { createSingleTypeService };\n"],"names":[],"mappings":";AAGO,MAAM,0BAA0B,YAAuD;AAAA,EACpF;AAAA,EAER,YAAY,aAAsC;AAC1C;AAEN,SAAK,cAAc;AAAA,EACrB;AAAA,EAEA,MAAM,gBAAgB;AACd,UAAA,EAAE,IAAI,IAAI,KAAK;AAEd,WAAA,OAAO,GACX,MAAM,GAAG,EACT,UACA,KAAK,CAAC,aAAa,UAAU,UAAoB;AAAA,EACtD;AAAA,EAEA,MAAM,KAAK,SAAS,IAAI;AAChB,UAAA,EAAE,IAAI,IAAI,KAAK;AAEd,WAAA,OAAO,UAAU,GAAG,EAAE,UAAU,KAAK,eAAe,MAAM,CAAC;AAAA,EACpE;AAAA,EAEA,MAAM,eAAe,SAAS,IAAI;AAC1B,UAAA,EAAE,IAAI,IAAI,KAAK;AAEf,UAAA,aAAa,MAAM,KAAK;AAE9B,QAAI,YAAY;AACd,aAAO,OAAO,UAAU,GAAG,EAAE,OAAO;AAAA,QAClC,GAAG,KAAK,eAAe,MAAM;AAAA,QAC7B;AAAA,MAAA,CACD;AAAA,IACH;AAEO,WAAA,OAAO,UAAU,GAAG,EAAE,OAAO,KAAK,eAAe,MAAM,CAAC;AAAA,EACjE;AAAA,EAEA,MAAM,OAAO,SAAS,IAAI;AAClB,UAAA,EAAE,IAAI,IAAI,KAAK;AAEf,UAAA,aAAa,MAAM,KAAK;AAC9B,QAAI,CAAC;AAAmB,aAAA,EAAE,gBAAgB;AAEpC,UAAA,EAAE,YAAY,MAAM,OAAO,UAAU,GAAG,EAAE,OAAO;AAAA,MACrD,GAAG,KAAK,eAAe,MAAM;AAAA,MAC7B;AAAA,IAAA,CACD;AAEM,WAAA,EAAE,gBAAgB,QAAQ;EACnC;AACF;AAEM,MAAA,0BAA0B,CAC9B,gBACoC;AAC7B,SAAA,IAAI,kBAAkB,WAAW;AAC1C;"}
@@ -1 +1 @@
1
- {"version":3,"file":"apis.d.ts","sourceRoot":"","sources":["../../src/loaders/apis.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,IAAI,EAAU,MAAM,eAAe,CAAC;AAgClD,wBAA8B,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,iBAwBzD"}
1
+ {"version":3,"file":"apis.d.ts","sourceRoot":"","sources":["../../src/loaders/apis.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,IAAI,EAAU,MAAM,eAAe,CAAC;AAgClD,wBAA8B,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,iBAyBzD"}
@@ -53,7 +53,7 @@ const validateContentTypesUnicity = (apis) => {
53
53
  });
54
54
  };
55
55
  const loadAPI = async (apiName, dir) => {
56
- const [index2, config, routes, controllers, services, policies, middlewares, contentTypes] = await Promise.all([
56
+ const [index2, config, routes, controllers, services, policies, middlewares, contentTypes] = (await Promise.all([
57
57
  loadIndex(dir),
58
58
  loadDir(path.join(dir, "config")),
59
59
  loadDir(path.join(dir, "routes")),
@@ -62,7 +62,7 @@ const loadAPI = async (apiName, dir) => {
62
62
  loadDir(path.join(dir, "policies")),
63
63
  loadDir(path.join(dir, "middlewares")),
64
64
  loadContentTypes(apiName, path.join(dir, "content-types"))
65
- ]);
65
+ ])).map((result) => result?.result);
66
66
  return {
67
67
  ...index2 || {},
68
68
  config: config || {},
@@ -90,7 +90,7 @@ const loadContentTypes = async (apiName, dir) => {
90
90
  continue;
91
91
  }
92
92
  const contentTypeName = normalizeName(fd.name);
93
- const loadedContentType = await loadDir(path.join(dir, fd.name));
93
+ const loadedContentType = (await loadDir(path.join(dir, fd.name)))?.result;
94
94
  if (_$1.isEmpty(loadedContentType) || _$1.isEmpty(loadedContentType.schema)) {
95
95
  throw new Error(`Could not load content type found at ${dir}`);
96
96
  }
@@ -105,7 +105,7 @@ const loadContentTypes = async (apiName, dir) => {
105
105
  });
106
106
  contentTypes[normalizeName(contentTypeName)] = contentType;
107
107
  }
108
- return contentTypes;
108
+ return { result: contentTypes };
109
109
  };
110
110
  const loadDir = async (dir) => {
111
111
  if (!await fse__default.default.pathExists(dir)) {
@@ -118,19 +118,19 @@ const loadDir = async (dir) => {
118
118
  continue;
119
119
  }
120
120
  const key = path.basename(fd.name, path.extname(fd.name));
121
- root[normalizeName(key)] = await loadFile(path.join(dir, fd.name));
121
+ root[normalizeName(key)] = (await loadFile(path.join(dir, fd.name))).result;
122
122
  }
123
- return root;
123
+ return { result: root };
124
124
  };
125
- const loadFile = (file) => {
125
+ const loadFile = async (file) => {
126
126
  const ext = path.extname(file);
127
127
  switch (ext) {
128
128
  case ".js":
129
- return strapiUtils.importDefault(file);
129
+ return { result: strapiUtils.importDefault(file) };
130
130
  case ".json":
131
- return fse__default.default.readJSON(file);
131
+ return { result: await fse__default.default.readJSON(file) };
132
132
  default:
133
- return {};
133
+ return { result: {} };
134
134
  }
135
135
  };
136
136
  module.exports = loadAPIs;
@@ -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 { strings, importDefault } from '@strapi/utils';\nimport { isEmpty } from 'lodash/fp';\nimport type { Core, Struct } 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, Core.Router>;\n controllers: Record<string, Core.Controller>;\n services: Record<string, Core.Service>;\n policies: Record<string, Core.Policy>;\n middlewares: Record<string, Core.Middleware>;\n contentTypes: Record<string, { schema: Struct.ContentTypeSchema }>;\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: Core.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,EAC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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 { Core, Struct } 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, Core.Router>;\n controllers: Record<string, Core.Controller>;\n services: Record<string, Core.Service>;\n policies: Record<string, Core.Policy>;\n middlewares: Record<string, Core.Middleware>;\n contentTypes: Record<string, { schema: Struct.ContentTypeSchema }>;\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: Core.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 // @ts-expect-error TODO verify that it's a valid api, not missing bootstrap, register, and destroy\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 ).map((result) => result?.result);\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\n// because this is async and its contents are dynamic, we must return it within an object to avoid a property called `then` being interpreted as a Promise\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)))?.result;\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 { result: contentTypes };\n};\n\n// because this is async and its contents are dynamic, we must return it within an object to avoid a property called `then` being interpreted as a Promise\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))).result;\n }\n\n return { result: root };\n};\n\n// because this is async and its contents are dynamic, we must return it as an array to avoid a property called `then` being interpreted as a Promise\nconst loadFile = async (file: string): Promise<{ result: unknown }> => {\n const ext = extname(file);\n\n switch (ext) {\n case '.js':\n return { result: importDefault(file) };\n case '.json':\n return { result: await fse.readJSON(file) };\n default:\n return { result: {} };\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,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A,UAAM,MAAMC,KAAS,SAAA,GAAG,MAAMD,KAAAA,QAAQ,GAAG,IAAI,CAAC;AAEzC,SAAA,cAAc,GAAG,CAAC,KAAK,MAAM,SAASJ,KAAA,KAAK,KAAK,GAAG,IAAI,CAAC,GAAG;AAAA,EAClE;AAEO,SAAA,EAAE,QAAQ;AACnB;AAGA,MAAM,WAAW,OAAO,SAA+C;AAC/D,QAAA,MAAMI,aAAQ,IAAI;AAExB,UAAQ,KAAK;AAAA,IACX,KAAK;AACH,aAAO,EAAE,QAAQE,0BAAc,IAAI,EAAE;AAAA,IACvC,KAAK;AACH,aAAO,EAAE,QAAQ,MAAMP,aAAAA,QAAI,SAAS,IAAI,EAAE;AAAA,IAC5C;AACS,aAAA,EAAE,QAAQ,CAAA;EACrB;AACF;;"}
@@ -49,7 +49,7 @@ const validateContentTypesUnicity = (apis) => {
49
49
  });
50
50
  };
51
51
  const loadAPI = async (apiName, dir) => {
52
- const [index, config, routes, controllers, services, policies, middlewares, contentTypes] = await Promise.all([
52
+ const [index, config, routes, controllers, services, policies, middlewares, contentTypes] = (await Promise.all([
53
53
  loadIndex(dir),
54
54
  loadDir(join(dir, "config")),
55
55
  loadDir(join(dir, "routes")),
@@ -58,7 +58,7 @@ const loadAPI = async (apiName, dir) => {
58
58
  loadDir(join(dir, "policies")),
59
59
  loadDir(join(dir, "middlewares")),
60
60
  loadContentTypes(apiName, join(dir, "content-types"))
61
- ]);
61
+ ])).map((result) => result?.result);
62
62
  return {
63
63
  ...index || {},
64
64
  config: config || {},
@@ -86,7 +86,7 @@ const loadContentTypes = async (apiName, dir) => {
86
86
  continue;
87
87
  }
88
88
  const contentTypeName = normalizeName(fd.name);
89
- const loadedContentType = await loadDir(join(dir, fd.name));
89
+ const loadedContentType = (await loadDir(join(dir, fd.name)))?.result;
90
90
  if (isEmpty(loadedContentType) || isEmpty(loadedContentType.schema)) {
91
91
  throw new Error(`Could not load content type found at ${dir}`);
92
92
  }
@@ -101,7 +101,7 @@ const loadContentTypes = async (apiName, dir) => {
101
101
  });
102
102
  contentTypes[normalizeName(contentTypeName)] = contentType;
103
103
  }
104
- return contentTypes;
104
+ return { result: contentTypes };
105
105
  };
106
106
  const loadDir = async (dir) => {
107
107
  if (!await fse.pathExists(dir)) {
@@ -114,19 +114,19 @@ const loadDir = async (dir) => {
114
114
  continue;
115
115
  }
116
116
  const key = basename(fd.name, extname(fd.name));
117
- root[normalizeName(key)] = await loadFile(join(dir, fd.name));
117
+ root[normalizeName(key)] = (await loadFile(join(dir, fd.name))).result;
118
118
  }
119
- return root;
119
+ return { result: root };
120
120
  };
121
- const loadFile = (file) => {
121
+ const loadFile = async (file) => {
122
122
  const ext = extname(file);
123
123
  switch (ext) {
124
124
  case ".js":
125
- return importDefault(file);
125
+ return { result: importDefault(file) };
126
126
  case ".json":
127
- return fse.readJSON(file);
127
+ return { result: await fse.readJSON(file) };
128
128
  default:
129
- return {};
129
+ return { result: {} };
130
130
  }
131
131
  };
132
132
  export {
@@ -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 { strings, importDefault } from '@strapi/utils';\nimport { isEmpty } from 'lodash/fp';\nimport type { Core, Struct } 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, Core.Router>;\n controllers: Record<string, Core.Controller>;\n services: Record<string, Core.Service>;\n policies: Record<string, Core.Policy>;\n middlewares: Record<string, Core.Middleware>;\n contentTypes: Record<string, { schema: Struct.ContentTypeSchema }>;\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: Core.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,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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 { Core, Struct } 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, Core.Router>;\n controllers: Record<string, Core.Controller>;\n services: Record<string, Core.Service>;\n policies: Record<string, Core.Policy>;\n middlewares: Record<string, Core.Middleware>;\n contentTypes: Record<string, { schema: Struct.ContentTypeSchema }>;\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: Core.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 // @ts-expect-error TODO verify that it's a valid api, not missing bootstrap, register, and destroy\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 ).map((result) => result?.result);\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\n// because this is async and its contents are dynamic, we must return it within an object to avoid a property called `then` being interpreted as a Promise\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)))?.result;\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 { result: contentTypes };\n};\n\n// because this is async and its contents are dynamic, we must return it within an object to avoid a property called `then` being interpreted as a Promise\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))).result;\n }\n\n return { result: root };\n};\n\n// because this is async and its contents are dynamic, we must return it as an array to avoid a property called `then` being interpreted as a Promise\nconst loadFile = async (file: string): Promise<{ result: unknown }> => {\n const ext = extname(file);\n\n switch (ext) {\n case '.js':\n return { result: importDefault(file) };\n case '.json':\n return { result: await fse.readJSON(file) };\n default:\n return { result: {} };\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,QAAqB;AAC1D,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,CAA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,IAAI,MAAM,wCAAwC,GAAG,EAAE;AAAA,IAC/D;AAEA,UAAM,cAAc;AAAA,MAClB,GAAG;AAAA,MACH,GAAG;AAAA,IAAA;AAGE,WAAA,OAAO,YAAY,QAAQ;AAAA,MAChC;AAAA,MACA,gBAAgB,YAAY,OAAO,kBAAkB,YAAY,OAAO,KAAK;AAAA,MAC7E,UAAU,YAAY,YAAY,MAAM;AAAA,IAAA,CACzC;AAEY,iBAAA,cAAc,eAAe,CAAC,IAAI;AAAA,EACjD;AAEO,SAAA,EAAE,QAAQ;AACnB;AAGA,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,KAAK,MAAM,SAAS,KAAK,KAAK,GAAG,IAAI,CAAC,GAAG;AAAA,EAClE;AAEO,SAAA,EAAE,QAAQ;AACnB;AAGA,MAAM,WAAW,OAAO,SAA+C;AAC/D,QAAA,MAAM,QAAQ,IAAI;AAExB,UAAQ,KAAK;AAAA,IACX,KAAK;AACH,aAAO,EAAE,QAAQ,cAAc,IAAI,EAAE;AAAA,IACvC,KAAK;AACH,aAAO,EAAE,QAAQ,MAAM,IAAI,SAAS,IAAI,EAAE;AAAA,IAC5C;AACS,aAAA,EAAE,QAAQ,CAAA;EACrB;AACF;"}
@@ -9,11 +9,11 @@ const getUserPluginsConfig = require("./get-user-plugins-config.js");
9
9
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
10
10
  const ___default = /* @__PURE__ */ _interopDefault(_);
11
11
  const INTERNAL_PLUGINS = [
12
- "@strapi/plugin-content-manager",
13
- "@strapi/plugin-content-type-builder",
14
- "@strapi/plugin-email",
15
- "@strapi/plugin-upload",
16
- "@strapi/plugin-i18n",
12
+ "@strapi/content-manager",
13
+ "@strapi/content-type-builder",
14
+ "@strapi/email",
15
+ "@strapi/upload",
16
+ "@strapi/i18n",
17
17
  "@strapi/content-releases",
18
18
  "@strapi/review-workflows"
19
19
  ];
@@ -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 { strings } from '@strapi/utils';\nimport type { Core } 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/plugin-i18n',\n '@strapi/content-releases',\n '@strapi/review-workflows',\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: Core.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;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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AMM,qBAAAA;AAEhCC,aAAAA,QAAE,QAAQ,mBAAmB,CAAC,aAAa,eAAe;AACxD,uBAAmB,UAAU;AAE7B,oBAAgB,UAAU,IAAI;AAAA,MAC5B,GAAG,sBAAsB,WAAW;AAAA,MACpC,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;;"}
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 { Core } 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/content-manager',\n '@strapi/content-type-builder',\n '@strapi/email',\n '@strapi/upload',\n '@strapi/i18n',\n '@strapi/content-releases',\n '@strapi/review-workflows',\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: Core.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;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,iBAAiB,CAAC,SAAqBA,IAAAA,IAAI,eAAe,IAAI,MAAM;AAE1E,MAAM,qBAAqB,CAAC,eAAuB;AACjD,MAAI,CAACC,YAA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AAAA,OAAO,CAAC,MAAkB,EAAE,OAAO;AAAA,IACnC,eAAe;AAEV,SAAA;AACT;;"}
@@ -5,11 +5,11 @@ import { map, prop, pickBy, pipe, defaultsDeep, get } from "lodash/fp";
5
5
  import { strings } from "@strapi/utils";
6
6
  import { getUserPluginsConfig } from "./get-user-plugins-config.mjs";
7
7
  const INTERNAL_PLUGINS = [
8
- "@strapi/plugin-content-manager",
9
- "@strapi/plugin-content-type-builder",
10
- "@strapi/plugin-email",
11
- "@strapi/plugin-upload",
12
- "@strapi/plugin-i18n",
8
+ "@strapi/content-manager",
9
+ "@strapi/content-type-builder",
10
+ "@strapi/email",
11
+ "@strapi/upload",
12
+ "@strapi/i18n",
13
13
  "@strapi/content-releases",
14
14
  "@strapi/review-workflows"
15
15
  ];
@@ -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 { strings } from '@strapi/utils';\nimport type { Core } 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/plugin-i18n',\n '@strapi/content-releases',\n '@strapi/review-workflows',\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: Core.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;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,UA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EJ;AAAA,EACF;AAEA,QAAM,kBAA+B,CAAA;AAC/B,QAAA,oBAAoB,MAAM;AAEhC,IAAE,QAAQ,mBAAmB,CAAC,aAAa,eAAe;AACxD,uBAAmB,UAAU;AAE7B,oBAAgB,UAAU,IAAI;AAAA,MAC5B,GAAG,sBAAsB,WAAW;AAAA,MACpC,MAAM,CAAC;AAAA,IAAA;AAGT,UAAM,EAAE,aAAA,IAAiB,gBAAgB,UAAU;AAGnD,QAAI,cAAc;AACV,YAAA,cAAc,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,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;"}
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 { Core } 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/content-manager',\n '@strapi/content-type-builder',\n '@strapi/email',\n '@strapi/upload',\n '@strapi/i18n',\n '@strapi/content-releases',\n '@strapi/review-workflows',\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: Core.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;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,wB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ACF;AAEI,QAAA,eAAe,WAAW,GAAG;AACZ,yBAAA,YAAY,OAAO,IAAI;AACzB,uBAAA,YAAY,OAAO,IAAI,IAAI;AAAA,QAC1C,GAAG,sBAAsB,EAAE,SAAS,MAAM,SAAS,aAAa,UAAU,QAAQ;AAAA,QAClF,MAAM;AAAA,UACJ,GAAG,YAAY;AAAA,UACf,aAAa,YAAY;AAAA,QAC3B;AAAA,MAAA;AAAA,IAEJ;AAAA,EACF;AAEA,QAAM,kBAA+B,CAAA;AAC/B,QAAA,oBAAoB,MAAM;AAEhC,IAAE,QAAQ,mBAAmB,CAAC,aAAa,eAAe;AACxD,uBAAmB,UAAU;AAE7B,oBAAgB,UAAU,IAAI;AAAA,MAC5B,GAAG,sBAAsB,WAAW;AAAA,MACpC,MAAM,CAAC;AAAA,IAAA;AAGT,UAAM,EAAE,aAAA,IAAiB,gBAAgB,UAAU;AAGnD,QAAI,cAAc;AACV,YAAA,cAAc,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,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,12 @@
1
+ import type { Migration } from '@strapi/database';
2
+ /**
3
+ * On V4 there was no concept of document, and an entry could be in a draft or published state.
4
+ * But not both at the same time.
5
+ *
6
+ * On V5 we introduced the concept of document, and an entry can be in a draft or published state,
7
+ * with the requirement that a document must always have a draft.
8
+ *
9
+ * This migration creates the document draft counterpart for all the entries that were in a published state.
10
+ */
11
+ export declare const discardDocumentDrafts: Migration;
12
+ //# sourceMappingURL=5.0.0-discard-drafts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"5.0.0-discard-drafts.d.ts","sourceRoot":"","sources":["../../../src/migrations/database/5.0.0-discard-drafts.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAY,SAAS,EAAE,MAAM,kBAAkB,CAAC;AA8E5D;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,EAAE,SASnC,CAAC"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const strapiUtils = require("@strapi/utils");
4
+ async function* getBatchToDiscard({
5
+ db,
6
+ trx,
7
+ uid,
8
+ batchSize = 1e3
9
+ }) {
10
+ let offset = 0;
11
+ let hasMore = true;
12
+ while (hasMore) {
13
+ const batch = await db.queryBuilder(uid).select(["id", "documentId", "locale"]).where({ publishedAt: { $ne: null } }).limit(batchSize).offset(offset).orderBy("id").transacting(trx).execute();
14
+ if (batch.length < batchSize) {
15
+ hasMore = false;
16
+ }
17
+ offset += batchSize;
18
+ yield batch;
19
+ }
20
+ }
21
+ const migrateUp = async (trx, db) => {
22
+ for (const meta of db.metadata.values()) {
23
+ const hasTable = await trx.schema.hasTable(meta.tableName);
24
+ if (!hasTable) {
25
+ continue;
26
+ }
27
+ const uid = meta.uid;
28
+ const model = strapi.getModel(uid);
29
+ const hasDP = strapiUtils.contentTypes.hasDraftAndPublish(model);
30
+ if (!hasDP) {
31
+ continue;
32
+ }
33
+ const discardDraft = async (entry) => strapi.documents(uid).discardDraft({ documentId: entry.documentId, locale: entry.locale });
34
+ for await (const batch of getBatchToDiscard({ db, trx, uid: meta.uid })) {
35
+ await strapiUtils.async.map(batch, discardDraft, { concurrency: 10 });
36
+ }
37
+ }
38
+ };
39
+ const discardDocumentDrafts = {
40
+ name: "core::5.0.0-discard-drafts",
41
+ async up(trx, db) {
42
+ await migrateUp(trx, db);
43
+ },
44
+ async down() {
45
+ throw new Error("not implemented");
46
+ }
47
+ };
48
+ exports.discardDocumentDrafts = discardDocumentDrafts;
49
+ //# sourceMappingURL=5.0.0-discard-drafts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"5.0.0-discard-drafts.js","sources":["../../../src/migrations/database/5.0.0-discard-drafts.ts"],"sourcesContent":["/* eslint-disable no-continue */\nimport type { UID } from '@strapi/types';\nimport type { Database, Migration } from '@strapi/database';\nimport { async, contentTypes } from '@strapi/utils';\n\ntype DocumentVersion = { documentId: string; locale: string };\ntype Knex = Parameters<Migration['up']>[0];\n\n/**\n * Load a batch of versions to discard.\n *\n * Versions with only a draft version will be ignored.\n * Only versions with a published version (which always have a draft version) will be discarded.\n */\nasync function* getBatchToDiscard({\n db,\n trx,\n uid,\n batchSize = 1000,\n}: {\n db: Database;\n trx: Knex;\n uid: string;\n batchSize?: number;\n}) {\n let offset = 0;\n let hasMore = true;\n\n while (hasMore) {\n // Look for the published entries to discard\n const batch: DocumentVersion[] = await db\n .queryBuilder(uid)\n .select(['id', 'documentId', 'locale'])\n .where({ publishedAt: { $ne: null } })\n .limit(batchSize)\n .offset(offset)\n .orderBy('id')\n .transacting(trx)\n .execute();\n\n if (batch.length < batchSize) {\n hasMore = false;\n }\n\n offset += batchSize;\n yield batch;\n }\n}\n\nconst migrateUp = async (trx: Knex, db: Database) => {\n for (const meta of db.metadata.values()) {\n const hasTable = await trx.schema.hasTable(meta.tableName);\n\n if (!hasTable) {\n continue;\n }\n\n const uid = meta.uid as UID.ContentType;\n const model = strapi.getModel(uid);\n const hasDP = contentTypes.hasDraftAndPublish(model);\n if (!hasDP) {\n continue;\n }\n\n const discardDraft = async (entry: DocumentVersion) =>\n strapi\n .documents(uid)\n // Discard draft by referencing the documentId and locale\n .discardDraft({ documentId: entry.documentId, locale: entry.locale });\n\n /**\n * Load a batch of entries (batched to prevent loading millions of rows at once ),\n * and discard them using the document service.\n */\n for await (const batch of getBatchToDiscard({ db, trx, uid: meta.uid })) {\n await async.map(batch, discardDraft, { concurrency: 10 });\n }\n }\n};\n\n/**\n * On V4 there was no concept of document, and an entry could be in a draft or published state.\n * But not both at the same time.\n *\n * On V5 we introduced the concept of document, and an entry can be in a draft or published state,\n * with the requirement that a document must always have a draft.\n *\n * This migration creates the document draft counterpart for all the entries that were in a published state.\n */\nexport const discardDocumentDrafts: Migration = {\n name: 'core::5.0.0-discard-drafts',\n async up(trx, db) {\n // TODO: Log to inform the user that the migration is running in the background\n await migrateUp(trx, db);\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["contentTypes","async"],"mappings":";;;AAcA,gBAAgB,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY;AACd,GAKG;AACD,MAAI,SAAS;AACb,MAAI,UAAU;AAEd,SAAO,SAAS;AAEd,UAAM,QAA2B,MAAM,GACpC,aAAa,GAAG,EAChB,OAAO,CAAC,MAAM,cAAc,QAAQ,CAAC,EACrC,MAAM,EAAE,aAAa,EAAE,KAAK,KAAO,EAAA,CAAC,EACpC,MAAM,SAAS,EACf,OAAO,MAAM,EACb,QAAQ,IAAI,EACZ,YAAY,GAAG,EACf,QAAQ;AAEP,QAAA,MAAM,SAAS,WAAW;AAClB,gBAAA;AAAA,IACZ;AAEU,cAAA;AACJ,UAAA;AAAA,EACR;AACF;AAEA,MAAM,YAAY,OAAO,KAAW,OAAiB;AACnD,aAAW,QAAQ,GAAG,SAAS,OAAA,GAAU;AACvC,UAAM,WAAW,MAAM,IAAI,OAAO,SAAS,KAAK,SAAS;AAEzD,QAAI,CAAC,UAAU;AACb;AAAA,IACF;AAEA,UAAM,MAAM,KAAK;AACX,UAAA,QAAQ,OAAO,SAAS,GAAG;AAC3B,UAAA,QAAQA,YAAAA,aAAa,mBAAmB,KAAK;AACnD,QAAI,CAAC,OAAO;AACV;AAAA,IACF;AAEA,UAAM,eAAe,OAAO,UAC1B,OACG,UAAU,GAAG,EAEb,aAAa,EAAE,YAAY,MAAM,YAAY,QAAQ,MAAM,QAAQ;AAMvD,qBAAA,SAAS,kBAAkB,EAAE,IAAI,KAAK,KAAK,KAAK,IAAI,CAAC,GAAG;AACvE,YAAMC,YAAAA,MAAM,IAAI,OAAO,cAAc,EAAE,aAAa,IAAI;AAAA,IAC1D;AAAA,EACF;AACF;AAWO,MAAM,wBAAmC;AAAA,EAC9C,MAAM;AAAA,EACN,MAAM,GAAG,KAAK,IAAI;AAEV,UAAA,UAAU,KAAK,EAAE;AAAA,EACzB;AAAA,EACA,MAAM,OAAO;AACL,UAAA,IAAI,MAAM,iBAAiB;AAAA,EACnC;AACF;;"}
@@ -0,0 +1,49 @@
1
+ import { contentTypes, async } from "@strapi/utils";
2
+ async function* getBatchToDiscard({
3
+ db,
4
+ trx,
5
+ uid,
6
+ batchSize = 1e3
7
+ }) {
8
+ let offset = 0;
9
+ let hasMore = true;
10
+ while (hasMore) {
11
+ const batch = await db.queryBuilder(uid).select(["id", "documentId", "locale"]).where({ publishedAt: { $ne: null } }).limit(batchSize).offset(offset).orderBy("id").transacting(trx).execute();
12
+ if (batch.length < batchSize) {
13
+ hasMore = false;
14
+ }
15
+ offset += batchSize;
16
+ yield batch;
17
+ }
18
+ }
19
+ const migrateUp = async (trx, db) => {
20
+ for (const meta of db.metadata.values()) {
21
+ const hasTable = await trx.schema.hasTable(meta.tableName);
22
+ if (!hasTable) {
23
+ continue;
24
+ }
25
+ const uid = meta.uid;
26
+ const model = strapi.getModel(uid);
27
+ const hasDP = contentTypes.hasDraftAndPublish(model);
28
+ if (!hasDP) {
29
+ continue;
30
+ }
31
+ const discardDraft = async (entry) => strapi.documents(uid).discardDraft({ documentId: entry.documentId, locale: entry.locale });
32
+ for await (const batch of getBatchToDiscard({ db, trx, uid: meta.uid })) {
33
+ await async.map(batch, discardDraft, { concurrency: 10 });
34
+ }
35
+ }
36
+ };
37
+ const discardDocumentDrafts = {
38
+ name: "core::5.0.0-discard-drafts",
39
+ async up(trx, db) {
40
+ await migrateUp(trx, db);
41
+ },
42
+ async down() {
43
+ throw new Error("not implemented");
44
+ }
45
+ };
46
+ export {
47
+ discardDocumentDrafts
48
+ };
49
+ //# sourceMappingURL=5.0.0-discard-drafts.mjs.map