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

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 (80) hide show
  1. package/dist/core-api/controller/collection-type.d.ts.map +1 -1
  2. package/dist/core-api/controller/collection-type.js +2 -0
  3. package/dist/core-api/controller/collection-type.js.map +1 -1
  4. package/dist/core-api/controller/collection-type.mjs +2 -0
  5. package/dist/core-api/controller/collection-type.mjs.map +1 -1
  6. package/dist/core-api/controller/single-type.d.ts.map +1 -1
  7. package/dist/core-api/controller/single-type.js +1 -0
  8. package/dist/core-api/controller/single-type.js.map +1 -1
  9. package/dist/core-api/controller/single-type.mjs +1 -0
  10. package/dist/core-api/controller/single-type.mjs.map +1 -1
  11. package/dist/core-api/service/collection-type.d.ts +1 -7
  12. package/dist/core-api/service/collection-type.d.ts.map +1 -1
  13. package/dist/core-api/service/collection-type.js +3 -2
  14. package/dist/core-api/service/collection-type.js.map +1 -1
  15. package/dist/core-api/service/collection-type.mjs +4 -3
  16. package/dist/core-api/service/collection-type.mjs.map +1 -1
  17. package/dist/core-api/service/pagination.d.ts +4 -11
  18. package/dist/core-api/service/pagination.d.ts.map +1 -1
  19. package/dist/core-api/service/pagination.js +14 -40
  20. package/dist/core-api/service/pagination.js.map +1 -1
  21. package/dist/core-api/service/pagination.mjs +16 -42
  22. package/dist/core-api/service/pagination.mjs.map +1 -1
  23. package/dist/migrations/database/5.0.0-discard-drafts.d.ts +19 -1
  24. package/dist/migrations/database/5.0.0-discard-drafts.d.ts.map +1 -1
  25. package/dist/migrations/database/5.0.0-discard-drafts.js +1 -0
  26. package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
  27. package/dist/migrations/database/5.0.0-discard-drafts.mjs +2 -1
  28. package/dist/migrations/database/5.0.0-discard-drafts.mjs.map +1 -1
  29. package/dist/migrations/draft-publish.d.ts.map +1 -1
  30. package/dist/migrations/draft-publish.js +14 -31
  31. package/dist/migrations/draft-publish.js.map +1 -1
  32. package/dist/migrations/draft-publish.mjs +15 -32
  33. package/dist/migrations/draft-publish.mjs.map +1 -1
  34. package/dist/services/document-service/entries.d.ts +1 -1
  35. package/dist/services/document-service/entries.d.ts.map +1 -1
  36. package/dist/services/document-service/entries.js +2 -1
  37. package/dist/services/document-service/entries.js.map +1 -1
  38. package/dist/services/document-service/entries.mjs +2 -1
  39. package/dist/services/document-service/entries.mjs.map +1 -1
  40. package/dist/services/document-service/events.d.ts +25 -0
  41. package/dist/services/document-service/events.d.ts.map +1 -0
  42. package/dist/services/document-service/events.js +47 -0
  43. package/dist/services/document-service/events.js.map +1 -0
  44. package/dist/services/document-service/events.mjs +47 -0
  45. package/dist/services/document-service/events.mjs.map +1 -0
  46. package/dist/services/document-service/index.d.ts.map +1 -1
  47. package/dist/services/document-service/index.js.map +1 -1
  48. package/dist/services/document-service/index.mjs.map +1 -1
  49. package/dist/services/document-service/repository.d.ts.map +1 -1
  50. package/dist/services/document-service/repository.js +66 -38
  51. package/dist/services/document-service/repository.js.map +1 -1
  52. package/dist/services/document-service/repository.mjs +67 -39
  53. package/dist/services/document-service/repository.mjs.map +1 -1
  54. package/dist/services/document-service/transform/relations/extract/data-ids.d.ts.map +1 -1
  55. package/dist/services/document-service/transform/relations/extract/data-ids.js +3 -0
  56. package/dist/services/document-service/transform/relations/extract/data-ids.js.map +1 -1
  57. package/dist/services/document-service/transform/relations/extract/data-ids.mjs +3 -0
  58. package/dist/services/document-service/transform/relations/extract/data-ids.mjs.map +1 -1
  59. package/dist/services/document-service/transform/relations/transform/data-ids.d.ts.map +1 -1
  60. package/dist/services/document-service/transform/relations/transform/data-ids.js +3 -0
  61. package/dist/services/document-service/transform/relations/transform/data-ids.js.map +1 -1
  62. package/dist/services/document-service/transform/relations/transform/data-ids.mjs +3 -0
  63. package/dist/services/document-service/transform/relations/transform/data-ids.mjs.map +1 -1
  64. package/dist/services/document-service/transform/relations/utils/map-relation.d.ts.map +1 -1
  65. package/dist/services/document-service/transform/relations/utils/map-relation.js +7 -3
  66. package/dist/services/document-service/transform/relations/utils/map-relation.js.map +1 -1
  67. package/dist/services/document-service/transform/relations/utils/map-relation.mjs +7 -3
  68. package/dist/services/document-service/transform/relations/utils/map-relation.mjs.map +1 -1
  69. package/dist/services/event-hub.d.ts +1 -0
  70. package/dist/services/event-hub.d.ts.map +1 -1
  71. package/dist/services/event-hub.js +9 -4
  72. package/dist/services/event-hub.js.map +1 -1
  73. package/dist/services/event-hub.mjs +9 -4
  74. package/dist/services/event-hub.mjs.map +1 -1
  75. package/dist/services/webhook-store.d.ts.map +1 -1
  76. package/dist/services/webhook-store.js +8 -1
  77. package/dist/services/webhook-store.js.map +1 -1
  78. package/dist/services/webhook-store.mjs +8 -1
  79. package/dist/services/webhook-store.mjs.map +1 -1
  80. package/package.json +13 -13
