@strapi/core 0.0.0-experimental.d1015a5194f12ae455cf40d340f03576bb0691c0 → 0.0.0-experimental.d190a700af70e9360d767221b76cd8e815bd01aa

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of @strapi/core might be problematic. Click here for more details.

Files changed (199) hide show
  1. package/dist/Strapi.d.ts +1 -0
  2. package/dist/Strapi.d.ts.map +1 -1
  3. package/dist/Strapi.js +22 -5
  4. package/dist/Strapi.js.map +1 -1
  5. package/dist/Strapi.mjs +22 -5
  6. package/dist/Strapi.mjs.map +1 -1
  7. package/dist/configuration/config-loader.js.map +1 -1
  8. package/dist/configuration/config-loader.mjs.map +1 -1
  9. package/dist/configuration/urls.js.map +1 -1
  10. package/dist/configuration/urls.mjs.map +1 -1
  11. package/dist/constants.d.ts +3 -0
  12. package/dist/constants.d.ts.map +1 -0
  13. package/dist/constants.js +6 -0
  14. package/dist/constants.js.map +1 -0
  15. package/dist/constants.mjs +4 -0
  16. package/dist/constants.mjs.map +1 -0
  17. package/dist/container.js.map +1 -1
  18. package/dist/container.mjs.map +1 -1
  19. package/dist/core-api/controller/index.d.ts.map +1 -1
  20. package/dist/core-api/controller/index.js +2 -1
  21. package/dist/core-api/controller/index.js.map +1 -1
  22. package/dist/core-api/controller/index.mjs +2 -1
  23. package/dist/core-api/controller/index.mjs.map +1 -1
  24. package/dist/core-api/controller/transform.d.ts +3 -2
  25. package/dist/core-api/controller/transform.d.ts.map +1 -1
  26. package/dist/core-api/controller/transform.js +13 -3
  27. package/dist/core-api/controller/transform.js.map +1 -1
  28. package/dist/core-api/controller/transform.mjs +13 -3
  29. package/dist/core-api/controller/transform.mjs.map +1 -1
  30. package/dist/core-api/routes/index.js.map +1 -1
  31. package/dist/core-api/routes/index.mjs.map +1 -1
  32. package/dist/core-api/routes/validation/attributes.d.ts +1 -1
  33. package/dist/core-api/routes/validation/mappers.d.ts.map +1 -1
  34. package/dist/core-api/routes/validation/mappers.js +35 -0
  35. package/dist/core-api/routes/validation/mappers.js.map +1 -1
  36. package/dist/core-api/routes/validation/mappers.mjs +35 -0
  37. package/dist/core-api/routes/validation/mappers.mjs.map +1 -1
  38. package/dist/core-api/routes/validation/utils.d.ts.map +1 -1
  39. package/dist/core-api/routes/validation/utils.js +22 -6
  40. package/dist/core-api/routes/validation/utils.js.map +1 -1
  41. package/dist/core-api/routes/validation/utils.mjs +22 -6
  42. package/dist/core-api/routes/validation/utils.mjs.map +1 -1
  43. package/dist/core-api/service/collection-type.js.map +1 -1
  44. package/dist/core-api/service/collection-type.mjs.map +1 -1
  45. package/dist/core-api/service/single-type.js.map +1 -1
  46. package/dist/core-api/service/single-type.mjs.map +1 -1
  47. package/dist/domain/content-type/index.js.map +1 -1
  48. package/dist/domain/content-type/index.mjs.map +1 -1
  49. package/dist/domain/module/index.js.map +1 -1
  50. package/dist/domain/module/index.mjs.map +1 -1
  51. package/dist/ee/index.js.map +1 -1
  52. package/dist/ee/index.mjs.map +1 -1
  53. package/dist/ee/license.js +1 -2
  54. package/dist/ee/license.js.map +1 -1
  55. package/dist/ee/license.mjs +1 -2
  56. package/dist/ee/license.mjs.map +1 -1
  57. package/dist/loaders/apis.js.map +1 -1
  58. package/dist/loaders/apis.mjs.map +1 -1
  59. package/dist/loaders/components.js.map +1 -1
  60. package/dist/loaders/components.mjs.map +1 -1
  61. package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
  62. package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
  63. package/dist/loaders/plugins/index.js +1 -1
  64. package/dist/loaders/plugins/index.js.map +1 -1
  65. package/dist/loaders/plugins/index.mjs +1 -1
  66. package/dist/loaders/plugins/index.mjs.map +1 -1
  67. package/dist/loaders/src-index.js.map +1 -1
  68. package/dist/loaders/src-index.mjs.map +1 -1
  69. package/dist/middlewares/logger.js.map +1 -1
  70. package/dist/middlewares/logger.mjs.map +1 -1
  71. package/dist/middlewares/response-time.js.map +1 -1
  72. package/dist/middlewares/response-time.mjs.map +1 -1
  73. package/dist/middlewares/security.d.ts.map +1 -1
  74. package/dist/middlewares/security.js +2 -15
  75. package/dist/middlewares/security.js.map +1 -1
  76. package/dist/middlewares/security.mjs +2 -15
  77. package/dist/middlewares/security.mjs.map +1 -1
  78. package/dist/migrations/first-published-at.js.map +1 -1
  79. package/dist/migrations/first-published-at.mjs.map +1 -1
  80. package/dist/package.json.js +14 -12
  81. package/dist/package.json.js.map +1 -1
  82. package/dist/package.json.mjs +14 -12
  83. package/dist/package.json.mjs.map +1 -1
  84. package/dist/providers/index.d.ts.map +1 -1
  85. package/dist/providers/index.js +2 -0
  86. package/dist/providers/index.js.map +1 -1
  87. package/dist/providers/index.mjs +2 -0
  88. package/dist/providers/index.mjs.map +1 -1
  89. package/dist/providers/session-manager.d.ts +3 -0
  90. package/dist/providers/session-manager.d.ts.map +1 -0
  91. package/dist/providers/session-manager.js +23 -0
  92. package/dist/providers/session-manager.js.map +1 -0
  93. package/dist/providers/session-manager.mjs +21 -0
  94. package/dist/providers/session-manager.mjs.map +1 -0
  95. package/dist/registries/apis.js.map +1 -1
  96. package/dist/registries/apis.mjs.map +1 -1
  97. package/dist/registries/custom-fields.js.map +1 -1
  98. package/dist/registries/custom-fields.mjs.map +1 -1
  99. package/dist/registries/namespace.js.map +1 -1
  100. package/dist/registries/namespace.mjs.map +1 -1
  101. package/dist/registries/plugins.js.map +1 -1
  102. package/dist/registries/plugins.mjs.map +1 -1
  103. package/dist/registries/policies.js.map +1 -1
  104. package/dist/registries/policies.mjs.map +1 -1
  105. package/dist/services/config.js.map +1 -1
  106. package/dist/services/config.mjs.map +1 -1
  107. package/dist/services/content-api/index.d.ts +1 -1
  108. package/dist/services/content-api/index.d.ts.map +1 -1
  109. package/dist/services/content-api/index.js +1 -1
  110. package/dist/services/content-api/index.js.map +1 -1
  111. package/dist/services/content-api/index.mjs +2 -2
  112. package/dist/services/content-api/index.mjs.map +1 -1
  113. package/dist/services/content-api/permissions/index.js.map +1 -1
  114. package/dist/services/content-api/permissions/index.mjs.map +1 -1
  115. package/dist/services/content-source-maps.d.ts +13 -0
  116. package/dist/services/content-source-maps.d.ts.map +1 -0
  117. package/dist/services/content-source-maps.js +108 -0
  118. package/dist/services/content-source-maps.js.map +1 -0
  119. package/dist/services/content-source-maps.mjs +106 -0
  120. package/dist/services/content-source-maps.mjs.map +1 -0
  121. package/dist/services/core-store.js.map +1 -1
  122. package/dist/services/core-store.mjs.map +1 -1
  123. package/dist/services/document-service/components.d.ts +31 -1
  124. package/dist/services/document-service/components.d.ts.map +1 -1
  125. package/dist/services/document-service/components.js +109 -0
  126. package/dist/services/document-service/components.js.map +1 -1
  127. package/dist/services/document-service/components.mjs +107 -1
  128. package/dist/services/document-service/components.mjs.map +1 -1
  129. package/dist/services/document-service/repository.d.ts.map +1 -1
  130. package/dist/services/document-service/repository.js +5 -1
  131. package/dist/services/document-service/repository.js.map +1 -1
  132. package/dist/services/document-service/repository.mjs +6 -2
  133. package/dist/services/document-service/repository.mjs.map +1 -1
  134. package/dist/services/document-service/transform/fields.js.map +1 -1
  135. package/dist/services/document-service/transform/fields.mjs.map +1 -1
  136. package/dist/services/document-service/transform/id-map.js.map +1 -1
  137. package/dist/services/document-service/transform/id-map.mjs.map +1 -1
  138. package/dist/services/document-service/utils/clean-component-join-table.d.ts +7 -0
  139. package/dist/services/document-service/utils/clean-component-join-table.d.ts.map +1 -0
  140. package/dist/services/document-service/utils/clean-component-join-table.js +145 -0
  141. package/dist/services/document-service/utils/clean-component-join-table.js.map +1 -0
  142. package/dist/services/document-service/utils/clean-component-join-table.mjs +143 -0
  143. package/dist/services/document-service/utils/clean-component-join-table.mjs.map +1 -0
  144. package/dist/services/document-service/utils/unidirectional-relations.d.ts +19 -2
  145. package/dist/services/document-service/utils/unidirectional-relations.d.ts.map +1 -1
  146. package/dist/services/document-service/utils/unidirectional-relations.js +21 -6
  147. package/dist/services/document-service/utils/unidirectional-relations.js.map +1 -1
  148. package/dist/services/document-service/utils/unidirectional-relations.mjs +21 -6
  149. package/dist/services/document-service/utils/unidirectional-relations.mjs.map +1 -1
  150. package/dist/services/entity-service/index.js.map +1 -1
  151. package/dist/services/entity-service/index.mjs.map +1 -1
  152. package/dist/services/entity-validator/blocks-validator.js.map +1 -1
  153. package/dist/services/entity-validator/blocks-validator.mjs.map +1 -1
  154. package/dist/services/entity-validator/index.js.map +1 -1
  155. package/dist/services/entity-validator/index.mjs.map +1 -1
  156. package/dist/services/metrics/index.js +2 -1
  157. package/dist/services/metrics/index.js.map +1 -1
  158. package/dist/services/metrics/index.mjs +2 -1
  159. package/dist/services/metrics/index.mjs.map +1 -1
  160. package/dist/services/metrics/middleware.d.ts +2 -1
  161. package/dist/services/metrics/middleware.d.ts.map +1 -1
  162. package/dist/services/metrics/middleware.js +2 -2
  163. package/dist/services/metrics/middleware.js.map +1 -1
  164. package/dist/services/metrics/middleware.mjs +2 -2
  165. package/dist/services/metrics/middleware.mjs.map +1 -1
  166. package/dist/services/metrics/sender.d.ts.map +1 -1
  167. package/dist/services/metrics/sender.js +2 -1
  168. package/dist/services/metrics/sender.js.map +1 -1
  169. package/dist/services/metrics/sender.mjs +2 -1
  170. package/dist/services/metrics/sender.mjs.map +1 -1
  171. package/dist/services/server/compose-endpoint.js.map +1 -1
  172. package/dist/services/server/compose-endpoint.mjs.map +1 -1
  173. package/dist/services/server/index.js.map +1 -1
  174. package/dist/services/server/index.mjs.map +1 -1
  175. package/dist/services/server/middleware.js.map +1 -1
  176. package/dist/services/server/middleware.mjs.map +1 -1
  177. package/dist/services/server/register-routes.js.map +1 -1
  178. package/dist/services/server/register-routes.mjs.map +1 -1
  179. package/dist/services/server/routing.js.map +1 -1
  180. package/dist/services/server/routing.mjs.map +1 -1
  181. package/dist/services/session-manager.d.ts +167 -0
  182. package/dist/services/session-manager.d.ts.map +1 -0
  183. package/dist/services/session-manager.js +529 -0
  184. package/dist/services/session-manager.js.map +1 -0
  185. package/dist/services/session-manager.mjs +526 -0
  186. package/dist/services/session-manager.mjs.map +1 -0
  187. package/dist/services/webhook-runner.js.map +1 -1
  188. package/dist/services/webhook-runner.mjs.map +1 -1
  189. package/dist/services/worker-queue.js.map +1 -1
  190. package/dist/services/worker-queue.mjs.map +1 -1
  191. package/dist/utils/fetch.js.map +1 -1
  192. package/dist/utils/fetch.mjs.map +1 -1
  193. package/dist/utils/filepath-to-prop-path.js.map +1 -1
  194. package/dist/utils/filepath-to-prop-path.mjs.map +1 -1
  195. package/dist/utils/load-config-file.js.map +1 -1
  196. package/dist/utils/load-config-file.mjs.map +1 -1
  197. package/dist/utils/startup-logger.js.map +1 -1
  198. package/dist/utils/startup-logger.mjs.map +1 -1
  199. package/package.json +14 -12