@@ -1 +1 @@
1
- {"version":3,"file":"collection-type.d.ts","sourceRoot":"","sources":["../../../src/core-api/controller/collection-type.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAO,MAAM,eAAe,CAAC;AAG9D,UAAU,OAAO;IACf,WAAW,EAAE,MAAM,CAAC,oBAAoB,CAAC;CAC1C;AAED;;;GAGG;AACH,QAAA,MAAM,8BAA8B,qBAEjC,OAAO,KAAG,MAAM,eAAe,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,cAAc,CAgGxE,CAAC;AAEF,OAAO,EAAE,8BAA8B,EAAE,CAAC"}
1
+ {"version":3,"file":"collection-type.d.ts","sourceRoot":"","sources":["../../../src/core-api/controller/collection-type.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAO,MAAM,eAAe,CAAC;AAG9D,UAAU,OAAO;IACf,WAAW,EAAE,MAAM,CAAC,oBAAoB,CAAC;CAC1C;AAED;;;GAGG;AACH,QAAA,MAAM,8BAA8B,qBAEjC,OAAO,KAAG,MAAM,eAAe,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,cAAc,CAoGxE,CAAC;AAEF,OAAO,EAAE,8BAA8B,EAAE,CAAC"}
@@ -38,6 +38,7 @@ const createCollectionTypeController = ({
38
38
  if (!_.isObject(body.data)) {
39
39
  throw new strapiUtils.errors.ValidationError('Missing "data" payload in the request body');
40
40
  }
41
+ await this.validateInput(body.data, ctx);
41
42
  const sanitizedInputData = await this.sanitizeInput(body.data, ctx);
42
43
  const entity = await strapi.service(uid).create({
43
44
  ...sanitizedQuery,
@@ -58,6 +59,7 @@ const createCollectionTypeController = ({
58
59
  if (!_.isObject(body.data)) {
59
60
  throw new strapiUtils.errors.ValidationError('Missing "data" payload in the request body');
60
61
  }
62
+ await this.validateInput(body.data, ctx);
61
63
  const sanitizedInputData = await this.sanitizeInput(body.data, ctx);
62
64
  const entity = await strapi.service(uid).update(id, {
63
65
  ...sanitizedQuery,
@@ -1 +1 @@
1
- {"version":3,"file":"collection-type.js","sources":["../../../src/core-api/controller/collection-type.ts"],"sourcesContent":["import { isObject } from 'lodash/fp';\nimport { errors } from '@strapi/utils';\nimport type { Core, Struct, Utils, UID } from '@strapi/types';\nimport type Koa from 'koa';\n\ninterface Options {\n contentType: Struct.CollectionTypeSchema;\n}\n\n/**\n *\n * Returns a collection type controller to handle default core-api actions\n */\nconst createCollectionTypeController = ({\n contentType,\n}: Options): Utils.PartialWithThis<Core.CoreAPI.Controller.CollectionType> => {\n const uid = contentType.uid as UID.Service;\n\n // TODO: transform into a class\n return {\n /**\n * Retrieve records.\n */\n async find(ctx) {\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n const { results, pagination } = await strapi.service(uid).find(sanitizedQuery);\n const sanitizedResults = await this.sanitizeOutput(results, ctx);\n return this.transformResponse(sanitizedResults, { pagination });\n },\n\n /**\n * Retrieve a record\n */\n async findOne(ctx) {\n const { id } = ctx.params;\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n const entity = await strapi.service(uid).findOne(id, sanitizedQuery);\n const sanitizedEntity = await this.sanitizeOutput(entity, ctx);\n\n return this.transformResponse(sanitizedEntity);\n },\n\n /**\n * Create a record.\n */\n async create(ctx) {\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n const { body = {} as any } = ctx.request;\n\n if (!isObject(body.data)) {\n throw new errors.ValidationError('Missing \"data\" payload in the request body');\n }\n\n const sanitizedInputData = await this.sanitizeInput(body.data, ctx);\n\n const entity = await strapi.service(uid).create({\n ...sanitizedQuery,\n data: sanitizedInputData,\n });\n\n const sanitizedEntity = await this.sanitizeOutput(entity, ctx);\n\n ctx.status = 201;\n return this.transformResponse(sanitizedEntity);\n },\n\n /**\n * Update a record.\n */\n async update(ctx: Koa.Context) {\n const { id } = ctx.params;\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n const { body = {} as any } = ctx.request;\n\n if (!isObject(body.data)) {\n throw new errors.ValidationError('Missing \"data\" payload in the request body');\n }\n\n const sanitizedInputData = await this.sanitizeInput(body.data, ctx);\n\n const entity = await strapi.service(uid).update(id, {\n ...sanitizedQuery,\n data: sanitizedInputData,\n });\n\n const sanitizedEntity = await this.sanitizeOutput(entity, ctx);\n\n return this.transformResponse(sanitizedEntity);\n },\n\n /**\n * Destroy a record.\n */\n async delete(ctx) {\n const { id } = ctx.params;\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n await strapi.service(uid).delete(id, sanitizedQuery);\n\n ctx.status = 204;\n },\n };\n};\n\nexport { createCollectionTypeController };\n"],"names":["isObject","errors"],"mappings":";;;;AAaA,MAAM,iCAAiC,CAAC;AAAA,EACtC;AACF,MAA8E;AAC5E,QAAM,MAAM,YAAY;AAGjB,SAAA;AAAA;AAAA;AAAA;AAAA,IAIL,MAAM,KAAK,KAAK;AACR,YAAA,KAAK,cAAc,GAAG;AAC5B,YAAM,iBAAiB,MAAM,KAAK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AAM,KAAK,cAAc,GAAG;AAEnD,YAAM,EAAE,OAAO,CAAA,MAAc,IAAI;AAEjC,UAAI,CAACD,EAAA,SAAS,KAAK,IAAI,GAAG;AAClB,cAAA,IAAIC,YAAO,OAAA,gBAAgB,4CAA4C;AAAA,MAC/E;AAEA,YAAM,qBAAqB,MAAM,KAAK,cAAc,KAAK,MAAM,GAAG;AAElE,YAAM,SAAS,MAAM,OAAO,QAAQ,GAAG,EAAE,OAAO,IAAI;AAAA,QAClD,GAAG;AAAA,QACH,MAAM;AAAA,MAAA,CACP;AAED,YAAM,kBAAkB,MAAM,KAAK,eAAe,QAAQ,GAAG;AAEtD,aAAA,KAAK,kBAAkB,eAAe;AAAA,IAC/C;AAAA;AAAA;AAAA;AAAA,IAKA,MAAM,OAAO,KAAK;AACV,YAAA,EAAE,GAAG,IAAI,IAAI;AACb,YAAA,KAAK,cAAc,GAAG;AAC5B,YAAM,iBAAiB,MAAM,KAAK,cAAc,GAAG;AAEnD,YAAM,OAAO,QAAQ,GAAG,EAAE,OAAO,IAAI,cAAc;AAEnD,UAAI,SAAS;AAAA,IACf;AAAA,EAAA;AAEJ;;"}
1
+ {"version":3,"file":"collection-type.js","sources":["../../../src/core-api/controller/collection-type.ts"],"sourcesContent":["import { isObject } from 'lodash/fp';\nimport { errors } from '@strapi/utils';\nimport type { Core, Struct, Utils, UID } from '@strapi/types';\nimport type Koa from 'koa';\n\ninterface Options {\n contentType: Struct.CollectionTypeSchema;\n}\n\n/**\n *\n * Returns a collection type controller to handle default core-api actions\n */\nconst createCollectionTypeController = ({\n contentType,\n}: Options): Utils.PartialWithThis<Core.CoreAPI.Controller.CollectionType> => {\n const uid = contentType.uid as UID.Service;\n\n // TODO: transform into a class\n return {\n /**\n * Retrieve records.\n */\n async find(ctx) {\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n const { results, pagination } = await strapi.service(uid).find(sanitizedQuery);\n const sanitizedResults = await this.sanitizeOutput(results, ctx);\n return this.transformResponse(sanitizedResults, { pagination });\n },\n\n /**\n * Retrieve a record\n */\n async findOne(ctx) {\n const { id } = ctx.params;\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n const entity = await strapi.service(uid).findOne(id, sanitizedQuery);\n const sanitizedEntity = await this.sanitizeOutput(entity, ctx);\n\n return this.transformResponse(sanitizedEntity);\n },\n\n /**\n * Create a record.\n */\n async create(ctx) {\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n const { body = {} as any } = ctx.request;\n\n if (!isObject(body.data)) {\n throw new errors.ValidationError('Missing \"data\" payload in the request body');\n }\n\n await this.validateInput(body.data, ctx);\n\n const sanitizedInputData = await this.sanitizeInput(body.data, ctx);\n\n const entity = await strapi.service(uid).create({\n ...sanitizedQuery,\n data: sanitizedInputData,\n });\n\n const sanitizedEntity = await this.sanitizeOutput(entity, ctx);\n\n ctx.status = 201;\n return this.transformResponse(sanitizedEntity);\n },\n\n /**\n * Update a record.\n */\n async update(ctx: Koa.Context) {\n const { id } = ctx.params;\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n const { body = {} as any } = ctx.request;\n\n if (!isObject(body.data)) {\n throw new errors.ValidationError('Missing \"data\" payload in the request body');\n }\n\n await this.validateInput(body.data, ctx);\n\n const sanitizedInputData = await this.sanitizeInput(body.data, ctx);\n\n const entity = await strapi.service(uid).update(id, {\n ...sanitizedQuery,\n data: sanitizedInputData,\n });\n\n const sanitizedEntity = await this.sanitizeOutput(entity, ctx);\n\n return this.transformResponse(sanitizedEntity);\n },\n\n /**\n * Destroy a record.\n */\n async delete(ctx) {\n const { id } = ctx.params;\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n await strapi.service(uid).delete(id, sanitizedQuery);\n\n ctx.status = 204;\n },\n };\n};\n\nexport { createCollectionTypeController };\n"],"names":["isObject","errors"],"mappings":";;;;AAaA,MAAM,i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M,KAAK,eAAe,QAAQ,GAAG;AAE7D,UAAI,SAAS;AACN,aAAA,KAAK,kBAAkB,eAAe;AAAA,IAC/C;AAAA;AAAA;AAAA;AAAA,IAKA,MAAM,OAAO,KAAkB;AACvB,YAAA,EAAE,GAAG,IAAI,IAAI;AACb,YAAA,KAAK,cAAc,GAAG;AAC5B,YAAM,iBAAiB,MAAM,KAAK,cAAc,GAAG;AAEnD,YAAM,EAAE,OAAO,CAAA,MAAc,IAAI;AAEjC,UAAI,CAACD,EAAA,SAAS,KAAK,IAAI,GAAG;AAClB,cAAA,IAAIC,YAAO,OAAA,gBAAgB,4CAA4C;AAAA,MAC/E;AAEA,YAAM,KAAK,cAAc,KAAK,MAAM,GAAG;AAEvC,YAAM,qBAAqB,MAAM,KAAK,cAAc,KAAK,MAAM,GAAG;AAElE,YAAM,SAAS,MAAM,OAAO,QAAQ,GAAG,EAAE,OAAO,IAAI;AAAA,QAClD,GAAG;AAAA,QACH,MAAM;AAAA,MAAA,CACP;AAED,YAAM,kBAAkB,MAAM,KAAK,eAAe,QAAQ,GAAG;AAEtD,aAAA,KAAK,kBAAkB,eAAe;AAAA,IAC/C;AAAA;AAAA;AAAA;AAAA,IAKA,MAAM,OAAO,KAAK;AACV,YAAA,EAAE,GAAG,IAAI,IAAI;AACb,YAAA,KAAK,cAAc,GAAG;AAC5B,YAAM,iBAAiB,MAAM,KAAK,cAAc,GAAG;AAEnD,YAAM,OAAO,QAAQ,GAAG,EAAE,OAAO,IAAI,cAAc;AAEnD,UAAI,SAAS;AAAA,IACf;AAAA,EAAA;AAEJ;;"}
@@ -36,6 +36,7 @@ const createCollectionTypeController = ({
36
36
  if (!isObject(body.data)) {
37
37
  throw new errors.ValidationError('Missing "data" payload in the request body');
38
38
  }
39
+ await this.validateInput(body.data, ctx);
39
40
  const sanitizedInputData = await this.sanitizeInput(body.data, ctx);
40
41
  const entity = await strapi.service(uid).create({
41
42
  ...sanitizedQuery,
@@ -56,6 +57,7 @@ const createCollectionTypeController = ({
56
57
  if (!isObject(body.data)) {
57
58
  throw new errors.ValidationError('Missing "data" payload in the request body');
58
59
  }
60
+ await this.validateInput(body.data, ctx);
59
61
  const sanitizedInputData = await this.sanitizeInput(body.data, ctx);
60
62
  const entity = await strapi.service(uid).update(id, {
61
63
  ...sanitizedQuery,
@@ -1 +1 @@
1
- {"version":3,"file":"collection-type.mjs","sources":["../../../src/core-api/controller/collection-type.ts"],"sourcesContent":["import { isObject } from 'lodash/fp';\nimport { errors } from '@strapi/utils';\nimport type { Core, Struct, Utils, UID } from '@strapi/types';\nimport type Koa from 'koa';\n\ninterface Options {\n contentType: Struct.CollectionTypeSchema;\n}\n\n/**\n *\n * Returns a collection type controller to handle default core-api actions\n */\nconst createCollectionTypeController = ({\n contentType,\n}: Options): Utils.PartialWithThis<Core.CoreAPI.Controller.CollectionType> => {\n const uid = contentType.uid as UID.Service;\n\n // TODO: transform into a class\n return {\n /**\n * Retrieve records.\n */\n async find(ctx) {\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n const { results, pagination } = await strapi.service(uid).find(sanitizedQuery);\n const sanitizedResults = await this.sanitizeOutput(results, ctx);\n return this.transformResponse(sanitizedResults, { pagination });\n },\n\n /**\n * Retrieve a record\n */\n async findOne(ctx) {\n const { id } = ctx.params;\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n const entity = await strapi.service(uid).findOne(id, sanitizedQuery);\n const sanitizedEntity = await this.sanitizeOutput(entity, ctx);\n\n return this.transformResponse(sanitizedEntity);\n },\n\n /**\n * Create a record.\n */\n async create(ctx) {\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n const { body = {} as any } = ctx.request;\n\n if (!isObject(body.data)) {\n throw new errors.ValidationError('Missing \"data\" payload in the request body');\n }\n\n const sanitizedInputData = await this.sanitizeInput(body.data, ctx);\n\n const entity = await strapi.service(uid).create({\n ...sanitizedQuery,\n data: sanitizedInputData,\n });\n\n const sanitizedEntity = await this.sanitizeOutput(entity, ctx);\n\n ctx.status = 201;\n return this.transformResponse(sanitizedEntity);\n },\n\n /**\n * Update a record.\n */\n async update(ctx: Koa.Context) {\n const { id } = ctx.params;\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n const { body = {} as any } = ctx.request;\n\n if (!isObject(body.data)) {\n throw new errors.ValidationError('Missing \"data\" payload in the request body');\n }\n\n const sanitizedInputData = await this.sanitizeInput(body.data, ctx);\n\n const entity = await strapi.service(uid).update(id, {\n ...sanitizedQuery,\n data: sanitizedInputData,\n });\n\n const sanitizedEntity = await this.sanitizeOutput(entity, ctx);\n\n return this.transformResponse(sanitizedEntity);\n },\n\n /**\n * Destroy a record.\n */\n async delete(ctx) {\n const { id } = ctx.params;\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n await strapi.service(uid).delete(id, sanitizedQuery);\n\n ctx.status = 204;\n },\n };\n};\n\nexport { createCollectionTypeController };\n"],"names":[],"mappings":";;AAaA,MAAM,iCAAiC,CAAC;AAAA,EACtC;AACF,MAA8E;AAC5E,QAAM,MAAM,YAAY;AAGjB,SAAA;AAAA;AAAA;AAAA;AAAA,IAIL,MAAM,KAAK,KAAK;AACR,YAAA,KAAK,cAAc,GAAG;AAC5B,YAAM,iBAAiB,MAAM,KAAK,cAAc,GAAG;AAE7C,YAAA,EAAE,SAAS,WAAA,IAAe,MAAM,OAAO,QAAQ,GAAG,EAAE,KAAK,cAAc;AAC7E,YAAM,mBAAmB,MAAM,KAAK,eAAe,SAAS,GAAG;AAC/D,aAAO,KAAK,kBAAkB,kBAAkB,EAAE,WAAY,CAAA;AAAA,IAChE;AAAA;AAAA;AAAA;AAAA,IAKA,MAAM,QAAQ,KAAK;AACX,YAAA,EAAE,GAAG,IAAI,IAAI;AACb,YAAA,KAAK,cAAc,GAAG;AAC5B,YAAM,iBAAiB,MAAM,KAAK,cAAc,GAAG;AAE7C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,aAAA,KAAK,kBAAkB,eAAe;AAAA,IAC/C;AAAA;AAAA;AAAA;AAAA,IAKA,MAAM,OAAO,KAAK;AACV,YAAA,EAAE,GAAG,IAAI,IAAI;AACb,YAAA,KAAK,cAAc,GAAG;AAC5B,YAAM,iBAAiB,MAAM,KAAK,cAAc,GAAG;AAEnD,YAAM,OAAO,QAAQ,GAAG,EAAE,OAAO,IAAI,cAAc;AAEnD,UAAI,SAAS;AAAA,IACf;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"collection-type.mjs","sources":["../../../src/core-api/controller/collection-type.ts"],"sourcesContent":["import { isObject } from 'lodash/fp';\nimport { errors } from '@strapi/utils';\nimport type { Core, Struct, Utils, UID } from '@strapi/types';\nimport type Koa from 'koa';\n\ninterface Options {\n contentType: Struct.CollectionTypeSchema;\n}\n\n/**\n *\n * Returns a collection type controller to handle default core-api actions\n */\nconst createCollectionTypeController = ({\n contentType,\n}: Options): Utils.PartialWithThis<Core.CoreAPI.Controller.CollectionType> => {\n const uid = contentType.uid as UID.Service;\n\n // TODO: transform into a class\n return {\n /**\n * Retrieve records.\n */\n async find(ctx) {\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n const { results, pagination } = await strapi.service(uid).find(sanitizedQuery);\n const sanitizedResults = await this.sanitizeOutput(results, ctx);\n return this.transformResponse(sanitizedResults, { pagination });\n },\n\n /**\n * Retrieve a record\n */\n async findOne(ctx) {\n const { id } = ctx.params;\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n const entity = await strapi.service(uid).findOne(id, sanitizedQuery);\n const sanitizedEntity = await this.sanitizeOutput(entity, ctx);\n\n return this.transformResponse(sanitizedEntity);\n },\n\n /**\n * Create a record.\n */\n async create(ctx) {\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n const { body = {} as any } = ctx.request;\n\n if (!isObject(body.data)) {\n throw new errors.ValidationError('Missing \"data\" payload in the request body');\n }\n\n await this.validateInput(body.data, ctx);\n\n const sanitizedInputData = await this.sanitizeInput(body.data, ctx);\n\n const entity = await strapi.service(uid).create({\n ...sanitizedQuery,\n data: sanitizedInputData,\n });\n\n const sanitizedEntity = await this.sanitizeOutput(entity, ctx);\n\n ctx.status = 201;\n return this.transformResponse(sanitizedEntity);\n },\n\n /**\n * Update a record.\n */\n async update(ctx: Koa.Context) {\n const { id } = ctx.params;\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n const { body = {} as any } = ctx.request;\n\n if (!isObject(body.data)) {\n throw new errors.ValidationError('Missing \"data\" payload in the request body');\n }\n\n await this.validateInput(body.data, ctx);\n\n const sanitizedInputData = await this.sanitizeInput(body.data, ctx);\n\n const entity = await strapi.service(uid).update(id, {\n ...sanitizedQuery,\n data: sanitizedInputData,\n });\n\n const sanitizedEntity = await this.sanitizeOutput(entity, ctx);\n\n return this.transformResponse(sanitizedEntity);\n },\n\n /**\n * Destroy a record.\n */\n async delete(ctx) {\n const { id } = ctx.params;\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n await strapi.service(uid).delete(id, sanitizedQuery);\n\n ctx.status = 204;\n },\n };\n};\n\nexport { createCollectionTypeController };\n"],"names":[],"mappings":";;AAaA,MAAM,iCAAiC,CAAC;AAAA,EACtC;AACF,MAA8E;AAC5E,QAAM,MAAM,YAAY;AAGjB,SAAA;AAAA;AAAA;AAAA;AAAA,IAIL,MAAM,KAAK,KAAK;AACR,YAAA,KAAK,cAAc,GAAG;AAC5B,YAAM,iBAAiB,MAAM,KAAK,cAAc,GAAG;AAE7C,YAAA,EAAE,SAAS,WAAA,IAAe,MAAM,OAAO,QAAQ,GAAG,EAAE,KAAK,cAAc;AAC7E,YAAM,mBAAmB,MAAM,KAAK,eAAe,SAAS,GAAG;AAC/D,aAAO,KAAK,kBAAkB,kBAAkB,EAAE,WAAY,CAAA;AAAA,IAChE;AAAA;AAAA;AAA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M,GAAG;AAEvC,YAAM,qBAAqB,MAAM,KAAK,cAAc,KAAK,MAAM,GAAG;AAElE,YAAM,SAAS,MAAM,OAAO,QAAQ,GAAG,EAAE,OAAO,IAAI;AAAA,QAClD,GAAG;AAAA,QACH,MAAM;AAAA,MAAA,CACP;AAED,YAAM,kBAAkB,MAAM,KAAK,eAAe,QAAQ,GAAG;AAEtD,aAAA,KAAK,kBAAkB,eAAe;AAAA,IAC/C;AAAA;AAAA;AAAA;AAAA,IAKA,MAAM,OAAO,KAAK;AACV,YAAA,EAAE,GAAG,IAAI,IAAI;AACb,YAAA,KAAK,cAAc,GAAG;AAC5B,YAAM,iBAAiB,MAAM,KAAK,cAAc,GAAG;AAEnD,YAAM,OAAO,QAAQ,GAAG,EAAE,OAAO,IAAI,cAAc;AAEnD,UAAI,SAAS;AAAA,IACf;AAAA,EAAA;AAEJ;"}
@@ -1 +1 @@
1
- {"version":3,"file":"single-type.d.ts","sourceRoot":"","sources":["../../../src/core-api/controller/single-type.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAO,MAAM,eAAe,CAAC;AAE9D,UAAU,OAAO;IACf,WAAW,EAAE,MAAM,CAAC,gBAAgB,CAAC;CACtC;AAED;;GAEG;AACH,QAAA,MAAM,0BAA0B,qBAE7B,OAAO,KAAG,MAAM,eAAe,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,UAAU,CAkDpE,CAAC;AAEF,OAAO,EAAE,0BAA0B,EAAE,CAAC"}
1
+ {"version":3,"file":"single-type.d.ts","sourceRoot":"","sources":["../../../src/core-api/controller/single-type.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAO,MAAM,eAAe,CAAC;AAE9D,UAAU,OAAO;IACf,WAAW,EAAE,MAAM,CAAC,gBAAgB,CAAC;CACtC;AAED;;GAEG;AACH,QAAA,MAAM,0BAA0B,qBAE7B,OAAO,KAAG,MAAM,eAAe,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,UAAU,CAoDpE,CAAC;AAEF,OAAO,EAAE,0BAA0B,EAAE,CAAC"}
@@ -26,6 +26,7 @@ const createSingleTypeController = ({
26
26
  if (!_.isObject(body.data)) {
27
27
  throw new strapiUtils.errors.ValidationError('Missing "data" payload in the request body');
28
28
  }
29
+ await this.validateInput(body.data, ctx);
29
30
  const sanitizedInputData = await this.sanitizeInput(body.data, ctx);
30
31
  const entity = await strapi.service(uid).createOrUpdate({
31
32
  ...query,
@@ -1 +1 @@
1
- {"version":3,"file":"single-type.js","sources":["../../../src/core-api/controller/single-type.ts"],"sourcesContent":["import { isObject } from 'lodash/fp';\nimport { errors } from '@strapi/utils';\nimport type { Struct, Core, Utils, UID } from '@strapi/types';\n\ninterface Options {\n contentType: Struct.SingleTypeSchema;\n}\n\n/**\n * Returns a single type controller to handle default core-api actions\n */\nconst createSingleTypeController = ({\n contentType,\n}: Options): Utils.PartialWithThis<Core.CoreAPI.Controller.SingleType> => {\n const uid = contentType.uid as UID.Service;\n\n // TODO: transform into a class\n return {\n /**\n * Retrieve single type content\n *\n */\n async find(ctx) {\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n const entity = await strapi.service(uid).find(sanitizedQuery);\n\n const sanitizedEntity = await this.sanitizeOutput(entity, ctx);\n\n return this.transformResponse(sanitizedEntity);\n },\n\n /**\n * create or update single type content.\n */\n async update(ctx) {\n const { query, body = {} as any } = ctx.request;\n\n if (!isObject(body.data)) {\n throw new errors.ValidationError('Missing \"data\" payload in the request body');\n }\n\n const sanitizedInputData = await this.sanitizeInput(body.data, ctx);\n\n const entity = await strapi.service(uid).createOrUpdate({\n ...query,\n data: sanitizedInputData,\n });\n\n const sanitizedEntity = await this.sanitizeOutput(entity, ctx);\n\n return this.transformResponse(sanitizedEntity);\n },\n\n async delete(ctx) {\n const { query } = ctx;\n\n await strapi.service(uid).delete(query);\n\n ctx.status = 204;\n },\n };\n};\n\nexport { createSingleTypeController };\n"],"names":["isObject","errors"],"mappings":";;;;AAWA,MAAM,6BAA6B,CAAC;AAAA,EAClC;AACF,MAA0E;AACxE,QAAM,MAAM,YAAY;AAGjB,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAKL,MAAM,KAAK,KAAK;AACR,YAAA,KAAK,cAAc,GAAG;AAC5B,YAAM,iBAAiB,MAAM,KAAK,cAAc,GAAG;AAEnD,YAAM,SAAS,MAAM,OAAO,QAAQ,GAAG,EAAE,KAAK,cAAc;AAE5D,YAAM,kBAAkB,MAAM,KAAK,eAAe,QAAQ,GAAG;AAEtD,aAAA,KAAK,kBAAkB,eAAe;AAAA,IAC/C;AAAA;AAAA;AAAA;AAAA,IAKA,MAAM,OAAO,KAAK;AAChB,YAAM,EAAE,OAAO,OAAO,CAAC,EAAA,IAAa,IAAI;AAExC,UAAI,CAACA,EAAA,SAAS,KAAK,IAAI,GAAG;AAClB,cAAA,IAAIC,YAAO,OAAA,gBAAgB,4CAA4C;AAAA,MAC/E;AAEA,YAAM,qBAAqB,MAAM,KAAK,cAAc,KAAK,MAAM,GAAG;AAElE,YAAM,SAAS,MAAM,OAAO,QAAQ,GAAG,EAAE,eAAe;AAAA,QACtD,GAAG;AAAA,QACH,MAAM;AAAA,MAAA,CACP;AAED,YAAM,kBAAkB,MAAM,KAAK,eAAe,QAAQ,GAAG;AAEtD,aAAA,KAAK,kBAAkB,eAAe;AAAA,IAC/C;AAAA,IAEA,MAAM,OAAO,KAAK;AACV,YAAA,EAAE,MAAU,IAAA;AAElB,YAAM,OAAO,QAAQ,GAAG,EAAE,OAAO,KAAK;AAEtC,UAAI,SAAS;AAAA,IACf;AAAA,EAAA;AAEJ;;"}
1
+ {"version":3,"file":"single-type.js","sources":["../../../src/core-api/controller/single-type.ts"],"sourcesContent":["import { isObject } from 'lodash/fp';\nimport { errors } from '@strapi/utils';\nimport type { Struct, Core, Utils, UID } from '@strapi/types';\n\ninterface Options {\n contentType: Struct.SingleTypeSchema;\n}\n\n/**\n * Returns a single type controller to handle default core-api actions\n */\nconst createSingleTypeController = ({\n contentType,\n}: Options): Utils.PartialWithThis<Core.CoreAPI.Controller.SingleType> => {\n const uid = contentType.uid as UID.Service;\n\n // TODO: transform into a class\n return {\n /**\n * Retrieve single type content\n *\n */\n async find(ctx) {\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n const entity = await strapi.service(uid).find(sanitizedQuery);\n\n const sanitizedEntity = await this.sanitizeOutput(entity, ctx);\n\n return this.transformResponse(sanitizedEntity);\n },\n\n /**\n * create or update single type content.\n */\n async update(ctx) {\n const { query, body = {} as any } = ctx.request;\n\n if (!isObject(body.data)) {\n throw new errors.ValidationError('Missing \"data\" payload in the request body');\n }\n\n await this.validateInput(body.data, ctx);\n\n const sanitizedInputData = await this.sanitizeInput(body.data, ctx);\n\n const entity = await strapi.service(uid).createOrUpdate({\n ...query,\n data: sanitizedInputData,\n });\n\n const sanitizedEntity = await this.sanitizeOutput(entity, ctx);\n\n return this.transformResponse(sanitizedEntity);\n },\n\n async delete(ctx) {\n const { query } = ctx;\n\n await strapi.service(uid).delete(query);\n\n ctx.status = 204;\n },\n };\n};\n\nexport { createSingleTypeController };\n"],"names":["isObject","errors"],"mappings":";;;;AAWA,MAAM,6BAA6B,CAAC;AAAA,EAClC;AACF,MAA0E;AACxE,QAAM,MAAM,YAAY;AAGjB,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAKL,MAAM,KAAK,KAAK;AACR,YAAA,KAAK,cAAc,GAAG;AAC5B,YAAM,iBAAiB,MAAM,KAAK,cAAc,GAAG;AAEnD,YAAM,SAAS,MAAM,OAAO,QAAQ,GAAG,EAAE,KAAK,cAAc;AAE5D,YAAM,kBAAkB,MAAM,KAAK,eAAe,QAAQ,GAAG;AAEtD,aAAA,KAAK,kBAAkB,eAAe;AAAA,IAC/C;AAAA;AAAA;AAAA;AAAA,IAKA,MAAM,OAAO,KAAK;AAChB,YAAM,EAAE,OAAO,OAAO,CAAC,EAAA,IAAa,IAAI;AAExC,UAAI,CAACA,EAAA,SAAS,KAAK,IAAI,GAAG;AAClB,cAAA,IAAIC,YAAO,OAAA,gBAAgB,4CAA4C;AAAA,MAC/E;AAEA,YAAM,KAAK,cAAc,KAAK,MAAM,GAAG;AAEvC,YAAM,qBAAqB,MAAM,KAAK,cAAc,KAAK,MAAM,GAAG;AAElE,YAAM,SAAS,MAAM,OAAO,QAAQ,GAAG,EAAE,eAAe;AAAA,QACtD,GAAG;AAAA,QACH,MAAM;AAAA,MAAA,CACP;AAED,YAAM,kBAAkB,MAAM,KAAK,eAAe,QAAQ,GAAG;AAEtD,aAAA,KAAK,kBAAkB,eAAe;AAAA,IAC/C;AAAA,IAEA,MAAM,OAAO,KAAK;AACV,YAAA,EAAE,MAAU,IAAA;AAElB,YAAM,OAAO,QAAQ,GAAG,EAAE,OAAO,KAAK;AAEtC,UAAI,SAAS;AAAA,IACf;AAAA,EAAA;AAEJ;;"}
@@ -24,6 +24,7 @@ const createSingleTypeController = ({
24
24
  if (!isObject(body.data)) {
25
25
  throw new errors.ValidationError('Missing "data" payload in the request body');
26
26
  }
27
+ await this.validateInput(body.data, ctx);
27
28
  const sanitizedInputData = await this.sanitizeInput(body.data, ctx);
28
29
  const entity = await strapi.service(uid).createOrUpdate({
29
30
  ...query,
@@ -1 +1 @@
1
- {"version":3,"file":"single-type.mjs","sources":["../../../src/core-api/controller/single-type.ts"],"sourcesContent":["import { isObject } from 'lodash/fp';\nimport { errors } from '@strapi/utils';\nimport type { Struct, Core, Utils, UID } from '@strapi/types';\n\ninterface Options {\n contentType: Struct.SingleTypeSchema;\n}\n\n/**\n * Returns a single type controller to handle default core-api actions\n */\nconst createSingleTypeController = ({\n contentType,\n}: Options): Utils.PartialWithThis<Core.CoreAPI.Controller.SingleType> => {\n const uid = contentType.uid as UID.Service;\n\n // TODO: transform into a class\n return {\n /**\n * Retrieve single type content\n *\n */\n async find(ctx) {\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n const entity = await strapi.service(uid).find(sanitizedQuery);\n\n const sanitizedEntity = await this.sanitizeOutput(entity, ctx);\n\n return this.transformResponse(sanitizedEntity);\n },\n\n /**\n * create or update single type content.\n */\n async update(ctx) {\n const { query, body = {} as any } = ctx.request;\n\n if (!isObject(body.data)) {\n throw new errors.ValidationError('Missing \"data\" payload in the request body');\n }\n\n const sanitizedInputData = await this.sanitizeInput(body.data, ctx);\n\n const entity = await strapi.service(uid).createOrUpdate({\n ...query,\n data: sanitizedInputData,\n });\n\n const sanitizedEntity = await this.sanitizeOutput(entity, ctx);\n\n return this.transformResponse(sanitizedEntity);\n },\n\n async delete(ctx) {\n const { query } = ctx;\n\n await strapi.service(uid).delete(query);\n\n ctx.status = 204;\n },\n };\n};\n\nexport { createSingleTypeController };\n"],"names":[],"mappings":";;AAWA,MAAM,6BAA6B,CAAC;AAAA,EAClC;AACF,MAA0E;AACxE,QAAM,MAAM,YAAY;AAGjB,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAKL,MAAM,KAAK,KAAK;AACR,YAAA,KAAK,cAAc,GAAG;AAC5B,YAAM,iBAAiB,MAAM,KAAK,cAAc,GAAG;AAEnD,YAAM,SAAS,MAAM,OAAO,QAAQ,GAAG,EAAE,KAAK,cAAc;AAE5D,YAAM,kBAAkB,MAAM,KAAK,eAAe,QAAQ,GAAG;AAEtD,aAAA,KAAK,kBAAkB,eAAe;AAAA,IAC/C;AAAA;AAAA;AAAA;AAAA,IAKA,MAAM,OAAO,KAAK;AAChB,YAAM,EAAE,OAAO,OAAO,CAAC,EAAA,IAAa,IAAI;AAExC,UAAI,CAAC,SAAS,KAAK,IAAI,GAAG;AAClB,cAAA,IAAI,OAAO,gBAAgB,4CAA4C;AAAA,MAC/E;AAEA,YAAM,qBAAqB,MAAM,KAAK,cAAc,KAAK,MAAM,GAAG;AAElE,YAAM,SAAS,MAAM,OAAO,QAAQ,GAAG,EAAE,eAAe;AAAA,QACtD,GAAG;AAAA,QACH,MAAM;AAAA,MAAA,CACP;AAED,YAAM,kBAAkB,MAAM,KAAK,eAAe,QAAQ,GAAG;AAEtD,aAAA,KAAK,kBAAkB,eAAe;AAAA,IAC/C;AAAA,IAEA,MAAM,OAAO,KAAK;AACV,YAAA,EAAE,MAAU,IAAA;AAElB,YAAM,OAAO,QAAQ,GAAG,EAAE,OAAO,KAAK;AAEtC,UAAI,SAAS;AAAA,IACf;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"single-type.mjs","sources":["../../../src/core-api/controller/single-type.ts"],"sourcesContent":["import { isObject } from 'lodash/fp';\nimport { errors } from '@strapi/utils';\nimport type { Struct, Core, Utils, UID } from '@strapi/types';\n\ninterface Options {\n contentType: Struct.SingleTypeSchema;\n}\n\n/**\n * Returns a single type controller to handle default core-api actions\n */\nconst createSingleTypeController = ({\n contentType,\n}: Options): Utils.PartialWithThis<Core.CoreAPI.Controller.SingleType> => {\n const uid = contentType.uid as UID.Service;\n\n // TODO: transform into a class\n return {\n /**\n * Retrieve single type content\n *\n */\n async find(ctx) {\n await this.validateQuery(ctx);\n const sanitizedQuery = await this.sanitizeQuery(ctx);\n\n const entity = await strapi.service(uid).find(sanitizedQuery);\n\n const sanitizedEntity = await this.sanitizeOutput(entity, ctx);\n\n return this.transformResponse(sanitizedEntity);\n },\n\n /**\n * create or update single type content.\n */\n async update(ctx) {\n const { query, body = {} as any } = ctx.request;\n\n if (!isObject(body.data)) {\n throw new errors.ValidationError('Missing \"data\" payload in the request body');\n }\n\n await this.validateInput(body.data, ctx);\n\n const sanitizedInputData = await this.sanitizeInput(body.data, ctx);\n\n const entity = await strapi.service(uid).createOrUpdate({\n ...query,\n data: sanitizedInputData,\n });\n\n const sanitizedEntity = await this.sanitizeOutput(entity, ctx);\n\n return this.transformResponse(sanitizedEntity);\n },\n\n async delete(ctx) {\n const { query } = ctx;\n\n await strapi.service(uid).delete(query);\n\n ctx.status = 204;\n },\n };\n};\n\nexport { createSingleTypeController };\n"],"names":[],"mappings":";;AAWA,MAAM,6BAA6B,CAAC;AAAA,EAClC;AACF,MAA0E;AACxE,QAAM,MAAM,YAAY;AAGjB,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAKL,MAAM,KAAK,KAAK;AACR,YAAA,KAAK,cAAc,GAAG;AAC5B,YAAM,iBAAiB,MAAM,KAAK,cAAc,GAAG;AAEnD,YAAM,SAAS,MAAM,OAAO,QAAQ,GAAG,EAAE,KAAK,cAAc;AAE5D,YAAM,kBAAkB,MAAM,KAAK,eAAe,QAAQ,GAAG;AAEtD,aAAA,KAAK,kBAAkB,eAAe;AAAA,IAC/C;AAAA;AAAA;AAAA;AAAA,IAKA,MAAM,OAAO,KAAK;AAChB,YAAM,EAAE,OAAO,OAAO,CAAC,EAAA,IAAa,IAAI;AAExC,UAAI,CAAC,SAAS,KAAK,IAAI,GAAG;AAClB,cAAA,IAAI,OAAO,gBAAgB,4CAA4C;AAAA,MAC/E;AAEA,YAAM,KAAK,cAAc,KAAK,MAAM,GAAG;AAEvC,YAAM,qBAAqB,MAAM,KAAK,cAAc,KAAK,MAAM,GAAG;AAElE,YAAM,SAAS,MAAM,OAAO,QAAQ,GAAG,EAAE,eAAe;AAAA,QACtD,GAAG;AAAA,QACH,MAAM;AAAA,MAAA,CACP;AAED,YAAM,kBAAkB,MAAM,KAAK,eAAe,QAAQ,GAAG;AAEtD,aAAA,KAAK,kBAAkB,eAAe;AAAA,IAC/C;AAAA,IAEA,MAAM,OAAO,KAAK;AACV,YAAA,EAAE,MAAU,IAAA;AAElB,YAAM,OAAO,QAAQ,GAAG,EAAE,OAAO,KAAK;AAEtC,UAAI,SAAS;AAAA,IACf;AAAA,EAAA;AAEJ;"}
@@ -5,13 +5,7 @@ export declare class CollectionTypeService extends CoreService implements Core.C
5
5
  constructor(contentType: Struct.CollectionTypeSchema);
6
6
  find(params?: {}): Promise<{
7
7
  results: Modules.Documents.AnyDocument[];
8
- pagination: {
9
- page: number;
10
- pageSize: number;
11
- } | {
12
- start: number;
13
- limit: number;
14
- };
8
+ pagination: import("@strapi/utils/dist/pagination").PagePatinationInformation | import("@strapi/utils/dist/pagination").OffsetPaginationInformation;
15
9
  }>;
16
10
  findOne(documentId: Modules.Documents.ID, params?: {}): import("@strapi/types/dist/modules/documents/result/document-engine").FindOne<import("@strapi/types/dist/uid").ContentType, import("@strapi/types/dist/modules/documents/params/document-engine").FindOne<import("@strapi/types/dist/uid").ContentType>>;
17
11
  create(params?: {
@@ -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;;;CAU3D;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;AAS3D,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;;;;IAgCtB,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"}
@@ -12,6 +12,7 @@ class CollectionTypeService extends coreService.CoreService {
12
12
  const { uid } = this.contentType;
13
13
  const fetchParams = this.getFetchParams(params);
14
14
  const paginationInfo = pagination.getPaginationInfo(fetchParams);
15
+ const isPaged = pagination.isPagedPagination(fetchParams.pagination);
15
16
  const results = await strapi.documents(uid).findMany({
16
17
  ...fetchParams,
17
18
  ...paginationInfo
@@ -23,12 +24,12 @@ class CollectionTypeService extends coreService.CoreService {
23
24
  }
24
25
  return {
25
26
  results,
26
- pagination: pagination.transformPaginationResponse(paginationInfo, count)
27
+ pagination: pagination.transformPaginationResponse(paginationInfo, count, isPaged)
27
28
  };
28
29
  }
29
30
  return {
30
31
  results,
31
- pagination: paginationInfo
32
+ pagination: pagination.transformPaginationResponse(paginationInfo, void 0, isPaged)
32
33
  };
33
34
  }
34
35
  findOne(documentId, params = {}) {
@@ -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 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;;;"}
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 {\n getPaginationInfo,\n shouldCount,\n isPagedPagination,\n transformPaginationResponse,\n} 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 const isPaged = isPagedPagination(fetchParams.pagination);\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, isPaged),\n };\n }\n\n return {\n results,\n pagination: transformPaginationResponse(paginationInfo, undefined, isPaged),\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","isPagedPagination","shouldCount","transformPaginationResponse"],"mappings":";;;;AAWO,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;AAC9C,UAAA,UAAUC,WAAAA,kBAAkB,YAAY,UAAU;AAExD,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,O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+ import { getPaginationInfo, isPagedPagination, shouldCount, transformPaginationResponse } from "./pagination.mjs";
2
2
  import { CoreService } from "./core-service.mjs";
3
3
  class CollectionTypeService extends CoreService {
4
4
  contentType;
@@ -10,6 +10,7 @@ class CollectionTypeService extends CoreService {
10
10
  const { uid } = this.contentType;
11
11
  const fetchParams = this.getFetchParams(params);
12
12
  const paginationInfo = getPaginationInfo(fetchParams);
13
+ const isPaged = isPagedPagination(fetchParams.pagination);
13
14
  const results = await strapi.documents(uid).findMany({
14
15
  ...fetchParams,
15
16
  ...paginationInfo
@@ -21,12 +22,12 @@ class CollectionTypeService extends CoreService {
21
22
  }
22
23
  return {
23
24
  results,
24
- pagination: transformPaginationResponse(paginationInfo, count)
25
+ pagination: transformPaginationResponse(paginationInfo, count, isPaged)
25
26
  };
26
27
  }
27
28
  return {
28
29
  results,
29
- pagination: paginationInfo
30
+ pagination: transformPaginationResponse(paginationInfo, void 0, isPaged)
30
31
  };
31
32
  }
32
33
  findOne(documentId, params = {}) {
@@ -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 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,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,IAAA,CACJ;AAEG,QAAA,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,YAAY,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;"}
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 {\n getPaginationInfo,\n shouldCount,\n isPagedPagination,\n transformPaginationResponse,\n} 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 const isPaged = isPagedPagination(fetchParams.pagination);\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, isPaged),\n };\n }\n\n return {\n results,\n pagination: transformPaginationResponse(paginationInfo, undefined, isPaged),\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":";;AAWO,MAAM,8BACH,YAEV;AAAA,EACU;AAAA,EAER,YAAY,aAA0C;AAC9C;AAEN,SAAK,cAAc;AAAA,EACrB;AAAA,EAEA,MAAM,KAAK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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,3 +1,4 @@
1
+ import { pagination } from '@strapi/utils';
1
2
  interface BasePaginationParams {
2
3
  withCount?: boolean | 't' | '1' | 'true' | 'f' | '0' | 'false' | 0 | 1;
3
4
  }
@@ -17,21 +18,13 @@ type PaginationInfo = {
17
18
  start: number;
18
19
  limit: number;
19
20
  };
21
+ declare const isPagedPagination: (pagination?: PaginationParams) => pagination is PagedPagination;
20
22
  declare const shouldCount: (params: {
21
23
  pagination?: PaginationParams;
22
24
  }) => boolean;
23
25
  declare const getPaginationInfo: (params: {
24
26
  pagination?: PaginationParams;
25
27
  }) => PaginationInfo;
26
- declare const transformPaginationResponse: (paginationInfo: PaginationInfo, count: number) => {
27
- pageCount: number;
28
- total: number;
29
- page: number;
30
- pageSize: number;
31
- } | {
32
- total: number;
33
- start: number;
34
- limit: number;
35
- };
36
- export { getPaginationInfo, transformPaginationResponse, shouldCount };
28
+ declare const transformPaginationResponse: (paginationInfo: PaginationInfo, total: number | undefined, isPaged: boolean) => pagination.PagePatinationInformation | pagination.OffsetPaginationInformation;
29
+ export { isPagedPagination, shouldCount, getPaginationInfo, transformPaginationResponse };
37
30
  //# sourceMappingURL=pagination.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../../../src/core-api/service/pagination.ts"],"names":[],"mappings":"AAGA,UAAU,oBAAoB;IAC5B,SAAS,CAAC,EAAE,OAAO,GAAG,GAAG,GAAG,GAAG,GAAG,MAAM,GAAG,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AG;IAC5C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,gBAAgB,GAAG,oBAAoB,GAAG;IAC7C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,eAAe,GAAG,gBAAgB,CAAC;AAElE,KAAK,cAAc,GACf;IACE,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,GACD;IACE,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAaN,QAAA,MAAM,iBAAiB,gBAAiB,gBAAgB,kCACmC,CAAC;AAE5F,QAAA,MAAM,WAAW,WAAY;IAAE,UAAU,CAAC,EAAE,gBAAgB,CAAA;CAAE,YA0B7D,CAAC;AAEF,QAAA,MAAM,iBAAiB,WAAY;IAAE,UAAU,CAAC,EAAE,gBAAgB,CAAA;CAAE,KAAG,cAStE,CAAC;AAEF,QAAA,MAAM,2BAA2B,mBACf,cAAc,SACvB,MAAM,GAAG,SAAS,WAChB,OAAO,kFAcjB,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,iBAAiB,EAAE,2BAA2B,EAAE,CAAC"}
@@ -6,7 +6,8 @@ const getLimitConfigDefaults = () => ({
6
6
  defaultLimit: _.toNumber(strapi.config.get("api.rest.defaultLimit", 25)),
7
7
  maxLimit: _.toNumber(strapi.config.get("api.rest.maxLimit")) || null
8
8
  });
9
- const shouldApplyMaxLimit = (limit, maxLimit, { isPagedPagination: isPagedPagination2 = false } = {}) => !isPagedPagination2 && limit === -1 || maxLimit !== null && limit > maxLimit;
9
+ const isOffsetPagination = (pagination2) => _.has("start", pagination2) || _.has("limit", pagination2);
10
+ const isPagedPagination = (pagination2) => _.has("page", pagination2) || _.has("pageSize", pagination2) || !isOffsetPagination(pagination2);
10
11
  const shouldCount = (params) => {
11
12
  if (_.has("pagination.withCount", params)) {
12
13
  const withCount = params.pagination?.withCount;
@@ -28,51 +29,24 @@ const shouldCount = (params) => {
28
29
  }
29
30
  return Boolean(strapi.config.get("api.rest.withCount", true));
30
31
  };
31
- const isOffsetPagination = (pagination) => _.has("start", pagination) || _.has("limit", pagination);
32
- const isPagedPagination = (pagination) => _.has("page", pagination) || _.has("pageSize", pagination);
33
32
  const getPaginationInfo = (params) => {
34
33
  const { defaultLimit, maxLimit } = getLimitConfigDefaults();
35
- const { pagination } = params;
36
- const isPaged = isPagedPagination(pagination);
37
- const isOffset = isOffsetPagination(pagination);
38
- if (isOffset && isPaged) {
39
- throw new strapiUtils.errors.ValidationError(
40
- "Invalid pagination parameters. Expected either start/limit or page/pageSize"
41
- );
42
- }
43
- if (!isOffset && !isPaged) {
44
- return {
45
- page: 1,
46
- pageSize: defaultLimit
47
- };
48
- }
49
- if (isPagedPagination(pagination)) {
50
- const pageSize = _.isUndefined(pagination.pageSize) ? defaultLimit : Math.max(1, _.toNumber(pagination.pageSize));
51
- return {
52
- page: Math.max(1, _.toNumber(pagination.page || 1)),
53
- pageSize: typeof maxLimit === "number" && shouldApplyMaxLimit(pageSize, maxLimit, { isPagedPagination: true }) ? maxLimit : Math.max(1, pageSize)
54
- };
55
- }
56
- const limit = _.isUndefined(pagination.limit) ? defaultLimit : _.toNumber(pagination.limit);
57
- return {
58
- start: Math.max(0, _.toNumber(pagination.start || 0)),
59
- limit: shouldApplyMaxLimit(limit, maxLimit) ? maxLimit || -1 : Math.max(1, limit)
60
- };
34
+ const { start, limit } = strapiUtils.pagination.withDefaultPagination(params.pagination || {}, {
35
+ defaults: { offset: { limit: defaultLimit }, page: { pageSize: defaultLimit } },
36
+ maxLimit: maxLimit || -1
37
+ });
38
+ return { start, limit };
61
39
  };
62
- const transformPaginationResponse = (paginationInfo, count) => {
63
- if ("page" in paginationInfo) {
64
- return {
65
- ...paginationInfo,
66
- pageCount: Math.ceil(count / paginationInfo.pageSize),
67
- total: count
68
- };
40
+ const transformPaginationResponse = (paginationInfo, total, isPaged) => {
41
+ const transform = isPaged ? strapiUtils.pagination.transformPagedPaginationInfo : strapiUtils.pagination.transformOffsetPaginationInfo;
42
+ const paginationResponse = transform(paginationInfo, total);
43
+ if (!total) {
44
+ return _.omit(["total", "pageCount"], paginationResponse);
69
45
  }
70
- return {
71
- ...paginationInfo,
72
- total: count
73
- };
46
+ return paginationResponse;
74
47
  };
75
48
  exports.getPaginationInfo = getPaginationInfo;
49
+ exports.isPagedPagination = isPagedPagination;
76
50
  exports.shouldCount = shouldCount;
77
51
  exports.transformPaginationResponse = transformPaginationResponse;
78
52
  //# sourceMappingURL=pagination.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pagination.js","sources":["../../../src/core-api/service/pagination.ts"],"sourcesContent":["import { has, toNumber, isUndefined } from 'lodash/fp';\nimport { errors } from '@strapi/utils';\n\ninterface BasePaginationParams {\n withCount?: boolean | 't' | '1' | 'true' | 'f' | '0' | 'false' | 0 | 1;\n}\n\ntype PagedPagination = BasePaginationParams & {\n page?: number;\n pageSize?: number;\n};\n\ntype OffsetPagination = BasePaginationParams & {\n start?: number;\n limit?: number;\n};\n\nexport type PaginationParams = PagedPagination | OffsetPagination;\n\ntype PaginationInfo =\n | {\n page: number;\n pageSize: number;\n }\n | {\n start: number;\n limit: number;\n };\n\n/**\n * Default limit values from config\n */\nconst getLimitConfigDefaults = () => ({\n defaultLimit: toNumber(strapi.config.get('api.rest.defaultLimit', 25)),\n maxLimit: toNumber(strapi.config.get('api.rest.maxLimit')) || null,\n});\n\n/**\n * Should maxLimit be used as the limit or not\n */\nconst shouldApplyMaxLimit = (\n limit: number,\n maxLimit: number | null,\n { isPagedPagination = false } = {}\n) => (!isPagedPagination && limit === -1) || (maxLimit !== null && limit > maxLimit);\n\nconst shouldCount = (params: { pagination?: PaginationParams }) => {\n if (has('pagination.withCount', params)) {\n const withCount = params.pagination?.withCount;\n\n if (typeof withCount === 'boolean') {\n return withCount;\n }\n\n if (typeof withCount === 'undefined') {\n return false;\n }\n\n if (['true', 't', '1', 1].includes(withCount)) {\n return true;\n }\n\n if (['false', 'f', '0', 0].includes(withCount)) {\n return false;\n }\n\n throw new errors.ValidationError(\n 'Invalid withCount parameter. Expected \"t\",\"1\",\"true\",\"false\",\"0\",\"f\"'\n );\n }\n\n return Boolean(strapi.config.get('api.rest.withCount', true));\n};\n\nconst isOffsetPagination = (pagination?: PaginationParams): pagination is OffsetPagination =>\n has('start', pagination) || has('limit', pagination);\n\nconst isPagedPagination = (pagination?: PaginationParams): pagination is PagedPagination =>\n has('page', pagination) || has('pageSize', pagination);\n\nconst getPaginationInfo = (params: { pagination?: PaginationParams }): PaginationInfo => {\n const { defaultLimit, maxLimit } = getLimitConfigDefaults();\n\n const { pagination } = params;\n\n const isPaged = isPagedPagination(pagination);\n const isOffset = isOffsetPagination(pagination);\n\n if (isOffset && isPaged) {\n throw new errors.ValidationError(\n 'Invalid pagination parameters. Expected either start/limit or page/pageSize'\n );\n }\n\n if (!isOffset && !isPaged) {\n return {\n page: 1,\n pageSize: defaultLimit,\n };\n }\n\n if (isPagedPagination(pagination)) {\n const pageSize = isUndefined(pagination.pageSize)\n ? defaultLimit\n : Math.max(1, toNumber(pagination.pageSize));\n\n return {\n page: Math.max(1, toNumber(pagination.page || 1)),\n pageSize:\n typeof maxLimit === 'number' &&\n shouldApplyMaxLimit(pageSize, maxLimit, { isPagedPagination: true })\n ? maxLimit\n : Math.max(1, pageSize),\n };\n }\n\n const limit = isUndefined(pagination.limit) ? defaultLimit : toNumber(pagination.limit);\n\n return {\n start: Math.max(0, toNumber(pagination.start || 0)),\n limit: shouldApplyMaxLimit(limit, maxLimit) ? maxLimit || -1 : Math.max(1, limit),\n };\n};\n\nconst transformPaginationResponse = (paginationInfo: PaginationInfo, count: number) => {\n if ('page' in paginationInfo) {\n return {\n ...paginationInfo,\n pageCount: Math.ceil(count / paginationInfo.pageSize),\n total: count,\n };\n }\n\n return {\n ...paginationInfo,\n total: count,\n };\n};\n\nexport { getPaginationInfo, transformPaginationResponse, shouldCount };\n"],"names":["toNumber","isPagedPagination","has","errors","isUndefined"],"mappings":";;;;AAgCA,MAAM,yBAAyB,OAAO;AAAA,EACpC,cAAcA,EAAS,SAAA,OAAO,OAAO,IAAI,yBAAyB,EAAE,CAAC;AAAA,EACrE,UAAUA,EAAS,SAAA,OAAO,OAAO,IAAI,mBAAmB,CAAC,KAAK;AAChE;AAKA,MAAM,sBAAsB,CAC1B,OACA,UACA,EAAE,mBAAAC,qBAAoB,UAAU,CAAA,MAC5B,CAACA,sBAAqB,UAAU,MAAQ,aAAa,QAAQ,QAAQ;AAErE,MAAA,cAAc,CAAC,WAA8C;AAC7D,MAAAC,EAAA,IAAI,wBAAwB,MAAM,GAAG;AACjC,UAAA,YAAY,OAAO,YAAY;AAEjC,QAAA,OAAO,cAAc,WAAW;AAC3B,aAAA;AAAA,IACT;AAEI,QAAA,OAAO,cAAc,aAAa;AAC7B,aAAA;AAAA,IACT;AAEI,QAAA,CAAC,QAAQ,KAAK,KAAK,CAAC,EAAE,SAAS,SAAS,GAAG;AACtC,aAAA;AAAA,IACT;AAEI,QAAA,CAAC,SAAS,KAAK,KAAK,CAAC,EAAE,SAAS,SAAS,GAAG;AACvC,aAAA;AAAA,IACT;AAEA,UAAM,IAAIC,YAAO,OAAA;AAAA,MACf;AAAA,IAAA;AAAA,EAEJ;AAEA,SAAO,QAAQ,OAAO,OAAO,IAAI,sBAAsB,IAAI,CAAC;AAC9D;AAEA,MAAM,qBAAqB,CAAC,eAC1BD,EAAAA,IAAI,SAAS,UAAU,KAAKA,EAAI,IAAA,SAAS,UAAU;AAErD,MAAM,oBAAoB,CAAC,eACzBA,EAAAA,IAAI,QAAQ,UAAU,KAAKA,EAAI,IAAA,YAAY,UAAU;AAEjD,MAAA,oBAAoB,CAAC,WAA8D;AACvF,QAAM,EAAE,cAAc,SAAS,IAAI,uBAAuB;AAEp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Content":["import { omit, has, toNumber } from 'lodash/fp';\n\nimport { errors, pagination } from '@strapi/utils';\n\ninterface BasePaginationParams {\n withCount?: boolean | 't' | '1' | 'true' | 'f' | '0' | 'false' | 0 | 1;\n}\n\ntype PagedPagination = BasePaginationParams & {\n page?: number;\n pageSize?: number;\n};\n\ntype OffsetPagination = BasePaginationParams & {\n start?: number;\n limit?: number;\n};\n\nexport type PaginationParams = PagedPagination | OffsetPagination;\n\ntype PaginationInfo =\n | {\n page: number;\n pageSize: number;\n }\n | {\n start: number;\n limit: number;\n };\n\n/**\n * Default limit values from config\n */\nconst getLimitConfigDefaults = () => ({\n defaultLimit: toNumber(strapi.config.get('api.rest.defaultLimit', 25)),\n maxLimit: toNumber(strapi.config.get('api.rest.maxLimit')) || null,\n});\n\nconst isOffsetPagination = (pagination?: PaginationParams): pagination is OffsetPagination =>\n has('start', pagination) || has('limit', pagination);\n\nconst isPagedPagination = (pagination?: PaginationParams): pagination is PagedPagination =>\n has('page', pagination) || has('pageSize', pagination) || !isOffsetPagination(pagination);\n\nconst shouldCount = (params: { pagination?: PaginationParams }) => {\n if (has('pagination.withCount', params)) {\n const withCount = params.pagination?.withCount;\n\n if (typeof withCount === 'boolean') {\n return withCount;\n }\n\n if (typeof withCount === 'undefined') {\n return false;\n }\n\n if (['true', 't', '1', 1].includes(withCount)) {\n return true;\n }\n\n if (['false', 'f', '0', 0].includes(withCount)) {\n return false;\n }\n\n throw new errors.ValidationError(\n 'Invalid withCount parameter. Expected \"t\",\"1\",\"true\",\"false\",\"0\",\"f\"'\n );\n }\n\n return Boolean(strapi.config.get('api.rest.withCount', true));\n};\n\nconst getPaginationInfo = (params: { pagination?: PaginationParams }): PaginationInfo => {\n const { defaultLimit, maxLimit } = getLimitConfigDefaults();\n\n const { start, limit } = pagination.withDefaultPagination(params.pagination || {}, {\n defaults: { offset: { limit: defaultLimit }, page: { pageSize: defaultLimit } },\n maxLimit: maxLimit || -1,\n });\n\n return { start, limit };\n};\n\nconst transformPaginationResponse = (\n paginationInfo: PaginationInfo,\n total: number | undefined,\n isPaged: boolean\n) => {\n const transform = isPaged\n ? pagination.transformPagedPaginationInfo\n : pagination.transformOffsetPaginationInfo;\n\n const paginationResponse = transform(paginationInfo, total!);\n\n if (!total) {\n // Ignore total and pageCount if `total` value is not available.\n return omit(['total', 'pageCount'], paginationResponse) as ReturnType<typeof transform>;\n }\n\n return paginationResponse;\n};\n\nexport { isPagedPagination, shouldCount, getPaginationInfo, transformPaginationResponse };\n"],"names":["toNumber","pagination","has","errors","omit"],"mappings":";;;;AAiCA,MAAM,yBAAyB,OAAO;AAAA,EACpC,cAAcA,EAAS,SAAA,OAAO,OAAO,IAAI,yBAAyB,EAAE,CAAC;AAAA,EACrE,UAAUA,EAAS,SAAA,OAAO,OAAO,IAAI,mBAAmB,CAAC,KAAK;AAChE;AAEA,MAAM,qBAAqB,CAACC,gBAC1BC,EAAAA,IAAI,SAASD,WAAU,KAAKC,EAAI,IAAA,SAASD,WAAU;AAErD,MAAM,oBAAoB,CAACA,gBACzBC,EAAA,IAAI,QAAQD,WAAU,KAAKC,EAAA,IAAI,YAAYD,WAAU,KAAK,CAAC,mBAAmBA,WAAU;AAEpF,MAAA,cAAc,CAAC,WAA8C;AAC7D,MAAAC,EAAA,IAAI,wBAAwB,MAAM,GAAG;AACjC,UAAA,YAAY,OAAO,YAAY;AAEjC,QAAA,OAAO,cAAc,WAAW;AAC3B,aAAA;AAAA,IACT;AAEI,QAAA,OAAO,cAAc,aAAa;AAC7B,aAAA;AAAA,IACT;AAEI,QAAA,CAAC,QAAQ,KAAK,KAAK,CAAC,EAAE,SAAS,SAAS,GAAG;AACtC,aAAA;AAAA,IACT;AAEI,QAAA,CAAC,SAAS,KAAK,KAAK,CAAC,EAAE,SAAS,SAAS,GAAG;AACvC,aAAA;AAAA,IACT;AAEA,UAAM,IAAIC,YAAO,OAAA;AAAA,MACf;AAAA,IAAA;AAAA,EAEJ;AAEA,SAAO,QAAQ,OAAO,OAAO,IAAI,sBAAsB,IAAI,CAAC;AAC9D;AAEM,MAAA,oBAAoB,CAAC,WAA8D;AACvF,QAAM,EAAE,cAAc,SAAS,IAAI,uBAAuB;AAEpD,QAAA,EAAE,OAAO,UAAUF,YAAAA,WAAW,sBAAsB,OAAO,cAAc,IAAI;AAAA,IACjF,UAAU,EAAE,QAAQ,EAAE,OAAO,aAAa,GAAG,MAAM,EAAE,UAAU,eAAe;AAAA,IAC9E,UAAU,YAAY;AAAA,EAAA,CACvB;AAEM,SAAA,EAAE,OAAO;AAClB;AAEA,MAAM,8BAA8B,CAClC,gBACA,OACA,YACG;AACH,QAAM,YAAY,UACdA,YAAAA,WAAW,+BACXA,YAAAA,WAAW;AAET,QAAA,qBAAqB,UAAU,gBAAgB,KAAM;AAE3D,MAAI,CAAC,OAAO;AAEV,WAAOG,EAAK,KAAA,CAAC,SAAS,WAAW,GAAG,kBAAkB;AAAA,EACxD;AAEO,SAAA;AACT;;;;;"}
@@ -1,10 +1,11 @@
1
- import { has, isUndefined, toNumber } from "lodash/fp";
2
- import { errors } from "@strapi/utils";
1
+ import { has, omit, toNumber } from "lodash/fp";
2
+ import { errors, pagination } from "@strapi/utils";
3
3
  const getLimitConfigDefaults = () => ({
4
4
  defaultLimit: toNumber(strapi.config.get("api.rest.defaultLimit", 25)),
5
5
  maxLimit: toNumber(strapi.config.get("api.rest.maxLimit")) || null
6
6
  });
7
- const shouldApplyMaxLimit = (limit, maxLimit, { isPagedPagination: isPagedPagination2 = false } = {}) => !isPagedPagination2 && limit === -1 || maxLimit !== null && limit > maxLimit;
7
+ const isOffsetPagination = (pagination2) => has("start", pagination2) || has("limit", pagination2);
8
+ const isPagedPagination = (pagination2) => has("page", pagination2) || has("pageSize", pagination2) || !isOffsetPagination(pagination2);
8
9
  const shouldCount = (params) => {
9
10
  if (has("pagination.withCount", params)) {
10
11
  const withCount = params.pagination?.withCount;
@@ -26,52 +27,25 @@ const shouldCount = (params) => {
26
27
  }
27
28
  return Boolean(strapi.config.get("api.rest.withCount", true));
28
29
  };
29
- const isOffsetPagination = (pagination) => has("start", pagination) || has("limit", pagination);
30
- const isPagedPagination = (pagination) => has("page", pagination) || has("pageSize", pagination);
31
30
  const getPaginationInfo = (params) => {
32
31
  const { defaultLimit, maxLimit } = getLimitConfigDefaults();
33
- const { pagination } = params;
34
- const isPaged = isPagedPagination(pagination);
35
- const isOffset = isOffsetPagination(pagination);
36
- if (isOffset && isPaged) {
37
- throw new errors.ValidationError(
38
- "Invalid pagination parameters. Expected either start/limit or page/pageSize"
39
- );
40
- }
41
- if (!isOffset && !isPaged) {
42
- return {
43
- page: 1,
44
- pageSize: defaultLimit
45
- };
46
- }
47
- if (isPagedPagination(pagination)) {
48
- const pageSize = isUndefined(pagination.pageSize) ? defaultLimit : Math.max(1, toNumber(pagination.pageSize));
49
- return {
50
- page: Math.max(1, toNumber(pagination.page || 1)),
51
- pageSize: typeof maxLimit === "number" && shouldApplyMaxLimit(pageSize, maxLimit, { isPagedPagination: true }) ? maxLimit : Math.max(1, pageSize)
52
- };
53
- }
54
- const limit = isUndefined(pagination.limit) ? defaultLimit : toNumber(pagination.limit);
55
- return {
56
- start: Math.max(0, toNumber(pagination.start || 0)),
57
- limit: shouldApplyMaxLimit(limit, maxLimit) ? maxLimit || -1 : Math.max(1, limit)
58
- };
32
+ const { start, limit } = pagination.withDefaultPagination(params.pagination || {}, {
33
+ defaults: { offset: { limit: defaultLimit }, page: { pageSize: defaultLimit } },
34
+ maxLimit: maxLimit || -1
35
+ });
36
+ return { start, limit };
59
37
  };
60
- const transformPaginationResponse = (paginationInfo, count) => {
61
- if ("page" in paginationInfo) {
62
- return {
63
- ...paginationInfo,
64
- pageCount: Math.ceil(count / paginationInfo.pageSize),
65
- total: count
66
- };
38
+ const transformPaginationResponse = (paginationInfo, total, isPaged) => {
39
+ const transform = isPaged ? pagination.transformPagedPaginationInfo : pagination.transformOffsetPaginationInfo;
40
+ const paginationResponse = transform(paginationInfo, total);
41
+ if (!total) {
42
+ return omit(["total", "pageCount"], paginationResponse);
67
43
  }
68
- return {
69
- ...paginationInfo,
70
- total: count
71
- };
44
+ return paginationResponse;
72
45
  };
73
46
  export {
74
47
  getPaginationInfo,
48
+ isPagedPagination,
75
49
  shouldCount,
76
50
  transformPaginationResponse
77
51
  };
@@ -1 +1 @@
1
- {"version":3,"file":"pagination.mjs","sources":["../../../src/core-api/service/pagination.ts"],"sourcesContent":["import { has, toNumber, isUndefined } from 'lodash/fp';\nimport { errors } from '@strapi/utils';\n\ninterface BasePaginationParams {\n withCount?: boolean | 't' | '1' | 'true' | 'f' | '0' | 'false' | 0 | 1;\n}\n\ntype PagedPagination = BasePaginationParams & {\n page?: number;\n pageSize?: number;\n};\n\ntype OffsetPagination = BasePaginationParams & {\n start?: number;\n limit?: number;\n};\n\nexport type PaginationParams = PagedPagination | OffsetPagination;\n\ntype PaginationInfo =\n | {\n page: number;\n pageSize: number;\n }\n | {\n start: number;\n limit: number;\n };\n\n/**\n * Default limit values from config\n */\nconst getLimitConfigDefaults = () => ({\n defaultLimit: toNumber(strapi.config.get('api.rest.defaultLimit', 25)),\n maxLimit: toNumber(strapi.config.get('api.rest.maxLimit')) || null,\n});\n\n/**\n * Should maxLimit be used as the limit or not\n */\nconst shouldApplyMaxLimit = (\n limit: number,\n maxLimit: number | null,\n { isPagedPagination = false } = {}\n) => (!isPagedPagination && limit === -1) || (maxLimit !== null && limit > maxLimit);\n\nconst shouldCount = (params: { pagination?: PaginationParams }) => {\n if (has('pagination.withCount', params)) {\n const withCount = params.pagination?.withCount;\n\n if (typeof withCount === 'boolean') {\n return withCount;\n }\n\n if (typeof withCount === 'undefined') {\n return false;\n }\n\n if (['true', 't', '1', 1].includes(withCount)) {\n return true;\n }\n\n if (['false', 'f', '0', 0].includes(withCount)) {\n return false;\n }\n\n throw new errors.ValidationError(\n 'Invalid withCount parameter. Expected \"t\",\"1\",\"true\",\"false\",\"0\",\"f\"'\n );\n }\n\n return Boolean(strapi.config.get('api.rest.withCount', true));\n};\n\nconst isOffsetPagination = (pagination?: PaginationParams): pagination is OffsetPagination =>\n has('start', pagination) || has('limit', pagination);\n\nconst isPagedPagination = (pagination?: PaginationParams): pagination is PagedPagination =>\n has('page', pagination) || has('pageSize', pagination);\n\nconst getPaginationInfo = (params: { pagination?: PaginationParams }): PaginationInfo => {\n const { defaultLimit, maxLimit } = getLimitConfigDefaults();\n\n const { pagination } = params;\n\n const isPaged = isPagedPagination(pagination);\n const isOffset = isOffsetPagination(pagination);\n\n if (isOffset && isPaged) {\n throw new errors.ValidationError(\n 'Invalid pagination parameters. Expected either start/limit or page/pageSize'\n );\n }\n\n if (!isOffset && !isPaged) {\n return {\n page: 1,\n pageSize: defaultLimit,\n };\n }\n\n if (isPagedPagination(pagination)) {\n const pageSize = isUndefined(pagination.pageSize)\n ? defaultLimit\n : Math.max(1, toNumber(pagination.pageSize));\n\n return {\n page: Math.max(1, toNumber(pagination.page || 1)),\n pageSize:\n typeof maxLimit === 'number' &&\n shouldApplyMaxLimit(pageSize, maxLimit, { isPagedPagination: true })\n ? maxLimit\n : Math.max(1, pageSize),\n };\n }\n\n const limit = isUndefined(pagination.limit) ? defaultLimit : toNumber(pagination.limit);\n\n return {\n start: Math.max(0, toNumber(pagination.start || 0)),\n limit: shouldApplyMaxLimit(limit, maxLimit) ? maxLimit || -1 : Math.max(1, limit),\n };\n};\n\nconst transformPaginationResponse = (paginationInfo: PaginationInfo, count: number) => {\n if ('page' in paginationInfo) {\n return {\n ...paginationInfo,\n pageCount: Math.ceil(count / paginationInfo.pageSize),\n total: count,\n };\n }\n\n return {\n ...paginationInfo,\n total: count,\n };\n};\n\nexport { getPaginationInfo, transformPaginationResponse, shouldCount };\n"],"names":["isPagedPagination"],"mappings":";;AAgCA,MAAM,yBAAyB,OAAO;AAAA,EACpC,cAAc,SAAS,OAAO,OAAO,IAAI,yBAAyB,EAAE,CAAC;AAAA,EACrE,UAAU,SAAS,OAAO,OAAO,IAAI,mBAAmB,CAAC,KAAK;AAChE;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IAC5C,eACA,KAAK,IAAI,GAAG,SAAS,WAAW,QAAQ,CAAC;AAEtC,WAAA;AAAA,MACL,MAAM,KAAK,IAAI,GAAG,SAAS,WAAW,QAAQ,CAAC,CAAC;AAAA,MAChD,UACE,OAAO,aAAa,YACpB,oBAAoB,UAAU,UAAU,EAAE,mBAAmB,KAAA,CAAM,IAC/D,WACA,KAAK,IAAI,GAAG,QAAQ;AAAA,IAAA;AAAA,EAE9B;AAEM,QAAA,QAAQ,YAAY,WAAW,KAAK,IAAI,eAAe,SAAS,WAAW,KAAK;AAE/E,SAAA;AAAA,IACL,OAAO,KAAK,IAAI,GAAG,SAAS,WAAW,SAAS,CAAC,CAAC;AAAA,IAClD,OAAO,oBAAoB,OAAO,QAAQ,IAAI,YAAY,KAAK,KAAK,IAAI,GAAG,KAAK;AAAA,EAAA;AAEpF;AAEM,MAAA,8BAA8B,CAAC,gBAAgC,UAAkB;AACrF,MAAI,UAAU,gBAAgB;AACrB,WAAA;AAAA,MACL,GAAG;AAAA,MACH,WAAW,KAAK,KAAK,QAAQ,eAAe,QAAQ;AAAA,MACpD,OAAO;AAAA,IAAA;AAAA,EAEX;AAEO,SAAA;AAAA,IACL,GAAG;AAAA,IACH,OAAO;AAAA,EAAA;AAEX;"}
1
+ {"version":3,"file":"pagination.mjs","sources":["../../../src/core-api/service/pagination.ts"],"sourcesContent":["import { omit, has, toNumber } from 'lodash/fp';\n\nimport { errors, pagination } from '@strapi/utils';\n\ninterface BasePaginationParams {\n withCount?: boolean | 't' | '1' | 'true' | 'f' | '0' | 'false' | 0 | 1;\n}\n\ntype PagedPagination = BasePaginationParams & {\n page?: number;\n pageSize?: number;\n};\n\ntype OffsetPagination = BasePaginationParams & {\n start?: number;\n limit?: number;\n};\n\nexport type PaginationParams = PagedPagination | OffsetPagination;\n\ntype PaginationInfo =\n | {\n page: number;\n pageSize: number;\n }\n | {\n start: number;\n limit: number;\n };\n\n/**\n * Default limit values from config\n */\nconst getLimitConfigDefaults = () => ({\n defaultLimit: toNumber(strapi.config.get('api.rest.defaultLimit', 25)),\n maxLimit: toNumber(strapi.config.get('api.rest.maxLimit')) || null,\n});\n\nconst isOffsetPagination = (pagination?: PaginationParams): pagination is OffsetPagination =>\n has('start', pagination) || has('limit', pagination);\n\nconst isPagedPagination = (pagination?: PaginationParams): pagination is PagedPagination =>\n has('page', pagination) || has('pageSize', pagination) || !isOffsetPagination(pagination);\n\nconst shouldCount = (params: { pagination?: PaginationParams }) => {\n if (has('pagination.withCount', params)) {\n const withCount = params.pagination?.withCount;\n\n if (typeof withCount === 'boolean') {\n return withCount;\n }\n\n if (typeof withCount === 'undefined') {\n return false;\n }\n\n if (['true', 't', '1', 1].includes(withCount)) {\n return true;\n }\n\n if (['false', 'f', '0', 0].includes(withCount)) {\n return false;\n }\n\n throw new errors.ValidationError(\n 'Invalid withCount parameter. Expected \"t\",\"1\",\"true\",\"false\",\"0\",\"f\"'\n );\n }\n\n return Boolean(strapi.config.get('api.rest.withCount', true));\n};\n\nconst getPaginationInfo = (params: { pagination?: PaginationParams }): PaginationInfo => {\n const { defaultLimit, maxLimit } = getLimitConfigDefaults();\n\n const { start, limit } = pagination.withDefaultPagination(params.pagination || {}, {\n defaults: { offset: { limit: defaultLimit }, page: { pageSize: defaultLimit } },\n maxLimit: maxLimit || -1,\n });\n\n return { start, limit };\n};\n\nconst transformPaginationResponse = (\n paginationInfo: PaginationInfo,\n total: number | undefined,\n isPaged: boolean\n) => {\n const transform = isPaged\n ? pagination.transformPagedPaginationInfo\n : pagination.transformOffsetPaginationInfo;\n\n const paginationResponse = transform(paginationInfo, total!);\n\n if (!total) {\n // Ignore total and pageCount if `total` value is not available.\n return omit(['total', 'pageCount'], paginationResponse) as ReturnType<typeof transform>;\n }\n\n return paginationResponse;\n};\n\nexport { isPagedPagination, shouldCount, getPaginationInfo, transformPaginationResponse };\n"],"names":["pagination"],"mappings":";;AAiCA,MAAM,yBAAyB,OAAO;AAAA,EACpC,cAAc,SAAS,OAAO,OAA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OAAO;AAEV,WAAO,KAAK,CAAC,SAAS,WAAW,GAAG,kBAAkB;AAAA,EACxD;AAEO,SAAA;AACT;"}
@@ -1,4 +1,21 @@
1
- import type { Migration } from '@strapi/database';
1
+ import type { Database, Migration } from '@strapi/database';
2
+ type DocumentVersion = {
3
+ documentId: string;
4
+ locale: string;
5
+ };
6
+ type Knex = Parameters<Migration['up']>[0];
7
+ /**
8
+ * Load a batch of versions to discard.
9
+ *
10
+ * Versions with only a draft version will be ignored.
11
+ * Only versions with a published version (which always have a draft version) will be discarded.
12
+ */
13
+ export declare function getBatchToDiscard({ db, trx, uid, batchSize, }: {
14
+ db: Database;
15
+ trx: Knex;
16
+ uid: string;
17
+ batchSize?: number;
18
+ }): AsyncGenerator<DocumentVersion[], void, unknown>;
2
19
  /**
3
20
  * On V4 there was no concept of document, and an entry could be in a draft or published state.
4
21
  * But not both at the same time.
@@ -9,4 +26,5 @@ import type { Migration } from '@strapi/database';
9
26
  * This migration creates the document draft counterpart for all the entries that were in a published state.
10
27
  */
11
28
  export declare const discardDocumentDrafts: Migration;
29
+ export {};
12
30
  //# sourceMappingURL=5.0.0-discard-drafts.d.ts.map
@@ -1 +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"}
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,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG5D,KAAK,eAAe,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAC9D,KAAK,IAAI,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAE3C;;;;;GAKG;AACH,wBAAuB,iBAAiB,CAAC,EACvC,EAAE,EACF,GAAG,EACH,GAAG,EACH,SAAgB,GACjB,EAAE;IACD,EAAE,EAAE,QAAQ,CAAC;IACb,GAAG,EAAE,IAAI,CAAC;IACV,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,oDAuBA;AAiCD;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,EAAE,SASnC,CAAC"}
@@ -46,4 +46,5 @@ const discardDocumentDrafts = {
46
46
  }
47
47
  };
48
48
  exports.discardDocumentDrafts = discardDocumentDrafts;
49
+ exports.getBatchToDiscard = getBatchToDiscard;
49
50
  //# sourceMappingURL=5.0.0-discard-drafts.js.map