@@ -22,6 +22,9 @@ function _interopNamespaceDefault(e) {
22
22
 
23
23
  var z__namespace = /*#__PURE__*/_interopNamespaceDefault(z);
24
24
 
25
+ const isCustomFieldAttribute = (attribute)=>{
26
+ return !!attribute && typeof attribute === 'object' && attribute.type === 'customField' && typeof attribute.customField === 'string';
27
+ };
25
28
  /**
26
29
  * Creates a Zod schema for a collection of Strapi attributes.
27
30
  *
@@ -136,6 +139,22 @@ var z__namespace = /*#__PURE__*/_interopNamespaceDefault(z);
136
139
  return attributes.uidToSchema(attribute);
137
140
  default:
138
141
  {
142
+ if (isCustomFieldAttribute(attribute)) {
143
+ const attrCF = attribute;
144
+ const strapiInstance = global.strapi;
145
+ if (!strapiInstance) {
146
+ throw new Error('Strapi instance not available for custom field conversion');
147
+ }
148
+ const customField = strapiInstance.get('custom-fields').get(attrCF.customField);
149
+ if (!customField) {
150
+ throw new Error(`Custom field '${attrCF.customField}' not found`);
151
+ }
152
+ // Re-dispatch with the resolved underlying Strapi kind
153
+ return mapAttributeToSchema({
154
+ ...attrCF,
155
+ type: customField.type
156
+ });
157
+ }
139
158
  const { type } = attribute;
140
159
  throw new Error(`Unsupported attribute type: ${type}`);
141
160
  }
@@ -225,6 +244,22 @@ var z__namespace = /*#__PURE__*/_interopNamespaceDefault(z);
225
244
  return attributes.uidToInputSchema(attribute);
226
245
  default:
227
246
  {
247
+ if (isCustomFieldAttribute(attribute)) {
248
+ const attrCF = attribute;
249
+ const strapiInstance = global.strapi;
250
+ if (!strapiInstance) {
251
+ throw new Error('Strapi instance not available for custom field conversion');
252
+ }
253
+ const customField = strapiInstance.get('custom-fields').get(attrCF.customField);
254
+ if (!customField) {
255
+ throw new Error(`Custom field '${attrCF.customField}' not found`);
256
+ }
257
+ // Re-dispatch with the resolved underlying Strapi kind
258
+ return mapAttributeToInputSchema({
259
+ ...attrCF,
260
+ type: customField.type
261
+ });
262
+ }
228
263
  const { type } = attribute;
229
264
  throw new Error(`Unsupported attribute type: ${type}`);
230
265
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mappers.js","sources":["../../../../src/core-api/routes/validation/mappers.ts"],"sourcesContent":["/**\n * @fileoverview\n * This file contains functions responsible for mapping Strapi attribute definitions to Zod schemas.\n */\n\nimport type { Schema } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n// eslint-disable-next-line import/no-cycle\nimport * as attributes from './attributes';\n\n/**\n * Creates a Zod schema for a collection of Strapi attributes.\n *\n * @param attributes - An array of tuples, where each tuple contains the attribute name and its schema definition.\n * @returns A Zod object schema representing the combined attributes.\n *\n * @example\n * ```typescript\n * const myAttributes = [\n * ['title', { type: 'string', required: true }],\n * ['description', { type: 'text' }],\n * ];\n * const schema = createAttributesSchema(myAttributes);\n * // schema will be a Zod object with 'title' and 'description' fields,\n * // each mapped to their respective Zod schemas based on their Strapi attribute types.\n * ```\n */\nexport const createAttributesSchema = (\n attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]\n) => {\n return attributes.reduce((acc, [name, attribute]) => {\n return acc.extend({\n get [name]() {\n return mapAttributeToSchema(attribute);\n },\n });\n }, z.object({}));\n};\n\n/**\n * Creates a Zod input schema for a collection of Strapi attributes.\n * This is typically used for validating incoming data (e.g., from API requests).\n *\n * @param attributes - An array of tuples, where each tuple contains the attribute name and its schema definition.\n * @returns A Zod object schema representing the combined input attributes.\n *\n * @example\n * ```typescript\n * const myInputAttributes = [\n * ['email', { type: 'email', required: true }],\n * ['description', { type: 'text', minLength: 8 }],\n * ];\n * const inputSchema = createAttributesInputSchema(myInputAttributes);\n * // inputSchema will be a Zod object with 'email' and 'description' fields,\n * // mapped to Zod schemas suitable for input validation.\n * ```\n */\nexport const createAttributesInputSchema = (\n attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]\n) => {\n return attributes.reduce((acc, [name, attribute]) => {\n return acc.extend({\n get [name]() {\n return mapAttributeToInputSchema(attribute);\n },\n });\n }, z.object({}));\n};\n\n/**\n * Maps a Strapi attribute definition to a corresponding Zod validation schema.\n *\n * This function handles every Strapi attribute types and converts them into\n * appropriate Zod validation schemas.\n *\n * @param attribute - The Strapi attribute configuration object.\n * @returns A Zod schema that corresponds to the input attribute's type.\n * @throws {Error} Throws an error if an unsupported attribute type is provided.\n *\n * @example\n * ```typescript\n * const stringAttribute = { type: 'string', minLength: 3 };\n * const stringSchema = mapAttributeToSchema(stringAttribute); // Returns a Zod string schema with minLength.\n *\n * const booleanAttribute = { type: 'boolean', default: false };\n * const booleanSchema = mapAttributeToSchema(booleanAttribute); // Returns a Zod boolean schema with a default.\n * ```\n */\nexport const mapAttributeToSchema = (attribute: Schema.Attribute.AnyAttribute): z.ZodTypeAny => {\n switch (attribute.type) {\n case 'biginteger':\n return attributes.bigIntegerToSchema(attribute);\n case 'blocks':\n return attributes.blocksToSchema();\n case 'boolean':\n return attributes.booleanToSchema(attribute);\n case 'component':\n return attributes.componentToSchema(attribute);\n case 'date':\n return attributes.dateToSchema(attribute);\n case 'datetime':\n return attributes.datetimeToSchema(attribute);\n case 'decimal':\n return attributes.decimalToSchema(attribute);\n case 'dynamiczone':\n return attributes.dynamicZoneToSchema(attribute);\n case 'email':\n return attributes.emailToSchema(attribute);\n case 'enumeration':\n return attributes.enumToSchema(attribute);\n case 'float':\n return attributes.floatToSchema(attribute);\n case 'integer':\n return attributes.integerToSchema(attribute);\n case 'json':\n return attributes.jsonToSchema(attribute);\n case 'media':\n return attributes.mediaToSchema(attribute);\n case 'relation':\n return attributes.relationToSchema(attribute);\n case 'password':\n case 'text':\n case 'richtext':\n case 'string':\n return attributes.stringToSchema(attribute);\n case 'time':\n return attributes.timeToSchema(attribute);\n case 'timestamp':\n return attributes.timestampToSchema(attribute);\n case 'uid':\n return attributes.uidToSchema(attribute);\n default: {\n const { type } = attribute as Schema.Attribute.AnyAttribute;\n\n throw new Error(`Unsupported attribute type: ${type}`);\n }\n }\n};\n\n/**\n * Maps a Strapi attribute definition to a corresponding Zod input validation schema.\n *\n * This function handles every Strapi attribute types and converts them into\n * appropriate Zod validation schemas with their respective constraints.\n *\n * @param attribute - The Strapi attribute configuration object. Contains type information\n * and validation rules for the attribute.\n *\n * @returns A Zod schema that corresponds to the input attribute's type and validation rules\n *\n * @example\n * ```typescript\n * // String attribute with constraints\n * const stringAttribute = {\n * type: 'string',\n * minLength: 3,\n * maxLength: 50,\n * required: true\n * };\n * const stringSchema = mapAttributeToInputSchema(stringAttribute);\n *\n * // Enumeration attribute\n * const enumAttribute = {\n * type: 'enumeration',\n * enum: ['draft', 'published', 'archived']\n * };\n * const enumSchema = mapAttributeToInputSchema(enumAttribute);\n *\n * // Media attribute with multiple files\n * const mediaAttribute = {\n * type: 'media',\n * multiple: true\n * };\n * const mediaSchema = mapAttributeToInputSchema(mediaAttribute);\n * ```\n *\n * @throws {Error} Throws an error if an unsupported attribute type is provided\n *\n */\nexport const mapAttributeToInputSchema = (\n attribute: Schema.Attribute.AnyAttribute\n): z.ZodTypeAny => {\n switch (attribute.type) {\n case 'biginteger':\n return attributes.bigIntegerToInputSchema(attribute);\n case 'blocks':\n return attributes.blocksToInputSchema();\n case 'boolean':\n return attributes.booleanToInputSchema(attribute);\n case 'component':\n return attributes.componentToInputSchema(attribute);\n case 'date':\n return attributes.dateToInputSchema(attribute);\n case 'datetime':\n return attributes.datetimeToInputSchema(attribute);\n case 'decimal':\n return attributes.decimalToInputSchema(attribute);\n case 'dynamiczone':\n return attributes.dynamicZoneToInputSchema(attribute);\n case 'email':\n return attributes.emailToInputSchema(attribute);\n case 'enumeration':\n return attributes.enumerationToInputSchema(attribute);\n case 'float':\n return attributes.floatToInputSchema(attribute);\n case 'integer':\n return attributes.integerToInputSchema(attribute);\n case 'json':\n return attributes.jsonToInputSchema(attribute);\n case 'media':\n return attributes.mediaToInputSchema(attribute);\n case 'relation':\n return attributes.relationToInputSchema(attribute);\n case 'password':\n case 'text':\n case 'richtext':\n case 'string':\n return attributes.textToInputSchema(attribute);\n case 'time':\n return attributes.timeToInputSchema(attribute);\n case 'timestamp':\n return attributes.timestampToInputSchema(attribute);\n case 'uid':\n return attributes.uidToInputSchema(attribute);\n default: {\n const { type } = attribute as Schema.Attribute.AnyAttribute;\n\n throw new Error(`Unsupported attribute type: ${type}`);\n }\n }\n};\n"],"names":["createAttributesSchema","attributes","reduce","acc","name","attribute","extend","mapAttributeToSchema","z","object","createAttributesInputSchema","mapAttributeToInputSchema","type","Error"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAWA;;;;;;;;;;;;;;;;IAiBaA,MAAAA,sBAAAA,GAAyB,CACpCC,UAAAA,GAAAA;AAEA,IAAA,OAAOA,WAAWC,MAAM,CAAC,CAACC,GAAK,EAAA,CAACC,MAAMC,SAAU,CAAA,GAAA;QAC9C,OAAOF,GAAAA,CAAIG,MAAM,CAAC;YAChB,KAAKF,MAAQ,GAAA;AACX,gBAAA,OAAOG,oBAAqBF,CAAAA,SAAAA,CAAAA;AAC9B;AACF,SAAA,CAAA;KACCG,EAAAA,YAAAA,CAAEC,MAAM,CAAC,EAAC,CAAA,CAAA;AACf;AAEA;;;;;;;;;;;;;;;;;IAkBaC,MAAAA,2BAAAA,GAA8B,CACzCT,UAAAA,GAAAA;AAEA,IAAA,OAAOA,WAAWC,MAAM,CAAC,CAACC,GAAK,EAAA,CAACC,MAAMC,SAAU,CA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;QACvC,KAAK,SAAA;YACH,OAAOJ,+BAA+B,CAACI,SAAAA,CAAAA;QACzC,KAAK,MAAA;YACH,OAAOJ,4BAA4B,CAACI,SAAAA,CAAAA;QACtC,KAAK,OAAA;YACH,OAAOJ,6BAA6B,CAACI,SAAAA,CAAAA;QACvC,KAAK,UAAA;YACH,OAAOJ,gCAAgC,CAACI,SAAAA,CAAAA;QAC1C,KAAK,UAAA;QACL,KAAK,MAAA;QACL,KAAK,UAAA;QACL,KAAK,QAAA;YACH,OAAOJ,4BAA4B,CAACI,SAAAA,CAAAA;QACtC,KAAK,MAAA;YACH,OAAOJ,4BAA4B,CAACI,SAAAA,CAAAA;QACtC,KAAK,WAAA;YACH,OAAOJ,iCAAiC,CAACI,SAAAA,CAAAA;QAC3C,KAAK,KAAA;YACH,OAAOJ,2BAA2B,CAACI,SAAAA,CAAAA;AACrC,QAAA;AAAS,YAAA;gBACP,MAAM,EAAEO,IAAI,EAAE,GAAGP,SAAAA;AAEjB,gBAAA,MAAM,IAAIQ,KAAM,CAAA,CAAC,4BAA4B,EAAED,KAAK,CAAC,CAAA;AACvD;AACF;AACF;;;;;;;"}
1
+ {"version":3,"file":"mappers.js","sources":["../../../../src/core-api/routes/validation/mappers.ts"],"sourcesContent":["/**\n * @fileoverview\n * This file contains functions responsible for mapping Strapi attribute definitions to Zod schemas.\n */\n\nimport type { Schema } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n// eslint-disable-next-line import/no-cycle\nimport * as attributes from './attributes';\n\nconst isCustomFieldAttribute = (\n attribute: unknown\n): attribute is { type: 'customField'; customField: string } => {\n return (\n !!attribute &&\n typeof attribute === 'object' &&\n (attribute as any).type === 'customField' &&\n typeof (attribute as any).customField === 'string'\n );\n};\n\n/**\n * Creates a Zod schema for a collection of Strapi attributes.\n *\n * @param attributes - An array of tuples, where each tuple contains the attribute name and its schema definition.\n * @returns A Zod object schema representing the combined attributes.\n *\n * @example\n * ```typescript\n * const myAttributes = [\n * ['title', { type: 'string', required: true }],\n * ['description', { type: 'text' }],\n * ];\n * const schema = createAttributesSchema(myAttributes);\n * // schema will be a Zod object with 'title' and 'description' fields,\n * // each mapped to their respective Zod schemas based on their Strapi attribute types.\n * ```\n */\nexport const createAttributesSchema = (\n attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]\n) => {\n return attributes.reduce((acc, [name, attribute]) => {\n return acc.extend({\n get [name]() {\n return mapAttributeToSchema(attribute);\n },\n });\n }, z.object({}));\n};\n\n/**\n * Creates a Zod input schema for a collection of Strapi attributes.\n * This is typically used for validating incoming data (e.g., from API requests).\n *\n * @param attributes - An array of tuples, where each tuple contains the attribute name and its schema definition.\n * @returns A Zod object schema representing the combined input attributes.\n *\n * @example\n * ```typescript\n * const myInputAttributes = [\n * ['email', { type: 'email', required: true }],\n * ['description', { type: 'text', minLength: 8 }],\n * ];\n * const inputSchema = createAttributesInputSchema(myInputAttributes);\n * // inputSchema will be a Zod object with 'email' and 'description' fields,\n * // mapped to Zod schemas suitable for input validation.\n * ```\n */\nexport const createAttributesInputSchema = (\n attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]\n) => {\n return attributes.reduce((acc, [name, attribute]) => {\n return acc.extend({\n get [name]() {\n return mapAttributeToInputSchema(attribute);\n },\n });\n }, z.object({}));\n};\n\n/**\n * Maps a Strapi attribute definition to a corresponding Zod validation schema.\n *\n * This function handles every Strapi attribute types and converts them into\n * appropriate Zod validation schemas.\n *\n * @param attribute - The Strapi attribute configuration object.\n * @returns A Zod schema that corresponds to the input attribute's type.\n * @throws {Error} Throws an error if an unsupported attribute type is provided.\n *\n * @example\n * ```typescript\n * const stringAttribute = { type: 'string', minLength: 3 };\n * const stringSchema = mapAttributeToSchema(stringAttribute); // Returns a Zod string schema with minLength.\n *\n * const booleanAttribute = { type: 'boolean', default: false };\n * const booleanSchema = mapAttributeToSchema(booleanAttribute); // Returns a Zod boolean schema with a default.\n * ```\n */\nexport const mapAttributeToSchema = (attribute: Schema.Attribute.AnyAttribute): z.ZodTypeAny => {\n switch (attribute.type) {\n case 'biginteger':\n return attributes.bigIntegerToSchema(attribute);\n case 'blocks':\n return attributes.blocksToSchema();\n case 'boolean':\n return attributes.booleanToSchema(attribute);\n case 'component':\n return attributes.componentToSchema(attribute);\n case 'date':\n return attributes.dateToSchema(attribute);\n case 'datetime':\n return attributes.datetimeToSchema(attribute);\n case 'decimal':\n return attributes.decimalToSchema(attribute);\n case 'dynamiczone':\n return attributes.dynamicZoneToSchema(attribute);\n case 'email':\n return attributes.emailToSchema(attribute);\n case 'enumeration':\n return attributes.enumToSchema(attribute);\n case 'float':\n return attributes.floatToSchema(attribute);\n case 'integer':\n return attributes.integerToSchema(attribute);\n case 'json':\n return attributes.jsonToSchema(attribute);\n case 'media':\n return attributes.mediaToSchema(attribute);\n case 'relation':\n return attributes.relationToSchema(attribute);\n case 'password':\n case 'text':\n case 'richtext':\n case 'string':\n return attributes.stringToSchema(attribute);\n case 'time':\n return attributes.timeToSchema(attribute);\n case 'timestamp':\n return attributes.timestampToSchema(attribute);\n case 'uid':\n return attributes.uidToSchema(attribute);\n default: {\n if (isCustomFieldAttribute(attribute)) {\n const attrCF = attribute as { type: 'customField'; customField: string };\n const strapiInstance = global.strapi;\n if (!strapiInstance) {\n throw new Error('Strapi instance not available for custom field conversion');\n }\n\n const customField = strapiInstance.get('custom-fields').get(attrCF.customField);\n if (!customField) {\n throw new Error(`Custom field '${attrCF.customField}' not found`);\n }\n\n // Re-dispatch with the resolved underlying Strapi kind\n return mapAttributeToSchema({ ...attrCF, type: customField.type });\n }\n\n const { type } = attribute as Schema.Attribute.AnyAttribute;\n\n throw new Error(`Unsupported attribute type: ${type}`);\n }\n }\n};\n\n/**\n * Maps a Strapi attribute definition to a corresponding Zod input validation schema.\n *\n * This function handles every Strapi attribute types and converts them into\n * appropriate Zod validation schemas with their respective constraints.\n *\n * @param attribute - The Strapi attribute configuration object. Contains type information\n * and validation rules for the attribute.\n *\n * @returns A Zod schema that corresponds to the input attribute's type and validation rules\n *\n * @example\n * ```typescript\n * // String attribute with constraints\n * const stringAttribute = {\n * type: 'string',\n * minLength: 3,\n * maxLength: 50,\n * required: true\n * };\n * const stringSchema = mapAttributeToInputSchema(stringAttribute);\n *\n * // Enumeration attribute\n * const enumAttribute = {\n * type: 'enumeration',\n * enum: ['draft', 'published', 'archived']\n * };\n * const enumSchema = mapAttributeToInputSchema(enumAttribute);\n *\n * // Media attribute with multiple files\n * const mediaAttribute = {\n * type: 'media',\n * multiple: true\n * };\n * const mediaSchema = mapAttributeToInputSchema(mediaAttribute);\n * ```\n *\n * @throws {Error} Throws an error if an unsupported attribute type is provided\n *\n */\nexport const mapAttributeToInputSchema = (\n attribute: Schema.Attribute.AnyAttribute\n): z.ZodTypeAny => {\n switch (attribute.type) {\n case 'biginteger':\n return attributes.bigIntegerToInputSchema(attribute);\n case 'blocks':\n return attributes.blocksToInputSchema();\n case 'boolean':\n return attributes.booleanToInputSchema(attribute);\n case 'component':\n return attributes.componentToInputSchema(attribute);\n case 'date':\n return attributes.dateToInputSchema(attribute);\n case 'datetime':\n return attributes.datetimeToInputSchema(attribute);\n case 'decimal':\n return attributes.decimalToInputSchema(attribute);\n case 'dynamiczone':\n return attributes.dynamicZoneToInputSchema(attribute);\n case 'email':\n return attributes.emailToInputSchema(attribute);\n case 'enumeration':\n return attributes.enumerationToInputSchema(attribute);\n case 'float':\n return attributes.floatToInputSchema(attribute);\n case 'integer':\n return attributes.integerToInputSchema(attribute);\n case 'json':\n return attributes.jsonToInputSchema(attribute);\n case 'media':\n return attributes.mediaToInputSchema(attribute);\n case 'relation':\n return attributes.relationToInputSchema(attribute);\n case 'password':\n case 'text':\n case 'richtext':\n case 'string':\n return attributes.textToInputSchema(attribute);\n case 'time':\n return attributes.timeToInputSchema(attribute);\n case 'timestamp':\n return attributes.timestampToInputSchema(attribute);\n case 'uid':\n return attributes.uidToInputSchema(attribute);\n default: {\n if (isCustomFieldAttribute(attribute)) {\n const attrCF = attribute as { type: 'customField'; customField: string };\n const strapiInstance = global.strapi;\n if (!strapiInstance) {\n throw new Error('Strapi instance not available for custom field conversion');\n }\n\n const customField = strapiInstance.get('custom-fields').get(attrCF.customField);\n if (!customField) {\n throw new Error(`Custom field '${attrCF.customField}' not found`);\n }\n\n // Re-dispatch with the resolved underlying Strapi kind\n return mapAttributeToInputSchema({ ...attrCF, type: customField.type });\n }\n\n const { type } = attribute as Schema.Attribute.AnyAttribute;\n\n throw new Error(`Unsupported attribute type: ${type}`);\n }\n }\n};\n"],"names":["isCustomFieldAttribute","attribute","type","customField","createAttributesSchema","attributes","reduce","acc","name","extend","mapAttributeToSchema","z","object","createAttributesInputSchema","mapAttributeToInputSchema","attrCF","strapiInstance","global","strapi","Error","get"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAWA,MAAMA,yBAAyB,CAC7BC,SAAAA,GAAAA;AAEA,IAAA,OACE,CAAC,CAACA,SACF,IAAA,OAAOA,cAAc,QACrB,IAACA,SAAkBC,CAAAA,IAAI,KAAK,aAC5B,IAAA,OAAO,SAACD,CAAkBE,WAAW,KAAK,QAAA;AAE9C,CAAA;AAEA;;;;;;;;;;;;;;;;IAiBaC,MAAAA,sBAAAA,GAAyB,CACpCC,UAAAA,GAAAA;AAEA,IAAA,OAAOA,WAAWC,MAAM,CAAC,CAACC,GAAK,EAAA,CAACC,MAAMP,SAAU,CAAA,GAAA;QAC9C,OAAOM,GAAAA,CAAIE,MAAM,CAAC;YAChB,KAAKD,MAAQ,GAAA;AACX,gBAAA,OAAOE,oBAAqBT,CAAAA,SAAAA,CAAAA;AAC9B;AACF,SAAA,CAAA;KACCU,EAAAA,YAAAA,CAAEC,MAAM,CAAC,EAAC,CAAA,CAAA;AACf;AAEA;;;;;;;;;;;;;;;;;IAkBaC,MAAAA,2BAAAA,GAA8B,CACzCR,UAAAA,GAAAA;AAEA,IAAA,OAAOA,WAAWC,MAAM,CAAC,CAACC,GAAK,EAAA,CAACC,MAAMP,SAAU,CAAA,GAAA;QAC9C,OA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,cAAAA,GAAiBC,OAAOC,MAAM;AACpC,oBAAA,IAAI,CAACF,cAAgB,EAAA;AACnB,wBAAA,MAAM,IAAIG,KAAM,CAAA,2DAAA,CAAA;AAClB;oBAEA,MAAMhB,WAAAA,GAAca,eAAeI,GAAG,CAAC,iBAAiBA,GAAG,CAACL,OAAOZ,WAAW,CAAA;AAC9E,oBAAA,IAAI,CAACA,WAAa,EAAA;wBAChB,MAAM,IAAIgB,MAAM,CAAC,cAAc,EAAEJ,MAAOZ,CAAAA,WAAW,CAAC,WAAW,CAAC,CAAA;AAClE;;AAGA,oBAAA,OAAOW,yBAA0B,CAAA;AAAE,wBAAA,GAAGC,MAAM;AAAEb,wBAAAA,IAAAA,EAAMC,YAAYD;AAAK,qBAAA,CAAA;AACvE;gBAEA,MAAM,EAAEA,IAAI,EAAE,GAAGD,SAAAA;AAEjB,gBAAA,MAAM,IAAIkB,KAAAA,CAAM,CAAC,4BAA4B,EAAEjB,IAAM,CAAA,CAAA,CAAA;AACvD;AACF;AACF;;;;;;;"}
@@ -1,6 +1,9 @@
1
1
  import * as z from 'zod/v4';
2
2
  import { uidToSchema, timestampToSchema, timeToSchema, stringToSchema, relationToSchema, mediaToSchema, jsonToSchema, integerToSchema, floatToSchema, enumToSchema, emailToSchema, dynamicZoneToSchema, decimalToSchema, datetimeToSchema, dateToSchema, componentToSchema, booleanToSchema, blocksToSchema, bigIntegerToSchema, uidToInputSchema, timestampToInputSchema, timeToInputSchema, textToInputSchema, relationToInputSchema, mediaToInputSchema, jsonToInputSchema, integerToInputSchema, floatToInputSchema, enumerationToInputSchema, emailToInputSchema, dynamicZoneToInputSchema, decimalToInputSchema, datetimeToInputSchema, dateToInputSchema, componentToInputSchema, booleanToInputSchema, blocksToInputSchema, bigIntegerToInputSchema } from './attributes.mjs';
3
3
 
4
+ const isCustomFieldAttribute = (attribute)=>{
5
+ return !!attribute && typeof attribute === 'object' && attribute.type === 'customField' && typeof attribute.customField === 'string';
6
+ };
4
7
  /**
5
8
  * Creates a Zod schema for a collection of Strapi attributes.
6
9
  *
@@ -115,6 +118,22 @@ import { uidToSchema, timestampToSchema, timeToSchema, stringToSchema, relationT
115
118
  return uidToSchema(attribute);
116
119
  default:
117
120
  {
121
+ if (isCustomFieldAttribute(attribute)) {
122
+ const attrCF = attribute;
123
+ const strapiInstance = global.strapi;
124
+ if (!strapiInstance) {
125
+ throw new Error('Strapi instance not available for custom field conversion');
126
+ }
127
+ const customField = strapiInstance.get('custom-fields').get(attrCF.customField);
128
+ if (!customField) {
129
+ throw new Error(`Custom field '${attrCF.customField}' not found`);
130
+ }
131
+ // Re-dispatch with the resolved underlying Strapi kind
132
+ return mapAttributeToSchema({
133
+ ...attrCF,
134
+ type: customField.type
135
+ });
136
+ }
118
137
  const { type } = attribute;
119
138
  throw new Error(`Unsupported attribute type: ${type}`);
120
139
  }
@@ -204,6 +223,22 @@ import { uidToSchema, timestampToSchema, timeToSchema, stringToSchema, relationT
204
223
  return uidToInputSchema(attribute);
205
224
  default:
206
225
  {
226
+ if (isCustomFieldAttribute(attribute)) {
227
+ const attrCF = attribute;
228
+ const strapiInstance = global.strapi;
229
+ if (!strapiInstance) {
230
+ throw new Error('Strapi instance not available for custom field conversion');
231
+ }
232
+ const customField = strapiInstance.get('custom-fields').get(attrCF.customField);
233
+ if (!customField) {
234
+ throw new Error(`Custom field '${attrCF.customField}' not found`);
235
+ }
236
+ // Re-dispatch with the resolved underlying Strapi kind
237
+ return mapAttributeToInputSchema({
238
+ ...attrCF,
239
+ type: customField.type
240
+ });
241
+ }
207
242
  const { type } = attribute;
208
243
  throw new Error(`Unsupported attribute type: ${type}`);
209
244
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mappers.mjs","sources":["../../../../src/core-api/routes/validation/mappers.ts"],"sourcesContent":["/**\n * @fileoverview\n * This file contains functions responsible for mapping Strapi attribute definitions to Zod schemas.\n */\n\nimport type { Schema } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n// eslint-disable-next-line import/no-cycle\nimport * as attributes from './attributes';\n\n/**\n * Creates a Zod schema for a collection of Strapi attributes.\n *\n * @param attributes - An array of tuples, where each tuple contains the attribute name and its schema definition.\n * @returns A Zod object schema representing the combined attributes.\n *\n * @example\n * ```typescript\n * const myAttributes = [\n * ['title', { type: 'string', required: true }],\n * ['description', { type: 'text' }],\n * ];\n * const schema = createAttributesSchema(myAttributes);\n * // schema will be a Zod object with 'title' and 'description' fields,\n * // each mapped to their respective Zod schemas based on their Strapi attribute types.\n * ```\n */\nexport const createAttributesSchema = (\n attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]\n) => {\n return attributes.reduce((acc, [name, attribute]) => {\n return acc.extend({\n get [name]() {\n return mapAttributeToSchema(attribute);\n },\n });\n }, z.object({}));\n};\n\n/**\n * Creates a Zod input schema for a collection of Strapi attributes.\n * This is typically used for validating incoming data (e.g., from API requests).\n *\n * @param attributes - An array of tuples, where each tuple contains the attribute name and its schema definition.\n * @returns A Zod object schema representing the combined input attributes.\n *\n * @example\n * ```typescript\n * const myInputAttributes = [\n * ['email', { type: 'email', required: true }],\n * ['description', { type: 'text', minLength: 8 }],\n * ];\n * const inputSchema = createAttributesInputSchema(myInputAttributes);\n * // inputSchema will be a Zod object with 'email' and 'description' fields,\n * // mapped to Zod schemas suitable for input validation.\n * ```\n */\nexport const createAttributesInputSchema = (\n attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]\n) => {\n return attributes.reduce((acc, [name, attribute]) => {\n return acc.extend({\n get [name]() {\n return mapAttributeToInputSchema(attribute);\n },\n });\n }, z.object({}));\n};\n\n/**\n * Maps a Strapi attribute definition to a corresponding Zod validation schema.\n *\n * This function handles every Strapi attribute types and converts them into\n * appropriate Zod validation schemas.\n *\n * @param attribute - The Strapi attribute configuration object.\n * @returns A Zod schema that corresponds to the input attribute's type.\n * @throws {Error} Throws an error if an unsupported attribute type is provided.\n *\n * @example\n * ```typescript\n * const stringAttribute = { type: 'string', minLength: 3 };\n * const stringSchema = mapAttributeToSchema(stringAttribute); // Returns a Zod string schema with minLength.\n *\n * const booleanAttribute = { type: 'boolean', default: false };\n * const booleanSchema = mapAttributeToSchema(booleanAttribute); // Returns a Zod boolean schema with a default.\n * ```\n */\nexport const mapAttributeToSchema = (attribute: Schema.Attribute.AnyAttribute): z.ZodTypeAny => {\n switch (attribute.type) {\n case 'biginteger':\n return attributes.bigIntegerToSchema(attribute);\n case 'blocks':\n return attributes.blocksToSchema();\n case 'boolean':\n return attributes.booleanToSchema(attribute);\n case 'component':\n return attributes.componentToSchema(attribute);\n case 'date':\n return attributes.dateToSchema(attribute);\n case 'datetime':\n return attributes.datetimeToSchema(attribute);\n case 'decimal':\n return attributes.decimalToSchema(attribute);\n case 'dynamiczone':\n return attributes.dynamicZoneToSchema(attribute);\n case 'email':\n return attributes.emailToSchema(attribute);\n case 'enumeration':\n return attributes.enumToSchema(attribute);\n case 'float':\n return attributes.floatToSchema(attribute);\n case 'integer':\n return attributes.integerToSchema(attribute);\n case 'json':\n return attributes.jsonToSchema(attribute);\n case 'media':\n return attributes.mediaToSchema(attribute);\n case 'relation':\n return attributes.relationToSchema(attribute);\n case 'password':\n case 'text':\n case 'richtext':\n case 'string':\n return attributes.stringToSchema(attribute);\n case 'time':\n return attributes.timeToSchema(attribute);\n case 'timestamp':\n return attributes.timestampToSchema(attribute);\n case 'uid':\n return attributes.uidToSchema(attribute);\n default: {\n const { type } = attribute as Schema.Attribute.AnyAttribute;\n\n throw new Error(`Unsupported attribute type: ${type}`);\n }\n }\n};\n\n/**\n * Maps a Strapi attribute definition to a corresponding Zod input validation schema.\n *\n * This function handles every Strapi attribute types and converts them into\n * appropriate Zod validation schemas with their respective constraints.\n *\n * @param attribute - The Strapi attribute configuration object. Contains type information\n * and validation rules for the attribute.\n *\n * @returns A Zod schema that corresponds to the input attribute's type and validation rules\n *\n * @example\n * ```typescript\n * // String attribute with constraints\n * const stringAttribute = {\n * type: 'string',\n * minLength: 3,\n * maxLength: 50,\n * required: true\n * };\n * const stringSchema = mapAttributeToInputSchema(stringAttribute);\n *\n * // Enumeration attribute\n * const enumAttribute = {\n * type: 'enumeration',\n * enum: ['draft', 'published', 'archived']\n * };\n * const enumSchema = mapAttributeToInputSchema(enumAttribute);\n *\n * // Media attribute with multiple files\n * const mediaAttribute = {\n * type: 'media',\n * multiple: true\n * };\n * const mediaSchema = mapAttributeToInputSchema(mediaAttribute);\n * ```\n *\n * @throws {Error} Throws an error if an unsupported attribute type is provided\n *\n */\nexport const mapAttributeToInputSchema = (\n attribute: Schema.Attribute.AnyAttribute\n): z.ZodTypeAny => {\n switch (attribute.type) {\n case 'biginteger':\n return attributes.bigIntegerToInputSchema(attribute);\n case 'blocks':\n return attributes.blocksToInputSchema();\n case 'boolean':\n return attributes.booleanToInputSchema(attribute);\n case 'component':\n return attributes.componentToInputSchema(attribute);\n case 'date':\n return attributes.dateToInputSchema(attribute);\n case 'datetime':\n return attributes.datetimeToInputSchema(attribute);\n case 'decimal':\n return attributes.decimalToInputSchema(attribute);\n case 'dynamiczone':\n return attributes.dynamicZoneToInputSchema(attribute);\n case 'email':\n return attributes.emailToInputSchema(attribute);\n case 'enumeration':\n return attributes.enumerationToInputSchema(attribute);\n case 'float':\n return attributes.floatToInputSchema(attribute);\n case 'integer':\n return attributes.integerToInputSchema(attribute);\n case 'json':\n return attributes.jsonToInputSchema(attribute);\n case 'media':\n return attributes.mediaToInputSchema(attribute);\n case 'relation':\n return attributes.relationToInputSchema(attribute);\n case 'password':\n case 'text':\n case 'richtext':\n case 'string':\n return attributes.textToInputSchema(attribute);\n case 'time':\n return attributes.timeToInputSchema(attribute);\n case 'timestamp':\n return attributes.timestampToInputSchema(attribute);\n case 'uid':\n return attributes.uidToInputSchema(attribute);\n default: {\n const { type } = attribute as Schema.Attribute.AnyAttribute;\n\n throw new Error(`Unsupported attribute type: ${type}`);\n }\n }\n};\n"],"names":["createAttributesSchema","attributes","reduce","acc","name","attribute","extend","mapAttributeToSchema","z","object","createAttributesInputSchema","mapAttributeToIn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;;;;"}
1
+ {"version":3,"file":"mappers.mjs","sources":["../../../../src/core-api/routes/validation/mappers.ts"],"sourcesContent":["/**\n * @fileoverview\n * This file contains functions responsible for mapping Strapi attribute definitions to Zod schemas.\n */\n\nimport type { Schema } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n// eslint-disable-next-line import/no-cycle\nimport * as attributes from './attributes';\n\nconst isCustomFieldAttribute = (\n attribute: unknown\n): attribute is { type: 'customField'; customField: string } => {\n return (\n !!attribute &&\n typeof attribute === 'object' &&\n (attribute as any).type === 'customField' &&\n typeof (attribute as any).customField === 'string'\n );\n};\n\n/**\n * Creates a Zod schema for a collection of Strapi attributes.\n *\n * @param attributes - An array of tuples, where each tuple contains the attribute name and its schema definition.\n * @returns A Zod object schema representing the combined attributes.\n *\n * @example\n * ```typescript\n * const myAttributes = [\n * ['title', { type: 'string', required: true }],\n * ['description', { type: 'text' }],\n * ];\n * const schema = createAttributesSchema(myAttributes);\n * // schema will be a Zod object with 'title' and 'description' fields,\n * // each mapped to their respective Zod schemas based on their Strapi attribute types.\n * ```\n */\nexport const createAttributesSchema = (\n attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]\n) => {\n return attributes.reduce((acc, [name, attribute]) => {\n return acc.extend({\n get [name]() {\n return mapAttributeToSchema(attribute);\n },\n });\n }, z.object({}));\n};\n\n/**\n * Creates a Zod input schema for a collection of Strapi attributes.\n * This is typically used for validating incoming data (e.g., from API requests).\n *\n * @param attributes - An array of tuples, where each tuple contains the attribute name and its schema definition.\n * @returns A Zod object schema representing the combined input attributes.\n *\n * @example\n * ```typescript\n * const myInputAttributes = [\n * ['email', { type: 'email', required: true }],\n * ['description', { type: 'text', minLength: 8 }],\n * ];\n * const inputSchema = createAttributesInputSchema(myInputAttributes);\n * // inputSchema will be a Zod object with 'email' and 'description' fields,\n * // mapped to Zod schemas suitable for input validation.\n * ```\n */\nexport const createAttributesInputSchema = (\n attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]\n) => {\n return attributes.reduce((acc, [name, attribute]) => {\n return acc.extend({\n get [name]() {\n return mapAttributeToInputSchema(attribute);\n },\n });\n }, z.object({}));\n};\n\n/**\n * Maps a Strapi attribute definition to a corresponding Zod validation schema.\n *\n * This function handles every Strapi attribute types and converts them into\n * appropriate Zod validation schemas.\n *\n * @param attribute - The Strapi attribute configuration object.\n * @returns A Zod schema that corresponds to the input attribute's type.\n * @throws {Error} Throws an error if an unsupported attribute type is provided.\n *\n * @example\n * ```typescript\n * const stringAttribute = { type: 'string', minLength: 3 };\n * const stringSchema = mapAttributeToSchema(stringAttribute); // Returns a Zod string schema with minLength.\n *\n * const booleanAttribute = { type: 'boolean', default: false };\n * const booleanSchema = mapAttributeToSchema(booleanAttribute); // Returns a Zod boolean schema with a default.\n * ```\n */\nexport const mapAttributeToSchema = (attribute: Schema.Attribute.AnyAttribute): z.ZodTypeAny => {\n switch (attribute.type) {\n case 'biginteger':\n return attributes.bigIntegerToSchema(attribute);\n case 'blocks':\n return attributes.blocksToSchema();\n case 'boolean':\n return attributes.booleanToSchema(attribute);\n case 'component':\n return attributes.componentToSchema(attribute);\n case 'date':\n return attributes.dateToSchema(attribute);\n case 'datetime':\n return attributes.datetimeToSchema(attribute);\n case 'decimal':\n return attributes.decimalToSchema(attribute);\n case 'dynamiczone':\n return attributes.dynamicZoneToSchema(attribute);\n case 'email':\n return attributes.emailToSchema(attribute);\n case 'enumeration':\n return attributes.enumToSchema(attribute);\n case 'float':\n return attributes.floatToSchema(attribute);\n case 'integer':\n return attributes.integerToSchema(attribute);\n case 'json':\n return attributes.jsonToSchema(attribute);\n case 'media':\n return attributes.mediaToSchema(attribute);\n case 'relation':\n return attributes.relationToSchema(attribute);\n case 'password':\n case 'text':\n case 'richtext':\n case 'string':\n return attributes.stringToSchema(attribute);\n case 'time':\n return attributes.timeToSchema(attribute);\n case 'timestamp':\n return attributes.timestampToSchema(attribute);\n case 'uid':\n return attributes.uidToSchema(attribute);\n default: {\n if (isCustomFieldAttribute(attribute)) {\n const attrCF = attribute as { type: 'customField'; customField: string };\n const strapiInstance = global.strapi;\n if (!strapiInstance) {\n throw new Error('Strapi instance not available for custom field conversion');\n }\n\n const customField = strapiInstance.get('custom-fields').get(attrCF.customField);\n if (!customField) {\n throw new Error(`Custom field '${attrCF.customField}' not found`);\n }\n\n // Re-dispatch with the resolved underlying Strapi kind\n return mapAttributeToSchema({ ...attrCF, type: customField.type });\n }\n\n const { type } = attribute as Schema.Attribute.AnyAttribute;\n\n throw new Error(`Unsupported attribute type: ${type}`);\n }\n }\n};\n\n/**\n * Maps a Strapi attribute definition to a corresponding Zod input validation schema.\n *\n * This function handles every Strapi attribute types and converts them into\n * appropriate Zod validation schemas with their respective constraints.\n *\n * @param attribute - The Strapi attribute configuration object. Contains type information\n * and validation rules for the attribute.\n *\n * @returns A Zod schema that corresponds to the input attribute's type and validation rules\n *\n * @example\n * ```typescript\n * // String attribute with constraints\n * const stringAttribute = {\n * type: 'string',\n * minLength: 3,\n * maxLength: 50,\n * required: true\n * };\n * const stringSchema = mapAttributeToInputSchema(stringAttribute);\n *\n * // Enumeration attribute\n * const enumAttribute = {\n * type: 'enumeration',\n * enum: ['draft', 'published', 'archived']\n * };\n * const enumSchema = mapAttributeToInputSchema(enumAttribute);\n *\n * // Media attribute with multiple files\n * const mediaAttribute = {\n * type: 'media',\n * multiple: true\n * };\n * const mediaSchema = mapAttributeToInputSchema(mediaAttribute);\n * ```\n *\n * @throws {Error} Throws an error if an unsupported attribute type is provided\n *\n */\nexport const mapAttributeToInputSchema = (\n attribute: Schema.Attribute.AnyAttribute\n): z.ZodTypeAny => {\n switch (attribute.type) {\n case 'biginteger':\n return attributes.bigIntegerToInputSchema(attribute);\n case 'blocks':\n return attributes.blocksToInputSchema();\n case 'boolean':\n return attributes.booleanToInputSchema(attribute);\n case 'component':\n return attributes.componentToInputSchema(attribute);\n case 'date':\n return attributes.dateToInputSchema(attribute);\n case 'datetime':\n return attributes.datetimeToInputSchema(attribute);\n case 'decimal':\n return attributes.decimalToInputSchema(attribute);\n case 'dynamiczone':\n return attributes.dynamicZoneToInputSchema(attribute);\n case 'email':\n return attributes.emailToInputSchema(attribute);\n case 'enumeration':\n return attributes.enumerationToInputSchema(attribute);\n case 'float':\n return attributes.floatToInputSchema(attribute);\n case 'integer':\n return attributes.integerToInputSchema(attribute);\n case 'json':\n return attributes.jsonToInputSchema(attribute);\n case 'media':\n return attributes.mediaToInputSchema(attribute);\n case 'relation':\n return attributes.relationToInputSchema(attribute);\n case 'password':\n case 'text':\n case 'richtext':\n case 'string':\n return attributes.textToInputSchema(attribute);\n case 'time':\n return attributes.timeToInputSchema(attribute);\n case 'timestamp':\n return attributes.timestampToInputSchema(attribute);\n case 'uid':\n return attributes.uidToInputSchema(attribute);\n default: {\n if (isCustomFieldAttribute(attribute)) {\n const attrCF = attribute as { type: 'customField'; customField: string };\n const strapiInstance = global.strapi;\n if (!strapiInstance) {\n throw new Error('Strapi instance not available for custom field conversion');\n }\n\n const customField = strapiInstance.get('custom-fields').get(attrCF.customField);\n if (!customField) {\n throw new Error(`Custom field '${attrCF.customField}' not found`);\n }\n\n // Re-dispatch with the resolved underlying Strapi kind\n return mapAttributeToInputSchema({ ...attrCF, type: customField.type });\n }\n\n const { type } = attribute as Schema.Attribute.AnyAttribute;\n\n throw new Error(`Unsupported attribute type: ${type}`);\n }\n }\n};\n"],"names":["isCustomFieldAttribute","attribute","type","customField","createAttributesSchema","attributes","reduce","acc","name","extend","mapAttributeToSchema","z","object","createAttributesInputSchema","mapAttributeToInputSchema","attrCF","strapiInstance","global","strapi","Error","get"],"mappings":";;;AAWA,MAAMA,yBAAyB,CAC7BC,SAAAA,GAAAA;AAEA,IAAA,OACE,CAAC,CAACA,SACF,IAAA,OAAOA,cAAc,QACrB,IAACA,SAAkBC,CAAAA,IAAI,KAAK,aAC5B,IAAA,OAAO,SAACD,CAAkBE,WAAW,KAAK,QAAA;AAE9C,CAAA;AAEA;;;;;;;;;;;;;;;;IAiBaC,MAAAA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AAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,qBAAqB,OAAQ,SAAS,GAAG,CAAC,MAAM,UAAU,EAAE,OAAO,SAsB/E,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,kBAAkB,OAAQ,SAAS,GAAG,CAAC,MAAM,YAAY,MAAM,EAAE,OAAO,kFAmCpF,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/core-api/routes/validation/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAI5B;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,qBAAqB,OAAQ,SAAS,GAAG,CAAC,MAAM,UAAU,EAAE,OAAO,SAyB/E,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,kBAAkB,OAAQ,SAAS,GAAG,CAAC,MAAM,YAAY,MAAM,EAAE,OAAO,kFA0DpF,CAAC"}
@@ -22,6 +22,7 @@ function _interopNamespaceDefault(e) {
22
22
 
23
23
  var z__namespace = /*#__PURE__*/_interopNamespaceDefault(z);
24
24
 
25
+ // Schema generation happens on-demand when schemas don't exist in the registry
25
26
  /**
26
27
  * Safely adds or updates a schema in Zod's global registry.
27
28
  *
@@ -39,13 +40,13 @@ var z__namespace = /*#__PURE__*/_interopNamespaceDefault(z);
39
40
  try {
40
41
  const { _idmap: idMap } = z__namespace.globalRegistry;
41
42
  const transformedId = strapiUtils.transformUidToValidOpenApiName(id);
42
- if (idMap.has(transformedId)) {
43
+ const isReplacing = idMap.has(transformedId);
44
+ if (isReplacing) {
43
45
  // Remove existing schema to prevent conflicts
44
- strapi.log.debug(`Removing existing schema ${transformedId} from registry`);
45
46
  idMap.delete(transformedId);
46
47
  }
47
48
  // Register the new schema with the transformed ID
48
- strapi.log.debug(`Registering schema ${transformedId} in global registry`);
49
+ strapi.log.debug(`${isReplacing ? 'Replacing' : 'Registering'} schema ${transformedId} in global registry`);
49
50
  z__namespace.globalRegistry.add(schema, {
50
51
  id: transformedId
51
52
  });
@@ -88,10 +89,20 @@ var z__namespace = /*#__PURE__*/_interopNamespaceDefault(z);
88
89
  // Return existing schema if already registered
89
90
  const mapItem = idMap.get(transformedId);
90
91
  if (mapItem) {
91
- strapi.log.debug(`Schema ${transformedId} found in registry, returning existing schema`);
92
+ // Schema already exists, return it silently
92
93
  return mapItem;
93
94
  }
94
- strapi.log.warn(`Schema ${transformedId} not found in global registry, creating an any placeholder`);
95
+ strapi.log.debug(`Schema ${transformedId} not found in registry, generating new schema`);
96
+ // Determine if this is a built-in schema or user content
97
+ const isBuiltInSchema = id.startsWith('plugin::') || id.startsWith('admin');
98
+ if (isBuiltInSchema) {
99
+ // Built-in schemas keep at debug level to avoid clutter
100
+ strapi.log.debug(`Initializing validation schema for ${transformedId}`);
101
+ } else {
102
+ // User content
103
+ const schemaName = transformedId.replace('Document', '').replace('Entry', '').replace(/([A-Z])/g, ' $1').trim();
104
+ strapi.log.debug(`📝 Generating validation schema for "${schemaName}"`);
105
+ }
95
106
  // Temporary any placeholder before replacing with the actual schema type
96
107
  // Used to prevent infinite loops in cyclical data structures
97
108
  safeGlobalRegistrySet(id, z__namespace.any());
@@ -99,7 +110,12 @@ var z__namespace = /*#__PURE__*/_interopNamespaceDefault(z);
99
110
  const schema = callback();
100
111
  // Replace the placeholder with the real schema
101
112
  safeGlobalRegistrySet(id, schema);
102
- strapi.log.debug(`Schema ${transformedId} successfully created and registered`);
113
+ // Show completion for user content only
114
+ if (!isBuiltInSchema) {
115
+ const fieldCount = Object.keys(schema?._def?.shape || {}).length || 0;
116
+ const schemaName = transformedId.replace('Document', '').replace('Entry', '').replace(/([A-Z])/g, ' $1').trim();
117
+ strapi.log.debug(` ✅ "${schemaName}" schema created with ${fieldCount} fields`);
118
+ }
103
119
  return schema;
104
120
  } catch (error) {
105
121
  strapi.log.error(`Schema creation failed: Failed to create schema ${id}`);
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../../../../src/core-api/routes/validation/utils.ts"],"sourcesContent":["import { transformUidToValidOpenApiName } from '@strapi/utils';\nimport type { Internal } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n/**\n * Safely adds or updates a schema in Zod's global registry.\n *\n * If a schema with the given `id` already exists, it will be removed before adding the new one.\n *\n * This is useful for hot-reloading or preventing issues with cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param schema - The Zod schema to register.\n * @example\n * ```typescript\n * safeGlobalRegistrySet(\"mySchema\", z.object({ name: z.string() }));\n * ```\n */\nexport const safeGlobalRegistrySet = (id: Internal.UID.Schema, schema: z.ZodType) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n if (idMap.has(transformedId)) {\n // Remove existing schema to prevent conflicts\n strapi.log.debug(`Removing existing schema ${transformedId} from registry`);\n idMap.delete(transformedId);\n }\n\n // Register the new schema with the transformed ID\n strapi.log.debug(`Registering schema ${transformedId} in global registry`);\n z.globalRegistry.add(schema, { id: transformedId });\n } catch (error) {\n strapi.log.error(\n `Schema registration failed: Failed to register schema ${id} in global registry`\n );\n\n throw error;\n }\n};\n\n/**\n * Safely creates and registers a Zod schema in the global registry, particularly useful for handling cyclical data structures.\n *\n * If a schema with the given `id` already exists in the global registry, it returns the existing schema.\n *\n * Otherwise, it registers a temporary `z.any()` schema, calls the provided `callback` to create the actual schema,\n * and then replaces the temporary schema with the actual one in the registry.\n *\n * This prevents infinite loops in cases of cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param callback - A function that returns the Zod schema to be created and registered.\n * @returns The created or retrieved Zod schema.\n * @example\n * ```typescript\n * const CategorySchema = safeSchemaCreation(\"Category\", () =>\n * z.object({\n * name: z.string(),\n * products: z.array(safeSchemaCreation(\"Product\", () =>\n * z.object({\n * name: z.string(),\n * category: z.lazy(() => CategorySchema) // Cyclical reference\n * })\n * ))\n * })\n * );\n * ```\n */\nexport const safeSchemaCreation = (id: Internal.UID.Schema, callback: () => z.ZodType) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n // Return existing schema if already registered\n const mapItem = idMap.get(transformedId);\n if (mapItem) {\n strapi.log.debug(`Schema ${transformedId} found in registry, returning existing schema`);\n return mapItem;\n }\n\n strapi.log.warn(\n `Schema ${transformedId} not found in global registry, creating an any placeholder`\n );\n\n // Temporary any placeholder before replacing with the actual schema type\n // Used to prevent infinite loops in cyclical data structures\n safeGlobalRegistrySet(id, z.any());\n\n // Generate the actual schema using the callback\n const schema = callback();\n\n // Replace the placeholder with the real schema\n safeGlobalRegistrySet(id, schema);\n\n strapi.log.debug(`Schema ${transformedId} successfully created and registered`);\n\n return schema;\n } catch (error) {\n strapi.log.error(`Schema creation failed: Failed to create schema ${id}`);\n\n throw error;\n }\n};\n"],"names":["safeGlobalRegistrySet","id","schema","_idmap","idMap","z","globalRegistry","transformedId","transformUidToValidOpenApiName","has","strapi","log","debug","delete","add","error","safeSchemaCreation","callback","mapItem","get","warn","any"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAIA;;;;;;;;;;;;;AAaC,IACM,MAAMA,qBAAwB,GAAA,CAACC,EAAyBC,EAAAA,MAAAA,GAAAA;IAC7D,IAAI;AACF,QAAA,MAAM,EAAEC,MAAQC,EAAAA,KAAK,EAAE,GAAGC,aAAEC,cAAc;AAE1C,QAAA,MAAMC,gBAAgBC,0CAA+BP,CAAAA,EAAAA,CAAAA;QAErD,IAAIG,KAAAA,CAAMK,GAAG,CAACF,aAAgB,CAAA,EAAA;;YAE5BG,MAAOC,CAAAA,GAAG,CAACC,KAAK,CAAC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,MAAAA,CAAAA;QAE1BQ,MAAOC,CAAAA,GAAG,CAACC,KAAK,CAAC,CAAC,OAAO,EAAEL,aAAc,CAAA,oCAAoC,CAAC,CAAA;QAE9E,OAAOL,MAAAA;AACT,KAAA,CAAE,OAAOa,KAAO,EAAA;QACdL,MAAOC,CAAAA,GAAG,CAACI,KAAK,CAAC,CAAC,gDAAgD,EAAEd,GAAG,CAAC,CAAA;QAExE,MAAMc,KAAAA;AACR;AACF;;;;;"}
1
+ {"version":3,"file":"utils.js","sources":["../../../../src/core-api/routes/validation/utils.ts"],"sourcesContent":["import { transformUidToValidOpenApiName } from '@strapi/utils';\nimport type { Internal } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n// Schema generation happens on-demand when schemas don't exist in the registry\n\n/**\n * Safely adds or updates a schema in Zod's global registry.\n *\n * If a schema with the given `id` already exists, it will be removed before adding the new one.\n *\n * This is useful for hot-reloading or preventing issues with cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param schema - The Zod schema to register.\n * @example\n * ```typescript\n * safeGlobalRegistrySet(\"mySchema\", z.object({ name: z.string() }));\n * ```\n */\nexport const safeGlobalRegistrySet = (id: Internal.UID.Schema, schema: z.ZodType) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n const isReplacing = idMap.has(transformedId);\n\n if (isReplacing) {\n // Remove existing schema to prevent conflicts\n idMap.delete(transformedId);\n }\n\n // Register the new schema with the transformed ID\n strapi.log.debug(\n `${isReplacing ? 'Replacing' : 'Registering'} schema ${transformedId} in global registry`\n );\n z.globalRegistry.add(schema, { id: transformedId });\n } catch (error) {\n strapi.log.error(\n `Schema registration failed: Failed to register schema ${id} in global registry`\n );\n\n throw error;\n }\n};\n\n/**\n * Safely creates and registers a Zod schema in the global registry, particularly useful for handling cyclical data structures.\n *\n * If a schema with the given `id` already exists in the global registry, it returns the existing schema.\n *\n * Otherwise, it registers a temporary `z.any()` schema, calls the provided `callback` to create the actual schema,\n * and then replaces the temporary schema with the actual one in the registry.\n *\n * This prevents infinite loops in cases of cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param callback - A function that returns the Zod schema to be created and registered.\n * @returns The created or retrieved Zod schema.\n * @example\n * ```typescript\n * const CategorySchema = safeSchemaCreation(\"Category\", () =>\n * z.object({\n * name: z.string(),\n * products: z.array(safeSchemaCreation(\"Product\", () =>\n * z.object({\n * name: z.string(),\n * category: z.lazy(() => CategorySchema) // Cyclical reference\n * })\n * ))\n * })\n * );\n * ```\n */\nexport const safeSchemaCreation = (id: Internal.UID.Schema, callback: () => z.ZodType) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n // Return existing schema if already registered\n const mapItem = idMap.get(transformedId);\n if (mapItem) {\n // Schema already exists, return it silently\n return mapItem;\n }\n\n strapi.log.debug(`Schema ${transformedId} not found in registry, generating new schema`);\n\n // Determine if this is a built-in schema or user content\n const isBuiltInSchema = id.startsWith('plugin::') || id.startsWith('admin');\n\n if (isBuiltInSchema) {\n // Built-in schemas keep at debug level to avoid clutter\n strapi.log.debug(`Initializing validation schema for ${transformedId}`);\n } else {\n // User content\n const schemaName = transformedId\n .replace('Document', '')\n .replace('Entry', '')\n .replace(/([A-Z])/g, ' $1')\n .trim();\n strapi.log.debug(`📝 Generating validation schema for \"${schemaName}\"`);\n }\n\n // Temporary any placeholder before replacing with the actual schema type\n // Used to prevent infinite loops in cyclical data structures\n safeGlobalRegistrySet(id, z.any());\n\n // Generate the actual schema using the callback\n const schema = callback();\n\n // Replace the placeholder with the real schema\n safeGlobalRegistrySet(id, schema);\n\n // Show completion for user content only\n if (!isBuiltInSchema) {\n const fieldCount = Object.keys((schema as any)?._def?.shape || {}).length || 0;\n const schemaName = transformedId\n .replace('Document', '')\n .replace('Entry', '')\n .replace(/([A-Z])/g, ' $1')\n .trim();\n strapi.log.debug(` \"${schemaName}\" schema created with ${fieldCount} fields`);\n }\n\n return schema;\n } catch (error) {\n strapi.log.error(`Schema creation failed: Failed to create schema ${id}`);\n\n throw error;\n }\n};\n"],"names":["safeGlobalRegistrySet","id","schema","_idmap","idMap","z","globalRegistry","transformedId","transformUidToValidOpenApiName","isReplacing","has","delete","strapi","log","debug","add","error","safeSchemaCreation","callback","mapItem","get","isBuiltInSchema","startsWith","schemaName","replace","trim","any","fieldCount","Object","keys","_def","shape","length"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAIA;AAEA;;;;;;;;;;;;;AAaC,IACM,MAAMA,qBAAwB,GAAA,CAACC,EAAyBC,EAAAA,MAAAA,GAAAA;IAC7D,IAAI;AACF,QAAA,MAAM,EAAEC,MAAQC,EAAAA,KAAK,EAAE,GAAGC,aAAEC,cAAc;AAE1C,QAAA,MAAMC,gBAAgBC,0CAA+BP,CAAAA,EAAAA,CAAAA;QAErD,MAAMQ,WAAAA,GAAcL,KAAMM,CAAAA,GAAG,CAACH,aAAAA,CAAAA;AAE9B,QAAA,IAAIE,WAAa,EAAA;;AAEfL,YAAAA,KAAAA,CAAMO,MAAM,CAACJ,aAAAA,CAAAA;AACf;;AAGAK,QAAAA,MAAAA,CAAOC,GAAG,CAACC,KAAK,CACd,CAAGL,EAAAA,WAAAA,GAAc,WAAc,GAAA,aAAA,CAAc,QAAQ,EAAEF,aAAc,CAAA,mBAAmB,CAAC,CAAA;AAE3FF,QAAAA,YAAAA,CAAEC,cAAc,CAACS,GAAG,CAACb,MAAQ,EAAA;YAAED,EAAIM,EAAAA;AAAc,SAAA,CAAA;AACnD,KAAA,CAAE,OAAOS,KAAO,EAAA;QACdJ,MAAOC,CAAAA,GAAG,CAACG,KAAK,CACd,CAAC,sDAAsD,EAAEf,EAAG,CAAA,mBAAmB,CAAC,CAAA;QAGlF,MAAMe,KAAAA;AACR;AACF;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BC,IACM,MAAMC,kBAAqB,GAAA,CAAChB,EAAyBiB,EAAAA,Q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IAAAA,EAAMC,KAAS,IAAA,EAAIC,CAAAA,CAAAA,MAAM,IAAI,CAAA;AAC7E,YAAA,MAAMT,UAAahB,GAAAA,aAAAA,CAChBiB,OAAO,CAAC,YAAY,EACpBA,CAAAA,CAAAA,OAAO,CAAC,OAAA,EAAS,EACjBA,CAAAA,CAAAA,OAAO,CAAC,UAAA,EAAY,OACpBC,IAAI,EAAA;AACPb,YAAAA,MAAAA,CAAOC,GAAG,CAACC,KAAK,CAAC,CAAC,MAAM,EAAES,UAAAA,CAAW,sBAAsB,EAAEI,UAAW,CAAA,OAAO,CAAC,CAAA;AAClF;QAEA,OAAOzB,MAAAA;AACT,KAAA,CAAE,OAAOc,KAAO,EAAA;AACdJ,QAAAA,MAAAA,CAAOC,GAAG,CAACG,KAAK,CAAC,CAAC,gDAAgD,EAAEf,EAAI,CAAA,CAAA,CAAA;QAExE,MAAMe,KAAAA;AACR;AACF;;;;;"}
@@ -1,6 +1,7 @@
1
1
  import { transformUidToValidOpenApiName } from '@strapi/utils';
2
2
  import * as z from 'zod/v4';
3
3
 
4
+ // Schema generation happens on-demand when schemas don't exist in the registry
4
5
  /**
5
6
  * Safely adds or updates a schema in Zod's global registry.
6
7
  *
@@ -18,13 +19,13 @@ import * as z from 'zod/v4';
18
19
  try {
19
20
  const { _idmap: idMap } = z.globalRegistry;
20
21
  const transformedId = transformUidToValidOpenApiName(id);
21
- if (idMap.has(transformedId)) {
22
+ const isReplacing = idMap.has(transformedId);
23
+ if (isReplacing) {
22
24
  // Remove existing schema to prevent conflicts
23
- strapi.log.debug(`Removing existing schema ${transformedId} from registry`);
24
25
  idMap.delete(transformedId);
25
26
  }
26
27
  // Register the new schema with the transformed ID
27
- strapi.log.debug(`Registering schema ${transformedId} in global registry`);
28
+ strapi.log.debug(`${isReplacing ? 'Replacing' : 'Registering'} schema ${transformedId} in global registry`);
28
29
  z.globalRegistry.add(schema, {
29
30
  id: transformedId
30
31
  });
@@ -67,10 +68,20 @@ import * as z from 'zod/v4';
67
68
  // Return existing schema if already registered
68
69
  const mapItem = idMap.get(transformedId);
69
70
  if (mapItem) {
70
- strapi.log.debug(`Schema ${transformedId} found in registry, returning existing schema`);
71
+ // Schema already exists, return it silently
71
72
  return mapItem;
72
73
  }
73
- strapi.log.warn(`Schema ${transformedId} not found in global registry, creating an any placeholder`);
74
+ strapi.log.debug(`Schema ${transformedId} not found in registry, generating new schema`);
75
+ // Determine if this is a built-in schema or user content
76
+ const isBuiltInSchema = id.startsWith('plugin::') || id.startsWith('admin');
77
+ if (isBuiltInSchema) {
78
+ // Built-in schemas keep at debug level to avoid clutter
79
+ strapi.log.debug(`Initializing validation schema for ${transformedId}`);
80
+ } else {
81
+ // User content
82
+ const schemaName = transformedId.replace('Document', '').replace('Entry', '').replace(/([A-Z])/g, ' $1').trim();
83
+ strapi.log.debug(`📝 Generating validation schema for "${schemaName}"`);
84
+ }
74
85
  // Temporary any placeholder before replacing with the actual schema type
75
86
  // Used to prevent infinite loops in cyclical data structures
76
87
  safeGlobalRegistrySet(id, z.any());
@@ -78,7 +89,12 @@ import * as z from 'zod/v4';
78
89
  const schema = callback();
79
90
  // Replace the placeholder with the real schema
80
91
  safeGlobalRegistrySet(id, schema);
81
- strapi.log.debug(`Schema ${transformedId} successfully created and registered`);
92
+ // Show completion for user content only
93
+ if (!isBuiltInSchema) {
94
+ const fieldCount = Object.keys(schema?._def?.shape || {}).length || 0;
95
+ const schemaName = transformedId.replace('Document', '').replace('Entry', '').replace(/([A-Z])/g, ' $1').trim();
96
+ strapi.log.debug(` ✅ "${schemaName}" schema created with ${fieldCount} fields`);
97
+ }
82
98
  return schema;
83
99
  } catch (error) {
84
100
  strapi.log.error(`Schema creation failed: Failed to create schema ${id}`);
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","sources":["../../../../src/core-api/routes/validation/utils.ts"],"sourcesContent":["import { transformUidToValidOpenApiName } from '@strapi/utils';\nimport type { Internal } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n/**\n * Safely adds or updates a schema in Zod's global registry.\n *\n * If a schema with the given `id` already exists, it will be removed before adding the new one.\n *\n * This is useful for hot-reloading or preventing issues with cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param schema - The Zod schema to register.\n * @example\n * ```typescript\n * safeGlobalRegistrySet(\"mySchema\", z.object({ name: z.string() }));\n * ```\n */\nexport const safeGlobalRegistrySet = (id: Internal.UID.Schema, schema: z.ZodType) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n if (idMap.has(transformedId)) {\n // Remove existing schema to prevent conflicts\n strapi.log.debug(`Removing existing schema ${transformedId} from registry`);\n idMap.delete(transformedId);\n }\n\n // Register the new schema with the transformed ID\n strapi.log.debug(`Registering schema ${transformedId} in global registry`);\n z.globalRegistry.add(schema, { id: transformedId });\n } catch (error) {\n strapi.log.error(\n `Schema registration failed: Failed to register schema ${id} in global registry`\n );\n\n throw error;\n }\n};\n\n/**\n * Safely creates and registers a Zod schema in the global registry, particularly useful for handling cyclical data structures.\n *\n * If a schema with the given `id` already exists in the global registry, it returns the existing schema.\n *\n * Otherwise, it registers a temporary `z.any()` schema, calls the provided `callback` to create the actual schema,\n * and then replaces the temporary schema with the actual one in the registry.\n *\n * This prevents infinite loops in cases of cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param callback - A function that returns the Zod schema to be created and registered.\n * @returns The created or retrieved Zod schema.\n * @example\n * ```typescript\n * const CategorySchema = safeSchemaCreation(\"Category\", () =>\n * z.object({\n * name: z.string(),\n * products: z.array(safeSchemaCreation(\"Product\", () =>\n * z.object({\n * name: z.string(),\n * category: z.lazy(() => CategorySchema) // Cyclical reference\n * })\n * ))\n * })\n * );\n * ```\n */\nexport const safeSchemaCreation = (id: Internal.UID.Schema, callback: () => z.ZodType) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n // Return existing schema if already registered\n const mapItem = idMap.get(transformedId);\n if (mapItem) {\n strapi.log.debug(`Schema ${transformedId} found in registry, returning existing schema`);\n return mapItem;\n }\n\n strapi.log.warn(\n `Schema ${transformedId} not found in global registry, creating an any placeholder`\n );\n\n // Temporary any placeholder before replacing with the actual schema type\n // Used to prevent infinite loops in cyclical data structures\n safeGlobalRegistrySet(id, z.any());\n\n // Generate the actual schema using the callback\n const schema = callback();\n\n // Replace the placeholder with the real schema\n safeGlobalRegistrySet(id, schema);\n\n strapi.log.debug(`Schema ${transformedId} successfully created and registered`);\n\n return schema;\n } catch (error) {\n strapi.log.error(`Schema creation failed: Failed to create schema ${id}`);\n\n throw error;\n }\n};\n"],"names":["safeGlobalRegistrySet","id","schema","_idmap","idMap","z","globalRegistry","transformedId","transformUidToValidOpenApiName","has","strapi","log","debug","delete","add","error","safeSchemaCreation","callback","mapItem","get","warn","any"],"mappings":";;;AAIA;;;;;;;;;;;;;AAaC,IACM,MAAMA,qBAAwB,GAAA,CAACC,EAAyBC,EAAAA,MAAAA,GAAAA;IAC7D,IAAI;AACF,QAAA,MAAM,EAAEC,MAAQC,EAAAA,KAAK,EAAE,GAAGC,EAAEC,cAAc;AAE1C,QAAA,MAAMC,gBAAgBC,8BAA+BP,CAAAA,EAAAA,CAAAA;QAErD,IAAIG,KAAAA,CAAMK,GAAG,CAACF,aAAgB,CAAA,EAAA;;YAE5BG,MAAOC,CAAAA,GAAG,CAACC,KAAK,CAAC,CAAC,yBAAyB,EAAEL,aAAc,CAAA,cAAc,CAAC,CAAA;AAC1EH,YAAAA,KAAAA,CAAMS,MAAM,CAACN,aAAAA,CAAAA;AACf;;QAGAG,MAAOC,CAAAA,GAAG,CAACC,KAAK,CAAC,CAAC,mBAAmB,EAAEL,aAAc,CAAA,mBAAmB,CAAC,CAAA;AACzEF,QAAAA,CAAAA,CAAEC,cAAc,CAACQ,GAAG,CAACZ,MAAQ,EAAA;YAAED,EAAIM,EAAAA;AAAc,SAAA,CAAA;AACnD,KAAA,CAAE,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validation/utils.ts"],"sourcesContent":["import { transformUidToValidOpenApiName } from '@strapi/utils';\nimport type { Internal } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n// Schema generation happens on-demand when schemas don't exist in the registry\n\n/**\n * Safely adds or updates a schema in Zod's global registry.\n *\n * If a schema with the given `id` already exists, it will be removed before adding the new one.\n *\n * This is useful for hot-reloading or preventing issues with cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param schema - The Zod schema to register.\n * @example\n * ```typescript\n * safeGlobalRegistrySet(\"mySchema\", z.object({ name: z.string() }));\n * ```\n */\nexport const safeGlobalRegistrySet = (id: Internal.UID.Schema, schema: z.ZodType) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n const isReplacing = idMap.has(transformedId);\n\n if (isReplacing) {\n // Remove existing schema to prevent conflicts\n idMap.delete(transformedId);\n }\n\n // Register the new schema with the transformed ID\n strapi.log.debug(\n `${isReplacing ? 'Replacing' : 'Registering'} schema ${transformedId} in global registry`\n );\n z.globalRegistry.add(schema, { id: transformedId });\n } catch (error) {\n strapi.log.error(\n `Schema registration failed: Failed to register schema ${id} in global registry`\n );\n\n throw error;\n }\n};\n\n/**\n * Safely creates and registers a Zod schema in the global registry, particularly useful for handling cyclical data structures.\n *\n * If a schema with the given `id` already exists in the global registry, it returns the existing schema.\n *\n * Otherwise, it registers a temporary `z.any()` schema, calls the provided `callback` to create the actual schema,\n * and then replaces the temporary schema with the actual one in the registry.\n *\n * This prevents infinite loops in cases of cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param callback - A function that returns the Zod schema to be created and registered.\n * @returns The created or retrieved Zod schema.\n * @example\n * ```typescript\n * const CategorySchema = safeSchemaCreation(\"Category\", () =>\n * z.object({\n * name: z.string(),\n * products: z.array(safeSchemaCreation(\"Product\", () =>\n * z.object({\n * name: z.string(),\n * category: z.lazy(() => CategorySchema) // Cyclical reference\n * })\n * ))\n * })\n * );\n * ```\n */\nexport const safeSchemaCreation = (id: Internal.UID.Schema, callback: () => z.ZodType) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n // Return existing schema if already registered\n const mapItem = idMap.get(transformedId);\n if (mapItem) {\n // Schema already exists, return it silently\n return mapItem;\n }\n\n strapi.log.debug(`Schema ${transformedId} not found in registry, generating new schema`);\n\n // Determine if this is a built-in schema or user content\n const isBuiltInSchema = id.startsWith('plugin::') || id.startsWith('admin');\n\n if (isBuiltInSchema) {\n // Built-in schemas keep at debug level to avoid clutter\n strapi.log.debug(`Initializing validation schema for ${transformedId}`);\n } else {\n // User content\n const schemaName = transformedId\n .replace('Document', '')\n .replace('Entry', '')\n .replace(/([A-Z])/g, ' $1')\n .trim();\n strapi.log.debug(`📝 Generating validation schema for \"${schemaName}\"`);\n }\n\n // Temporary any placeholder before replacing with the actual schema type\n // Used to prevent infinite loops in cyclical data structures\n safeGlobalRegistrySet(id, z.any());\n\n // Generate the actual schema using the callback\n const schema = callback();\n\n // Replace the placeholder with the real schema\n safeGlobalRegistrySet(id, schema);\n\n // Show completion for user content only\n if (!isBuiltInSchema) {\n const fieldCount = Object.keys((schema as any)?._def?.shape || {}).length || 0;\n const schemaName = transformedId\n .replace('Document', '')\n .replace('Entry', '')\n .replace(/([A-Z])/g, ' $1')\n .trim();\n strapi.log.debug(` \"${schemaName}\" schema created with ${fieldCount} fields`);\n }\n\n return schema;\n } catch (error) {\n strapi.log.error(`Schema creation failed: Failed to create schema ${id}`);\n\n throw error;\n }\n};\n"],"names":["safeGlobalRegistrySet","id","schema","_idmap","idMap","z","globalRegistry","transformedId","transformUidToValidOpenApiName","isReplacing","has","delete","strapi","log","debug","add","error","safeSchemaCreation","callback","mapItem","get","isBuiltInSchema","startsWith","schemaName","replace","trim","any","fieldCount","Object","keys","_def","shape","length"],"mappings":";;;AAIA;AAEA;;;;;;;;;;;;;AAaC,IACM,MAAMA,qBAAwB,GAAA,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AC,CAAA;AAClF;QAEA,OAAOzB,MAAAA;AACT,KAAA,CAAE,OAAOc,KAAO,EAAA;AACdJ,QAAAA,MAAAA,CAAOC,GAAG,CAACG,KAAK,CAAC,CAAC,gDAAgD,EAAEf,EAAI,CAAA,CAAA,CAAA;QAExE,MAAMe,KAAAA;AACR;AACF;;;;"}
@@ -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 {\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":["CollectionTypeService","CoreService","find","params","uid","contentType","fetchParams","getFetchParams","paginationInfo","getPaginationInfo","isPaged","isPagedPagination","pagination","results","strapi","documents","findMany","shouldCount","count","Error","transformPaginationResponse","undefined","findOne","documentId","create","data","update","delete","entries","deletedEntries","length","constructor","createCollectionTypeService"],"mappings":";;;;;AAWO,MAAMA,qBACHC,SAAAA,uBAAAA,CAAAA;AAWR,IAAA,MAAMC,IAAKC,CAAAA,MAAAA,GAAS,EAAE,EAAE;AACtB,QAAA,MAAM,EAAEC,GAAG,EAAE,GAAG,IAAI,CAACC,WAAW;AAEhC,QAAA,MAAMC,WAAc,GAAA,IAAI,CAACC,cAAc,CAACJ,MAAAA,CAAAA;AAExC,QAAA,MAAMK,iBAAiBC,4BAAkBH,CAAAA,WAAAA,CAAAA;QACzC,MAAMI,OAAAA,GAAUC,4BAAkBL,CAAAA,WAAAA,CAAYM,UAAU,CAAA;AAExD,QAAA,MAAMC,UAAU,MAAMC,MAAAA,CAAOC,SAAS,CAACX,GAAAA,CAAAA,CAAKY,QAAQ,CAAC;AACnD,YAAA,GAAGV,WAAW;AACd,YAAA,GAAGE;AACL,SAAA,CAAA;AAEA,QAAA,IAAIS,uBAAYX,WAAc,CAAA,EAAA;AAC5B,YAAA,MAAMY,QAAQ,MAAMJ,MAAAA,CAAOC,SAAS,CAACX,GAAAA,CAAAA,CAAKc,KAAK,CAAC;AAAE,gBAAA,GAAGZ,WAAW;AAAE,gBAAA,GAAGE;AAAe,aAAA,CAA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oB,YAAAA;AACF,SAAA,CAAA;AACF;AAEA,IAAA,MAAMI,OAAOJ,UAAgC,EAAEpB,MAAS,GAAA,EAAE,EAAE;AAC1D,QAAA,MAAM,EAAEC,GAAG,EAAE,GAAG,IAAI,CAACC,WAAW;QAEhC,MAAM,EAAEuB,OAAO,EAAE,GAAG,MAAMd,OAAOC,SAAS,CAACX,GAAKuB,CAAAA,CAAAA,MAAM,CAAC;AACrD,YAAA,GAAG,IAAI,CAACpB,cAAc,CAACJ,MAAO,CAAA;AAC9BoB,YAAAA;AACF,SAAA,CAAA;QAEA,OAAO;AAAEM,YAAAA,cAAAA,EAAgBD,QAAQE;AAAO,SAAA;AAC1C;AAvEAC,IAAAA,WAAAA,CAAY1B,WAAwC,CAAE;QACpD,KAAK,EAAA;QAEL,IAAI,CAACA,WAAW,GAAGA,WAAAA;AACrB;AAoEF;AAEA;;;IAKA,MAAM2B,8BAA8B,CAClC3B,WAAAA,GAAAA;AAEA,IAAA,OAAO,IAAIL,qBAAsBK,CAAAA,WAAAA,CAAAA;AACnC;;;;;"}
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":["CollectionTypeService","CoreService","find","params","uid","contentType","fetchParams","getFetchParams","paginationInfo","getPaginationInfo","isPaged","isPagedPagination","pagination","results","strapi","documents","findMany","shouldCount","count","Error","transformPaginationResponse","undefined","findOne","documentId","create","data","update","delete","entries","deletedEntries","length","createCollectionTypeService"],"mappings":";;;;;AAWO,MAAMA,qBACHC,SAAAA,uBAAAA,CAAAA;AAWR,IAAA,MAAMC,IAAKC,CAAAA,MAAAA,GAAS,EAAE,EAAE;AACtB,QAAA,MAAM,EAAEC,GAAG,EAAE,GAAG,IAAI,CAACC,WAAW;AAEhC,QAAA,MAAMC,WAAc,GAAA,IAAI,CAACC,cAAc,CAACJ,MAAAA,CAAAA;AAExC,QAAA,MAAMK,iBAAiBC,4BAAkBH,CAAAA,WAAAA,CAA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AEhC,OAAOS,MAAAA,CAAOC,SAAS,CAACX,GAAAA,CAAAA,CAAKoB,MAAM,CAAC,IAAI,CAACjB,cAAc,CAACJ,MAAAA,CAAAA,CAAAA;AAC1D;IAEAuB,MAAOH,CAAAA,UAAgC,EAAEpB,MAAS,GAAA;AAAEsB,QAAAA,IAAAA,EAAM;AAAG,KAAC,EAAE;AAC9D,QAAA,MAAM,EAAErB,GAAG,EAAE,GAAG,IAAI,CAACC,WAAW;AAEhC,QAAA,OAAOS,MAAOC,CAAAA,SAAS,CAACX,GAAAA,CAAAA,CAAKsB,MAAM,CAAC;AAClC,YAAA,GAAG,IAAI,CAACnB,cAAc,CAACJ,MAAO,CAAA;AAC9BoB,YAAAA;AACF,SAAA,CAAA;AACF;AAEA,IAAA,MAAMI,OAAOJ,UAAgC,EAAEpB,MAAS,GAAA,EAAE,EAAE;AAC1D,QAAA,MAAM,EAAEC,GAAG,EAAE,GAAG,IAAI,CAACC,WAAW;QAEhC,MAAM,EAAEuB,OAAO,EAAE,GAAG,MAAMd,OAAOC,SAAS,CAACX,GAAKuB,CAAAA,CAAAA,MAAM,CAAC;AACrD,YAAA,GAAG,IAAI,CAACpB,cAAc,CAACJ,MAAO,CAAA;AAC9BoB,YAAAA;AACF,SAAA,CAAA;QAEA,OAAO;AAAEM,YAAAA,cAAAA,EAAgBD,QAAQE;AAAO,SAAA;AAC1C;AAvEA,IAAA,WAAA,CAAYzB,WAAwC,CAAE;QACpD,KAAK,EAAA;QAEL,IAAI,CAACA,WAAW,GAAGA,WAAAA;AACrB;AAoEF;AAEA;;;IAKA,MAAM0B,8BAA8B,CAClC1B,WAAAA,GAAAA;AAEA,IAAA,OAAO,IAAIL,qBAAsBK,CAAAA,WAAAA,CAAAA;AACnC;;;;;"}
@@ -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 {\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":["CollectionTypeService","CoreService","find","params","uid","contentType","fetchParams","getFetchParams","paginationInfo","getPaginationInfo","isPaged","isPagedPagination","pagination","results","strapi","documents","findMany","shouldCount","count","Error","transformPaginationResponse","undefined","findOne","documentId","create","data","update","delete","entries","deletedEntries","length","constructor","createCollectionTypeService"],"mappings":";;;AAWO,MAAMA,qBACHC,SAAAA,WAAAA,CAAAA;AAWR,IAAA,MAAMC,IAAKC,CAAAA,MAAAA,GAAS,EAAE,EAAE;AACtB,QAAA,MAAM,EAAEC,GAAG,EAAE,GAAG,IAAI,CAACC,WAAW;AAEhC,QAAA,MAAMC,WAAc,GAAA,IAAI,CAACC,cAAc,CAACJ,MAAAA,CAAAA;AAExC,QAAA,MAAMK,iBAAiBC,iBAAkBH,CAAAA,WAAAA,CAAAA;QACzC,MAAMI,OAAAA,GAAUC,iBAAkBL,CAAAA,WAAAA,CAAYM,UAAU,CAAA;AAExD,QAAA,MAAMC,UAAU,MAAMC,MAAAA,CAAOC,SAAS,CAACX,GAAAA,CAAAA,CAAKY,QAAQ,CAAC;AACnD,YAAA,GAAGV,WAAW;AACd,YAAA,GAAGE;AACL,SAAA,CAAA;AAEA,QAAA,IAAIS,YAAYX,WAAc,CAAA,EAAA;AAC5B,YAAA,MAAMY,QAAQ,MAAMJ,MAAAA,CAAOC,SAAS,CAACX,GAAAA,CAAAA,CAAKc,KAAK,CAAC;AAAE,gBAAA,GAAGZ,WAAW;AAAE,gBAAA,GAAGE;AAAe,aAAA,CAAA;YAEpF,IAAI,OAAOU,UAAU,QAAU,EAAA;AAC7B,gBAAA,MAAM,IAAIC,KAAM,CAAA,0BAAA,CAAA;AAClB;YAEA,OAAO;AACLN,gBAAAA,OAAAA;gBACAD,UAAYQ,EAAAA,2BAAAA,CAA4BZ,gBAAgBU,KAAOR,EAAAA,OAAAA;AACjE,aAAA;AACF;QAEA,OAAO;AACLG,YAAAA,OAAAA;YACAD,UAAYQ,EAAAA,2BAAAA,CAA4BZ,gBAAgBa,SAAWX,EAAAA,OAAAA;AACrE,SAAA;AACF;AAEAY,I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A;QAEA,OAAO;AAAEM,YAAAA,cAAAA,EAAgBD,QAAQE;AAAO,SAAA;AAC1C;AAvEAC,IAAAA,WAAAA,CAAY1B,WAAwC,CAAE;QACpD,KAAK,EAAA;QAEL,IAAI,CAACA,WAAW,GAAGA,WAAAA;AACrB;AAoEF;AAEA;;;IAKA,MAAM2B,8BAA8B,CAClC3B,WAAAA,GAAAA;AAEA,IAAA,OAAO,IAAIL,qBAAsBK,CAAAA,WAAAA,CAAAA;AACnC;;;;"}
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":["CollectionTypeService","CoreService","find","params","uid","contentType","fetchParams","getFetchParams","paginationInfo","getPaginationInfo","isPaged","isPagedPagination","pagination","results","strapi","documents","findMany","shouldCount","count","Error","transformPaginationResponse","undefined","findOne","documentId","create","data","update","delete","entries","deletedEntries","length","createCollectionTypeService"],"mappings":";;;AAWO,MAAMA,qBACHC,SAAAA,WAAAA,CAAAA;AAWR,IAAA,MAAMC,IAAKC,CAAAA,MAAAA,GAAS,EAAE,EAAE;AACtB,QAAA,MAAM,EAAEC,GAAG,EAAE,GAAG,IAAI,CAACC,WAAW;AAEhC,QAAA,MAAMC,WAAc,GAAA,IAAI,CAACC,cAAc,CAACJ,MAAAA,CAAAA;AAExC,QAAA,MAAMK,iBAAiBC,iBAAkBH,CAAAA,WAAAA,CAAAA;QACzC,MAAMI,OAAAA,GAAUC,iBAAkBL,CAAAA,WAAAA,CAAYM,UAAU,CAAA;AAExD,QAAA,MAAMC,UAAU,MAAMC,MAAAA,CAAOC,SAAS,CAACX,GAAAA,CAAAA,CAAKY,QAAQ,CAAC;AACnD,YAAA,GAAGV,WAAW;AACd,YAAA,GAAGE;AACL,SAAA,CAAA;AAEA,QAAA,IAAIS,YAAYX,WAAc,CAAA,EAAA;AAC5B,YAAA,MAAMY,QAAQ,MAAMJ,MAAAA,CAAOC,SAAS,CAACX,GAAAA,CAAAA,CAA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KsB,MAAM,CAAC;AAClC,YAAA,GAAG,IAAI,CAACnB,cAAc,CAACJ,MAAO,CAAA;AAC9BoB,YAAAA;AACF,SAAA,CAAA;AACF;AAEA,IAAA,MAAMI,OAAOJ,UAAgC,EAAEpB,MAAS,GAAA,EAAE,EAAE;AAC1D,QAAA,MAAM,EAAEC,GAAG,EAAE,GAAG,IAAI,CAACC,WAAW;QAEhC,MAAM,EAAEuB,OAAO,EAAE,GAAG,MAAMd,OAAOC,SAAS,CAACX,GAAKuB,CAAAA,CAAAA,MAAM,CAAC;AACrD,YAAA,GAAG,IAAI,CAACpB,cAAc,CAACJ,MAAO,CAAA;AAC9BoB,YAAAA;AACF,SAAA,CAAA;QAEA,OAAO;AAAEM,YAAAA,cAAAA,EAAgBD,QAAQE;AAAO,SAAA;AAC1C;AAvEA,IAAA,WAAA,CAAYzB,WAAwC,CAAE;QACpD,KAAK,EAAA;QAEL,IAAI,CAACA,WAAW,GAAGA,WAAAA;AACrB;AAoEF;AAEA;;;IAKA,MAAM0B,8BAA8B,CAClC1B,WAAAA,GAAAA;AAEA,IAAA,OAAO,IAAIL,qBAAsBK,CAAAA,WAAAA,CAAAA;AACnC;;;;"}
@@ -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 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":["SingleTypeService","CoreService","getDocumentId","uid","contentType","strapi","db","query","findOne","then","document","documentId","find","params","documents","findFirst","getFetchParams","createOrUpdate","update","create","delete","deletedEntries","entries","length","constructor","createSingleTypeService"],"mappings":";;;;AAGO,MAAMA,iBAA0BC,SAAAA,uBAAAA,CAAAA;AASrC,IAAA,MAAMC,aAAgB,GAAA;AACpB,QAAA,MAAM,EAAEC,GAAG,EAAE,GAAG,IAAI,CAACC,WAAW;AAEhC,QAAA,OAAOC,MAAOC,CAAAA,EAAE,CACbC,KAAK,CAACJ,GAAAA,CAAAA,CACNK,OAAO,EAAA,CACPC,IAAI,CAAC,CAACC,QAAAA,GAAaA,QAAUC,EAAAA,UAAAA,CAAAA;AAClC;AAEA,IAAA,MAAMC,IAAKC,CAAAA,MAAAA,GAAS,EAAE,EAAE;AACtB,QAAA,MAAM,EAAEV,GAAG,EAAE,GAAG,IAAI,CAACC,WAAW;QAEhC,OAAOC,MAAAA,CAAOS,SAAS,CAACX,GAAAA,CAAAA,CAAKY,SAAS,CAAC,IAAI,CAACC,cAAc,CAACH,MAAAA,CAAAA,CAAAA;AAC7D;AAEA,IAAA,MAAMI,cAAeJ,CAAAA,MAAAA,GAAS,EAAE,EAAE;AAChC,QAAA,MAAM,EAAEV,GAAG,EAAE,GAAG,IAAI,CAACC,WAAW;AAEhC,QAAA,MAAMO,UAAa,GAAA,MAAM,IAAI,CAACT,aAAa,EAAA;AAE3C,QAAA,IAAIS,UAAY,EAAA;AACd,YAAA,OAAON,MAAOS,CAAAA,SAAS,CAACX,GAAAA,CAAAA,CAAKe,MAAM,CAAC;AAClC,gBAAA,GAAG,IAAI,CAACF,cAAc,CAACH,MAAO,CAAA;AAC9BF,gBAAAA;AACF,aAAA,CAAA;AACF;QAEA,OAAON,MAAAA,CAAOS,SAAS,CAACX,GAAAA,CAAAA,CAAKgB,MAAM,CAAC,IAAI,CAACH,cAAc,CAACH,MAAAA,CAAAA,CAAAA;AAC1D;AAEA,IAAA,MAAMO,MAAOP,CAAAA,MAAAA,GAAS,EAAE,EAAE;AACxB,QAAA,MAAM,EAAEV,GAAG,EAAE,GAAG,IAAI,CAACC,WAAW;AAEhC,QAAA,MAAMO,UAAa,GAAA,MAAM,IAAI,CAACT,aAAa,EAAA;QAC3C,IAAI,CAACS,YAAY,OAAO;YAAEU,cAAgB,EAAA;AAAE,SAAA;QAE5C,MAAM,EAAEC,OAAO,EAAE,GAAG,MAAMjB,OAAOS,SAAS,CAACX,GAAKiB,CAAAA,CAAAA,MAAM,CAAC;AACrD,YAAA,GAAG,IAAI,CAACJ,cAAc,CAACH,MAAO,CAAA;AAC9BF,YAAAA;AACF,SAAA,CAAA;QAEA,OAAO;AAAEU,YAAAA,cAAAA,EAAgBC,QAAQC;AAAO,SAAA;AAC1C;AAhDAC,IAAAA,WAAAA,CAAYpB,WAAoC,CAAE;QAChD,KAAK,EAAA;QAEL,IAAI,CAACA,WAAW,GAAGA,WAAAA;AACrB;AA6CF;AAEA,MAAMqB,0BAA0B,CAC9BrB,WAAAA,GAAAA;AAEA,IAAA,OAAO,IAAIJ,iBAAkBI,CAAAA,WAAAA,CAAAA;AAC/B;;;;;"}
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":["SingleTypeService","CoreService","getDocumentId","uid","contentType","strapi","db","query","findOne","then","document","documentId","find","params","documents","findFirst","getFetchParams","createOrUpdate","update","create","delete","deletedEntries","entries","length","createSingleTypeService"],"mappings":";;;;AAGO,MAAMA,iBAA0BC,SAAAA,uBAAAA,CAAAA;AASrC,IAAA,MAAMC,aAAgB,GAAA;AACpB,QAAA,MAAM,EAAEC,GAAG,EAAE,GAAG,IAAI,CAACC,WAAW;AAEhC,QAAA,OAAOC,MAAOC,CAAAA,EAAE,CACbC,KAAK,CAACJ,GAAAA,CAAAA,CACNK,OAAO,EAAA,CACPC,IAAI,CAAC,CAACC,QAAAA,GAAaA,QAAUC,EAAAA,UAAAA,CAAAA;AAClC;AAEA,IAAA,MAAMC,IAAKC,CAAAA,MAAAA,GAAS,EAAE,EAAE;AACtB,QAAA,MAAM,EAAEV,GAAG,EAA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AEL,IAAI,CAACA,WAAW,GAAGA,WAAAA;AACrB;AA6CF;AAEA,MAAMoB,0BAA0B,CAC9BpB,WAAAA,GAAAA;AAEA,IAAA,OAAO,IAAIJ,iBAAkBI,CAAAA,WAAAA,CAAAA;AAC/B;;;;;"}
@@ -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 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":["SingleTypeService","CoreService","getDocumentId","uid","contentType","strapi","db","query","findOne","then","document","documentId","find","params","documents","findFirst","getFetchParams","createOrUpdate","update","create","delete","deletedEntries","entries","length","constructor","createSingleTypeService"],"mappings":";;AAGO,MAAMA,iBAA0BC,SAAAA,WAAAA,CAAAA;AASrC,IAAA,MA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gB,EAAA;AAAE,SAAA;QAE5C,MAAM,EAAEC,OAAO,EAAE,GAAG,MAAMjB,OAAOS,SAAS,CAACX,GAAKiB,CAAAA,CAAAA,MAAM,CAAC;AACrD,YAAA,GAAG,IAAI,CAACJ,cAAc,CAACH,MAAO,CAAA;AAC9BF,YAAAA;AACF,SAAA,CAAA;QAEA,OAAO;AAAEU,YAAAA,cAAAA,EAAgBC,QAAQC;AAAO,SAAA;AAC1C;AAhDAC,IAAAA,WAAAA,CAAYpB,WAAoC,CAAE;QAChD,KAAK,EAAA;QAEL,IAAI,CAACA,WAAW,GAAGA,WAAAA;AACrB;AA6CF;AAEA,MAAMqB,0BAA0B,CAC9BrB,WAAAA,GAAAA;AAEA,IAAA,OAAO,IAAIJ,iBAAkBI,CAAAA,WAAAA,CAAAA;AAC/B;;;;"}
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":["SingleTypeService","CoreService","getDocumentId","uid","contentType","strapi","db","query","findOne","then","document","documentId","find","params","documents","findFirst","getFetchParams","createOrUpdate","update","create","delete","deletedEntries","entries","length","createSingleTypeService"],"mappings":";;AAGO,MAAMA,iBAA0BC,SAAAA,WAAAA,CAAAA;AASrC,IAAA,MAAMC,aAAgB,GAAA;AACpB,QAAA,MAAM,EAAEC,GAAG,EAAE,GAAG,IAAI,CAACC,WAAW;AAEhC,QAAA,OAAOC,MAAOC,CAAAA,EAAE,CACbC,KAAK,CAACJ,GAAAA,CAAAA,CACNK,OAAO,EAAA,CACPC,IAAI,CAAC,CAACC,QAAAA,GAAaA,QAAUC,EAAAA,UAAAA,CAAAA;AAClC;AAEA,IAAA,MAAMC,IAAKC,CAAAA,MAAAA,GAAS,EAAE,EAAE;AACtB,QAAA,MAAM,EAAEV,GAAG,EAAE,GAAG,IAAI,CAACC,WAAW;QAEhC,OAAOC,MAAAA,CAAOS,SAAS,CAACX,GAAAA,CAAAA,CAAKY,SAAS,CAAC,IAAI,CAACC,cAAc,CAACH,MAAAA,CAAAA,CAAAA;AAC7D;AAEA,IAAA,MAAMI,cAAeJ,CAAAA,MAAAA,GAAS,EAAE,EAAE;AAChC,QAAA,MAAM,EAAEV,GAAG,EAAE,GAAG,IAAI,CAACC,WAAW;AAEhC,QAAA,MAAMO,UAAa,GAAA,MAAM,IAAI,CAACT,aAAa,EAAA;AAE3C,QAAA,IAAIS,UAAY,EAAA;AACd,YAAA,OAAON,MAAOS,CAAAA,SAAS,CAACX,GAAAA,CAAAA,CAAKe,MAAM,CAAC;AAClC,gBAAA,GAAG,IAAI,CAACF,cAAc,CAACH,MAAO,CAAA;AAC9BF,gBAAAA;AACF,aAAA,CAAA;AACF;QAEA,OAAON,MAAAA,CAAOS,S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