@strapi/core 5.58.0 → 5.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/Strapi.d.ts.map +1 -1
  2. package/dist/Strapi.js +1 -0
  3. package/dist/Strapi.js.map +1 -1
  4. package/dist/Strapi.mjs +1 -0
  5. package/dist/Strapi.mjs.map +1 -1
  6. package/dist/ee/entitlements.d.ts.map +1 -1
  7. package/dist/ee/entitlements.js.map +1 -1
  8. package/dist/ee/entitlements.mjs.map +1 -1
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +1 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/index.mjs +1 -1
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/loaders/apis.d.ts.map +1 -1
  15. package/dist/loaders/apis.js.map +1 -1
  16. package/dist/loaders/apis.mjs.map +1 -1
  17. package/dist/loaders/plugins/get-enabled-plugins.js +2 -2
  18. package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
  19. package/dist/loaders/plugins/get-enabled-plugins.mjs +2 -2
  20. package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
  21. package/dist/middlewares/cors.d.ts.map +1 -1
  22. package/dist/middlewares/cors.js.map +1 -1
  23. package/dist/middlewares/cors.mjs.map +1 -1
  24. package/dist/migrations/database/5.0.0-discard-drafts.js +1 -1
  25. package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
  26. package/dist/migrations/database/5.0.0-discard-drafts.mjs +1 -1
  27. package/dist/migrations/database/5.0.0-discard-drafts.mjs.map +1 -1
  28. package/dist/migrations/first-published-at.js +1 -1
  29. package/dist/migrations/first-published-at.js.map +1 -1
  30. package/dist/migrations/first-published-at.mjs +1 -1
  31. package/dist/migrations/first-published-at.mjs.map +1 -1
  32. package/dist/package.json.js +15 -14
  33. package/dist/package.json.js.map +1 -1
  34. package/dist/package.json.mjs +15 -14
  35. package/dist/package.json.mjs.map +1 -1
  36. package/dist/registries/controllers.d.ts.map +1 -1
  37. package/dist/registries/controllers.js.map +1 -1
  38. package/dist/registries/controllers.mjs.map +1 -1
  39. package/dist/services/content-source-maps.js +6 -6
  40. package/dist/services/content-source-maps.js.map +1 -1
  41. package/dist/services/content-source-maps.mjs +6 -6
  42. package/dist/services/content-source-maps.mjs.map +1 -1
  43. package/dist/services/document-service/components.d.ts +13 -11
  44. package/dist/services/document-service/components.d.ts.map +1 -1
  45. package/dist/services/document-service/components.js +115 -66
  46. package/dist/services/document-service/components.js.map +1 -1
  47. package/dist/services/document-service/components.mjs +116 -67
  48. package/dist/services/document-service/components.mjs.map +1 -1
  49. package/dist/services/document-service/events.d.ts.map +1 -1
  50. package/dist/services/document-service/events.js +5 -1
  51. package/dist/services/document-service/events.js.map +1 -1
  52. package/dist/services/document-service/events.mjs +5 -1
  53. package/dist/services/document-service/events.mjs.map +1 -1
  54. package/dist/services/document-service/repository.d.ts.map +1 -1
  55. package/dist/services/document-service/repository.js +26 -7
  56. package/dist/services/document-service/repository.js.map +1 -1
  57. package/dist/services/document-service/repository.mjs +27 -8
  58. package/dist/services/document-service/repository.mjs.map +1 -1
  59. package/dist/services/document-service/transform/data.d.ts.map +1 -1
  60. package/dist/services/document-service/transform/data.js.map +1 -1
  61. package/dist/services/document-service/transform/data.mjs.map +1 -1
  62. package/dist/services/document-service/transform/relations/transform/default-locale.d.ts +4 -1
  63. package/dist/services/document-service/transform/relations/transform/default-locale.d.ts.map +1 -1
  64. package/dist/services/document-service/transform/relations/transform/default-locale.js +12 -9
  65. package/dist/services/document-service/transform/relations/transform/default-locale.js.map +1 -1
  66. package/dist/services/document-service/transform/relations/transform/default-locale.mjs +12 -10
  67. package/dist/services/document-service/transform/relations/transform/default-locale.mjs.map +1 -1
  68. package/dist/services/document-service/utils/clone-relations.d.ts +21 -4
  69. package/dist/services/document-service/utils/clone-relations.d.ts.map +1 -1
  70. package/dist/services/document-service/utils/clone-relations.js +619 -34
  71. package/dist/services/document-service/utils/clone-relations.js.map +1 -1
  72. package/dist/services/document-service/utils/clone-relations.mjs +619 -36
  73. package/dist/services/document-service/utils/clone-relations.mjs.map +1 -1
  74. package/dist/services/document-service/utils/unidirectional-relations.d.ts +4 -2
  75. package/dist/services/document-service/utils/unidirectional-relations.d.ts.map +1 -1
  76. package/dist/services/document-service/utils/unidirectional-relations.js +1 -10
  77. package/dist/services/document-service/utils/unidirectional-relations.js.map +1 -1
  78. package/dist/services/document-service/utils/unidirectional-relations.mjs +1 -10
  79. package/dist/services/document-service/utils/unidirectional-relations.mjs.map +1 -1
  80. package/dist/services/event-hub.d.ts.map +1 -1
  81. package/dist/services/event-hub.js +23 -5
  82. package/dist/services/event-hub.js.map +1 -1
  83. package/dist/services/event-hub.mjs +23 -5
  84. package/dist/services/event-hub.mjs.map +1 -1
  85. package/dist/services/webhook-store.js +2 -2
  86. package/dist/services/webhook-store.js.map +1 -1
  87. package/dist/services/webhook-store.mjs +2 -2
  88. package/dist/services/webhook-store.mjs.map +1 -1
  89. package/dist/utils/fetch.d.ts.map +1 -1
  90. package/dist/utils/fetch.js +44 -8
  91. package/dist/utils/fetch.js.map +1 -1
  92. package/dist/utils/fetch.mjs +37 -8
  93. package/dist/utils/fetch.mjs.map +1 -1
  94. package/dist/utils/transform-content-types-to-models.js +5 -5
  95. package/dist/utils/transform-content-types-to-models.js.map +1 -1
  96. package/dist/utils/transform-content-types-to-models.mjs +5 -5
  97. package/dist/utils/transform-content-types-to-models.mjs.map +1 -1
  98. package/package.json +15 -14
@@ -1 +1 @@
1
- {"version":3,"file":"webhook-store.js","sources":["../../src/services/webhook-store.ts"],"sourcesContent":["/**\n * Webhook store is the implementation of webhook storage over the core_store\n */\n\nimport { errors } from '@strapi/utils';\nimport type { Model, Database } from '@strapi/database';\nimport type { Modules } from '@strapi/types';\n\nconst { ValidationError } = errors;\n\nconst webhookModel: Model = {\n uid: 'strapi::webhook',\n singularName: 'strapi_webhooks',\n tableName: 'strapi_webhooks',\n attributes: {\n id: {\n type: 'increments',\n },\n name: {\n type: 'string',\n },\n url: {\n type: 'text',\n },\n headers: {\n type: 'json',\n },\n events: {\n type: 'json',\n },\n enabled: {\n type: 'boolean',\n },\n },\n};\n\ntype Webhook = Modules.WebhookStore.Webhook;\ntype DBOutput = Omit<Webhook, 'id' | 'isEnabled'> & { id: string | number; enabled: boolean };\ntype DBInput = Omit<DBOutput, 'id'>;\n\nconst toDBObject = (data: Webhook): DBInput => {\n return {\n name: data.name,\n url: data.url,\n headers: data.headers,\n events: data.events,\n enabled: data.isEnabled,\n };\n};\n\nconst fromDBObject = (row: DBOutput): Webhook => {\n return {\n id: typeof row.id === 'number' ? row.id.toString() : row.id,\n name: row.name,\n url: row.url,\n headers: row.headers,\n events: row.events,\n isEnabled: row.enabled,\n };\n};\n\nconst webhookEventValidator = async (allowedEvents: Map<string, string>, events: string[]) => {\n const allowedValues = Array.from(allowedEvents.values());\n\n events.forEach((event) => {\n if (allowedValues.includes(event)) {\n return;\n }\n\n throw new ValidationError(`Webhook event ${event} is not supported`);\n });\n};\n\nexport interface WebhookStore {\n allowedEvents: Map<string, string>;\n addAllowedEvent(key: string, value: string): void;\n removeAllowedEvent(key: string): void;\n listAllowedEvents(): string[];\n getAllowedEvent(key: string): string | undefined;\n findWebhooks(): Promise<Webhook[]>;\n findWebhook(id: string): Promise<Webhook | null>;\n createWebhook(data: Webhook): Promise<Webhook>;\n updateWebhook(id: string, data: Webhook): Promise<Webhook | null>;\n deleteWebhook(id: string): Promise<Webhook | null>;\n}\n\nconst createWebhookStore = ({ db }: { db: Database }): WebhookStore => {\n return {\n allowedEvents: new Map([\n ['ENTRY_CREATE', 'entry.create'],\n ['ENTRY_UPDATE', 'entry.update'],\n ['ENTRY_DELETE', 'entry.delete'],\n ['ENTRY_PUBLISH', 'entry.publish'],\n ['ENTRY_UNPUBLISH', 'entry.unpublish'],\n ['ENTRY_DRAFT_DISCARD', 'entry.draft-discard'],\n ]),\n addAllowedEvent(key, value) {\n this.allowedEvents.set(key, value);\n },\n removeAllowedEvent(key) {\n this.allowedEvents.delete(key);\n },\n listAllowedEvents() {\n return Array.from(this.allowedEvents.keys());\n },\n getAllowedEvent(key) {\n return this.allowedEvents.get(key);\n },\n async findWebhooks() {\n const results = await db.query('strapi::webhook').findMany();\n\n return results.map(fromDBObject);\n },\n async findWebhook(id) {\n const result = await db.query('strapi::webhook').findOne({ where: { id } });\n return result ? fromDBObject(result) : null;\n },\n async createWebhook(data) {\n await webhookEventValidator(this.allowedEvents, data.events);\n\n return db\n .query('strapi::webhook')\n .create({\n data: toDBObject({ ...data, isEnabled: true }),\n })\n .then(fromDBObject);\n },\n async updateWebhook(id, data) {\n await webhookEventValidator(this.allowedEvents, data.events);\n\n const webhook = await db.query('strapi::webhook').update({\n where: { id },\n data: toDBObject(data),\n });\n\n return webhook ? fromDBObject(webhook) : null;\n },\n async deleteWebhook(id) {\n const webhook = await db.query('strapi::webhook').delete({ where: { id } });\n return webhook ? fromDBObject(webhook) : null;\n },\n };\n};\n\nexport { webhookModel, createWebhookStore };\n"],"names":["ValidationError","errors","webhookModel","uid","singularName","tableName","attributes","id","type","name","url","headers","events","enabled","toDBObject","data","isEnabled","fromDBObject","row","toString","webhookEventValidator","allowedEvents","allowedValues","Array","from","values","forEach","event","includes","createWebhookStore","db","Map","addAllowedEvent","key","value","set","removeAllowedEvent","delete","listAllowedEvents","keys","getAllowedEvent","get","findWebhooks","results","query","findMany","map","findWebhook","result","findOne","where","createWebhook","create","then","updateWebhook","webhook","update","deleteWebhook"],"mappings":";;;;AAQA,MAAM,EAAEA,eAAe,EAAE,GAAGC,kBAAAA;AAE5B,MAAMC,YAAAA,GAAsB;IAC1BC,GAAAA,EAAK,iBAAA;IACLC,YAAAA,EAAc,iBAAA;IACdC,SAAAA,EAAW,iBAAA;IACXC,UAAAA,EAAY;QACVC,EAAAA,EAAI;YACFC,IAAAA,EAAM;AACR,SAAA;QACAC,IAAAA,EAAM;YACJD,IAAAA,EAAM;AACR,SAAA;Q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,EAAAA,CAAGc,KAAK,CAAC,iBAAA,CAAA,CAAmBP,MAAM,CAAC;gBAAEa,KAAAA,EAAO;AAAE3C,oBAAAA;AAAG;AAAE,aAAA,CAAA;YACzE,OAAOgD,OAAAA,GAAUtC,aAAasC,OAAAA,CAAAA,GAAW,IAAA;AAC3C,QAAA;AACF,KAAA;AACF;;;;;"}
1
+ {"version":3,"file":"webhook-store.js","sources":["../../src/services/webhook-store.ts"],"sourcesContent":["/**\n * Webhook store is the implementation of webhook storage over the core_store\n */\n\nimport { errors } from '@strapi/utils';\nimport type { Model, Database } from '@strapi/database';\nimport type { Modules } from '@strapi/types';\n\nconst { ValidationError } = errors;\n\nconst webhookModel: Model = {\n uid: 'strapi::webhook',\n singularName: 'strapi_webhooks',\n tableName: 'strapi_webhooks',\n attributes: {\n id: {\n type: 'increments',\n },\n name: {\n type: 'string',\n },\n url: {\n type: 'text',\n },\n headers: {\n type: 'json',\n },\n events: {\n type: 'json',\n },\n enabled: {\n type: 'boolean',\n },\n },\n};\n\ntype Webhook = Modules.WebhookStore.Webhook;\ntype DBOutput = Omit<Webhook, 'id' | 'isEnabled'> & { id: string | number; enabled: boolean };\ntype DBInput = Omit<DBOutput, 'id'>;\n\nconst toDBObject = (data: Webhook): DBInput => {\n return {\n name: data.name,\n url: data.url,\n headers: data.headers,\n events: data.events,\n enabled: data.isEnabled,\n };\n};\n\nconst fromDBObject = (row: DBOutput): Webhook => {\n return {\n id: typeof row.id === 'number' ? row.id.toString() : row.id,\n name: row.name,\n url: row.url,\n headers: row.headers,\n events: row.events,\n isEnabled: row.enabled,\n };\n};\n\nconst webhookEventValidator = async (allowedEvents: Map<string, string>, events: string[]) => {\n const allowedValues = new Set(Array.from(allowedEvents.values()));\n\n events.forEach((event) => {\n if (allowedValues.has(event)) {\n return;\n }\n\n throw new ValidationError(`Webhook event ${event} is not supported`);\n });\n};\n\nexport interface WebhookStore {\n allowedEvents: Map<string, string>;\n addAllowedEvent(key: string, value: string): void;\n removeAllowedEvent(key: string): void;\n listAllowedEvents(): string[];\n getAllowedEvent(key: string): string | undefined;\n findWebhooks(): Promise<Webhook[]>;\n findWebhook(id: string): Promise<Webhook | null>;\n createWebhook(data: Webhook): Promise<Webhook>;\n updateWebhook(id: string, data: Webhook): Promise<Webhook | null>;\n deleteWebhook(id: string): Promise<Webhook | null>;\n}\n\nconst createWebhookStore = ({ db }: { db: Database }): WebhookStore => {\n return {\n allowedEvents: new Map([\n ['ENTRY_CREATE', 'entry.create'],\n ['ENTRY_UPDATE', 'entry.update'],\n ['ENTRY_DELETE', 'entry.delete'],\n ['ENTRY_PUBLISH', 'entry.publish'],\n ['ENTRY_UNPUBLISH', 'entry.unpublish'],\n ['ENTRY_DRAFT_DISCARD', 'entry.draft-discard'],\n ]),\n addAllowedEvent(key, value) {\n this.allowedEvents.set(key, value);\n },\n removeAllowedEvent(key) {\n this.allowedEvents.delete(key);\n },\n listAllowedEvents() {\n return Array.from(this.allowedEvents.keys());\n },\n getAllowedEvent(key) {\n return this.allowedEvents.get(key);\n },\n async findWebhooks() {\n const results = await db.query('strapi::webhook').findMany();\n\n return results.map(fromDBObject);\n },\n async findWebhook(id) {\n const result = await db.query('strapi::webhook').findOne({ where: { id } });\n return result ? fromDBObject(result) : null;\n },\n async createWebhook(data) {\n await webhookEventValidator(this.allowedEvents, data.events);\n\n return db\n .query('strapi::webhook')\n .create({\n data: toDBObject({ ...data, isEnabled: true }),\n })\n .then(fromDBObject);\n },\n async updateWebhook(id, data) {\n await webhookEventValidator(this.allowedEvents, data.events);\n\n const webhook = await db.query('strapi::webhook').update({\n where: { id },\n data: toDBObject(data),\n });\n\n return webhook ? fromDBObject(webhook) : null;\n },\n async deleteWebhook(id) {\n const webhook = await db.query('strapi::webhook').delete({ where: { id } });\n return webhook ? fromDBObject(webhook) : null;\n },\n };\n};\n\nexport { webhookModel, createWebhookStore };\n"],"names":["ValidationError","errors","webhookModel","uid","singularName","tableName","attributes","id","type","name","url","headers","events","enabled","toDBObject","data","isEnabled","fromDBObject","row","toString","webhookEventValidator","allowedEvents","allowedValues","Set","Array","from","values","forEach","event","has","createWebhookStore","db","Map","addAllowedEvent","key","value","set","removeAllowedEvent","delete","listAllowedEvents","keys","getAllowedEvent","get","findWebhooks","results","query","findMany","map","findWebhook","result","findOne","where","createWebhook","create","then","updateWebhook","webhook","update","deleteWebhook"],"mappings":";;;;AAQA,MAAM,EAAEA,eAAe,EAAE,GAAGC,kBAAAA;AAE5B,MAAMC,YAAAA,GAAsB;IAC1BC,GAAAA,EAAK,iBAAA;IACLC,YAAAA,EAAc,iBAAA;IACdC,SAAAA,EAAW,iBAAA;IACXC,UAAAA,EAAY;QACVC,EAAAA,EAAI;YACFC,IAAAA,EAAM;AACR,SAAA;QACAC,IAAAA,EAAM;YACJD,IAAAA,EAAM;AACR,SAAA;QACAE,GAAAA,EAAK;YACHF,IAAAA,EAAM;AACR,SAAA;QACAG,OAAAA,EAAS;YACPH,IAAAA,EAAM;AACR,SAAA;QACAI,MAAAA,EAAQ;YACNJ,IAAAA,EAAM;AACR,SAAA;QACAK,OAAAA,EAAS;YACPL,IAAAA,EAAM;AACR;AACF;AACF;AAMA,MAAMM,aAAa,CAACC,IAAAA,GAAAA;IAClB,OAAO;AACLN,QAAAA,IAAAA,EAAMM,KAAKN,IAAI;AACfC,QAAAA,GAAAA,EAAKK,KAAKL,GAAG;AACbC,QAAAA,OAAAA,EAASI,KAAKJ,OAAO;AACrBC,QAAAA,MAAAA,EAAQG,KAAKH,MAAM;AACnBC,QAAAA,OAAAA,EAASE,KAAKC;AAChB,KAAA;AACF,CAAA;AAEA,MAAMC,eAAe,CAACC,GAAAA,GAAAA;IACpB,OAAO;QACLX,EAAAA,EAAI,OAAOW,GAAAA,CAAIX,EAAE,KAAK,QAAA,GAAWW,GAAAA,CAAIX,EAAE,CAACY,QAAQ,EAAA,GAAKD,GAAAA,CAAIX,EAAE;AAC3DE,QAAAA,IAAAA,EAAMS,IAAIT,IAAI;AACdC,QAAAA,GAA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AACV,QAAA,CAAA;QACA,MAAMsC,aAAAA,CAAAA,CAAchD,EAAE,EAAEQ,IAAI,EAAA;AAC1B,YAAA,MAAMK,sBAAsB,IAAI,CAACC,aAAa,EAAEN,KAAKH,MAAM,CAAA;AAE3D,YAAA,MAAM4C,UAAU,MAAMzB,EAAAA,CAAGc,KAAK,CAAC,iBAAA,CAAA,CAAmBY,MAAM,CAAC;gBACvDN,KAAAA,EAAO;AAAE5C,oBAAAA;AAAG,iBAAA;AACZQ,gBAAAA,IAAAA,EAAMD,UAAAA,CAAWC,IAAAA;AACnB,aAAA,CAAA;YAEA,OAAOyC,OAAAA,GAAUvC,aAAauC,OAAAA,CAAAA,GAAW,IAAA;AAC3C,QAAA,CAAA;AACA,QAAA,MAAME,eAAcnD,EAAE,EAAA;AACpB,YAAA,MAAMiD,UAAU,MAAMzB,EAAAA,CAAGc,KAAK,CAAC,iBAAA,CAAA,CAAmBP,MAAM,CAAC;gBAAEa,KAAAA,EAAO;AAAE5C,oBAAAA;AAAG;AAAE,aAAA,CAAA;YACzE,OAAOiD,OAAAA,GAAUvC,aAAauC,OAAAA,CAAAA,GAAW,IAAA;AAC3C,QAAA;AACF,KAAA;AACF;;;;;"}
@@ -46,9 +46,9 @@ const fromDBObject = (row)=>{
46
46
  };
47
47
  };
48
48
  const webhookEventValidator = async (allowedEvents, events)=>{
49
- const allowedValues = Array.from(allowedEvents.values());
49
+ const allowedValues = new Set(Array.from(allowedEvents.values()));
50
50
  events.forEach((event)=>{
51
- if (allowedValues.includes(event)) {
51
+ if (allowedValues.has(event)) {
52
52
  return;
53
53
  }
54
54
  throw new ValidationError(`Webhook event ${event} is not supported`);
@@ -1 +1 @@
1
- {"version":3,"file":"webhook-store.mjs","sources":["../../src/services/webhook-store.ts"],"sourcesContent":["/**\n * Webhook store is the implementation of webhook storage over the core_store\n */\n\nimport { errors } from '@strapi/utils';\nimport type { Model, Database } from '@strapi/database';\nimport type { Modules } from '@strapi/types';\n\nconst { ValidationError } = errors;\n\nconst webhookModel: Model = {\n uid: 'strapi::webhook',\n singularName: 'strapi_webhooks',\n tableName: 'strapi_webhooks',\n attributes: {\n id: {\n type: 'increments',\n },\n name: {\n type: 'string',\n },\n url: {\n type: 'text',\n },\n headers: {\n type: 'json',\n },\n events: {\n type: 'json',\n },\n enabled: {\n type: 'boolean',\n },\n },\n};\n\ntype Webhook = Modules.WebhookStore.Webhook;\ntype DBOutput = Omit<Webhook, 'id' | 'isEnabled'> & { id: string | number; enabled: boolean };\ntype DBInput = Omit<DBOutput, 'id'>;\n\nconst toDBObject = (data: Webhook): DBInput => {\n return {\n name: data.name,\n url: data.url,\n headers: data.headers,\n events: data.events,\n enabled: data.isEnabled,\n };\n};\n\nconst fromDBObject = (row: DBOutput): Webhook => {\n return {\n id: typeof row.id === 'number' ? row.id.toString() : row.id,\n name: row.name,\n url: row.url,\n headers: row.headers,\n events: row.events,\n isEnabled: row.enabled,\n };\n};\n\nconst webhookEventValidator = async (allowedEvents: Map<string, string>, events: string[]) => {\n const allowedValues = Array.from(allowedEvents.values());\n\n events.forEach((event) => {\n if (allowedValues.includes(event)) {\n return;\n }\n\n throw new ValidationError(`Webhook event ${event} is not supported`);\n });\n};\n\nexport interface WebhookStore {\n allowedEvents: Map<string, string>;\n addAllowedEvent(key: string, value: string): void;\n removeAllowedEvent(key: string): void;\n listAllowedEvents(): string[];\n getAllowedEvent(key: string): string | undefined;\n findWebhooks(): Promise<Webhook[]>;\n findWebhook(id: string): Promise<Webhook | null>;\n createWebhook(data: Webhook): Promise<Webhook>;\n updateWebhook(id: string, data: Webhook): Promise<Webhook | null>;\n deleteWebhook(id: string): Promise<Webhook | null>;\n}\n\nconst createWebhookStore = ({ db }: { db: Database }): WebhookStore => {\n return {\n allowedEvents: new Map([\n ['ENTRY_CREATE', 'entry.create'],\n ['ENTRY_UPDATE', 'entry.update'],\n ['ENTRY_DELETE', 'entry.delete'],\n ['ENTRY_PUBLISH', 'entry.publish'],\n ['ENTRY_UNPUBLISH', 'entry.unpublish'],\n ['ENTRY_DRAFT_DISCARD', 'entry.draft-discard'],\n ]),\n addAllowedEvent(key, value) {\n this.allowedEvents.set(key, value);\n },\n removeAllowedEvent(key) {\n this.allowedEvents.delete(key);\n },\n listAllowedEvents() {\n return Array.from(this.allowedEvents.keys());\n },\n getAllowedEvent(key) {\n return this.allowedEvents.get(key);\n },\n async findWebhooks() {\n const results = await db.query('strapi::webhook').findMany();\n\n return results.map(fromDBObject);\n },\n async findWebhook(id) {\n const result = await db.query('strapi::webhook').findOne({ where: { id } });\n return result ? fromDBObject(result) : null;\n },\n async createWebhook(data) {\n await webhookEventValidator(this.allowedEvents, data.events);\n\n return db\n .query('strapi::webhook')\n .create({\n data: toDBObject({ ...data, isEnabled: true }),\n })\n .then(fromDBObject);\n },\n async updateWebhook(id, data) {\n await webhookEventValidator(this.allowedEvents, data.events);\n\n const webhook = await db.query('strapi::webhook').update({\n where: { id },\n data: toDBObject(data),\n });\n\n return webhook ? fromDBObject(webhook) : null;\n },\n async deleteWebhook(id) {\n const webhook = await db.query('strapi::webhook').delete({ where: { id } });\n return webhook ? fromDBObject(webhook) : null;\n },\n };\n};\n\nexport { webhookModel, createWebhookStore };\n"],"names":["ValidationError","errors","webhookModel","uid","singularName","tableName","attributes","id","type","name","url","headers","events","enabled","toDBObject","data","isEnabled","fromDBObject","row","toString","webhookEventValidator","allowedEvents","allowedValues","Array","from","values","forEach","event","includes","createWebhookStore","db","Map","addAllowedEvent","key","value","set","removeAllowedEvent","delete","listAllowedEvents","keys","getAllowedEvent","get","findWebhooks","results","query","findMany","map","findWebhook","result","findOne","where","createWebhook","create","then","updateWebhook","webhook","update","deleteWebhook"],"mappings":";;AAQA,MAAM,EAAEA,eAAe,EAAE,GAAGC,MAAAA;AAE5B,MAAMC,YAAAA,GAAsB;IAC1BC,GAAAA,EAAK,iBAAA;IACLC,YAAAA,EAAc,iBAAA;IACdC,SAAAA,EAAW,iBAAA;IACXC,UAAAA,EAAY;QACVC,EAAAA,E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3C,QAAA,CAAA;AACA,QAAA,MAAME,eAAclD,EAAE,EAAA;AACpB,YAAA,MAAMgD,UAAU,MAAMzB,EAAAA,CAAGc,KAAK,CAAC,iBAAA,CAAA,CAAmBP,MAAM,CAAC;gBAAEa,KAAAA,EAAO;AAAE3C,oBAAAA;AAAG;AAAE,aAAA,CAAA;YACzE,OAAOgD,OAAAA,GAAUtC,aAAasC,OAAAA,CAAAA,GAAW,IAAA;AAC3C,QAAA;AACF,KAAA;AACF;;;;"}
1
+ {"version":3,"file":"webhook-store.mjs","sources":["../../src/services/webhook-store.ts"],"sourcesContent":["/**\n * Webhook store is the implementation of webhook storage over the core_store\n */\n\nimport { errors } from '@strapi/utils';\nimport type { Model, Database } from '@strapi/database';\nimport type { Modules } from '@strapi/types';\n\nconst { ValidationError } = errors;\n\nconst webhookModel: Model = {\n uid: 'strapi::webhook',\n singularName: 'strapi_webhooks',\n tableName: 'strapi_webhooks',\n attributes: {\n id: {\n type: 'increments',\n },\n name: {\n type: 'string',\n },\n url: {\n type: 'text',\n },\n headers: {\n type: 'json',\n },\n events: {\n type: 'json',\n },\n enabled: {\n type: 'boolean',\n },\n },\n};\n\ntype Webhook = Modules.WebhookStore.Webhook;\ntype DBOutput = Omit<Webhook, 'id' | 'isEnabled'> & { id: string | number; enabled: boolean };\ntype DBInput = Omit<DBOutput, 'id'>;\n\nconst toDBObject = (data: Webhook): DBInput => {\n return {\n name: data.name,\n url: data.url,\n headers: data.headers,\n events: data.events,\n enabled: data.isEnabled,\n };\n};\n\nconst fromDBObject = (row: DBOutput): Webhook => {\n return {\n id: typeof row.id === 'number' ? row.id.toString() : row.id,\n name: row.name,\n url: row.url,\n headers: row.headers,\n events: row.events,\n isEnabled: row.enabled,\n };\n};\n\nconst webhookEventValidator = async (allowedEvents: Map<string, string>, events: string[]) => {\n const allowedValues = new Set(Array.from(allowedEvents.values()));\n\n events.forEach((event) => {\n if (allowedValues.has(event)) {\n return;\n }\n\n throw new ValidationError(`Webhook event ${event} is not supported`);\n });\n};\n\nexport interface WebhookStore {\n allowedEvents: Map<string, string>;\n addAllowedEvent(key: string, value: string): void;\n removeAllowedEvent(key: string): void;\n listAllowedEvents(): string[];\n getAllowedEvent(key: string): string | undefined;\n findWebhooks(): Promise<Webhook[]>;\n findWebhook(id: string): Promise<Webhook | null>;\n createWebhook(data: Webhook): Promise<Webhook>;\n updateWebhook(id: string, data: Webhook): Promise<Webhook | null>;\n deleteWebhook(id: string): Promise<Webhook | null>;\n}\n\nconst createWebhookStore = ({ db }: { db: Database }): WebhookStore => {\n return {\n allowedEvents: new Map([\n ['ENTRY_CREATE', 'entry.create'],\n ['ENTRY_UPDATE', 'entry.update'],\n ['ENTRY_DELETE', 'entry.delete'],\n ['ENTRY_PUBLISH', 'entry.publish'],\n ['ENTRY_UNPUBLISH', 'entry.unpublish'],\n ['ENTRY_DRAFT_DISCARD', 'entry.draft-discard'],\n ]),\n addAllowedEvent(key, value) {\n this.allowedEvents.set(key, value);\n },\n removeAllowedEvent(key) {\n this.allowedEvents.delete(key);\n },\n listAllowedEvents() {\n return Array.from(this.allowedEvents.keys());\n },\n getAllowedEvent(key) {\n return this.allowedEvents.get(key);\n },\n async findWebhooks() {\n const results = await db.query('strapi::webhook').findMany();\n\n return results.map(fromDBObject);\n },\n async findWebhook(id) {\n const result = await db.query('strapi::webhook').findOne({ where: { id } });\n return result ? fromDBObject(result) : null;\n },\n async createWebhook(data) {\n await webhookEventValidator(this.allowedEvents, data.events);\n\n return db\n .query('strapi::webhook')\n .create({\n data: toDBObject({ ...data, isEnabled: true }),\n })\n .then(fromDBObject);\n },\n async updateWebhook(id, data) {\n await webhookEventValidator(this.allowedEvents, data.events);\n\n const webhook = await db.query('strapi::webhook').update({\n where: { id },\n data: toDBObject(data),\n });\n\n return webhook ? fromDBObject(webhook) : null;\n },\n async deleteWebhook(id) {\n const webhook = await db.query('strapi::webhook').delete({ where: { id } });\n return webhook ? fromDBObject(webhook) : null;\n },\n };\n};\n\nexport { webhookModel, createWebhookStore };\n"],"names":["ValidationError","errors","webhookModel","uid","singularName","tableName","attributes","id","type","name","url","headers","events","enabled","toDBObject","data","isEnabled","fromDBObject","row","toString","webhookEventValidator","allowedEvents","allowedValues","Set","Array","from","values","forEach","event","has","createWebhookStore","db","Map","addAllowedEvent","key","value","set","removeAllowedEvent","delete","listAllowedEvents","keys","getAllowedEvent","get","findWebhooks","results","query","findMany","map","findWebhook","result","findOne","where","createWebhook","create","then","updateWebhook","webhook","update","deleteWebhook"],"mappings":";;AAQA,MAAM,EAAEA,eAAe,EAAE,GAAGC,MAAAA;AAE5B,MAAMC,YAAAA,GAAsB;IAC1BC,GAAAA,EAAK,iBAAA;IACLC,YAAAA,EAAc,iBAAA;IACdC,SAAAA,EAAW,iBAAA;IACXC,UAAAA,EAAY;QACVC,EAAAA,EAAI;YACFC,IAAAA,EAAM;AACR,SAAA;QACAC,IAAAA,EAAM;YACJD,IAAAA,EAAM;AACR,SAAA;QACAE,GAAAA,EAAK;YACHF,IAAAA,EAAM;AACR,SAAA;QACAG,OAAAA,EAAS;YACPH,IAAAA,EAAM;AACR,SAAA;QACAI,MAAAA,EAAQ;YACNJ,IAAAA,EAAM;AACR,SAAA;QACAK,OAAAA,EAAS;YACPL,IAAAA,EAAM;AACR;AACF;AACF;AAMA,MAAMM,aAAa,CAACC,IAAAA,GAAAA;IAClB,OAAO;AACLN,QAAAA,IAAAA,EAAMM,KAAKN,IAAI;AACfC,QAAAA,GAAAA,EAAKK,KAAKL,GAAG;AACbC,QAAAA,OAAAA,EAASI,KAAKJ,OAAO;AACrBC,QAAAA,MAAAA,EAAQG,KAAKH,MAAM;AACnBC,QAAAA,OAAAA,EAASE,KAAKC;AAChB,KAAA;AACF,CAAA;AAEA,MAAMC,eAAe,CAACC,GAAAA,GAAAA;IACpB,OAAO;QACLX,EAAAA,EAAI,OAAOW,GAAAA,CAAIX,EAAE,KAAK,QAAA,GAAWW,GAAAA,CAAIX,EAAE,CAACY,QAAQ,EAAA,GAAK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"fetch.d.ts","sourceRoot":"","sources":["../../src/utils/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAiBnD,UAAU,kBAAkB;IAC1B,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAgCD,eAAO,MAAM,iBAAiB,GAAI,QAAQ,IAAI,CAAC,MAAM,EAAE,UAAU,kBAAkB,KAAG,KAiCrF,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC"}
@@ -1,17 +1,51 @@
1
1
  'use strict';
2
2
 
3
- var undici = require('undici');
3
+ var ProxyAgent = require('undici/lib/dispatcher/proxy-agent.js');
4
+ var Dispatcher1Wrapper = require('undici/lib/dispatcher/dispatcher1-wrapper.js');
5
+ var Dispatcher = require('undici/lib/dispatcher/dispatcher.js');
6
+ var connect = require('undici/lib/api/api-connect.js');
4
7
 
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var ProxyAgent__default = /*#__PURE__*/_interopDefault(ProxyAgent);
11
+ var Dispatcher1Wrapper__default = /*#__PURE__*/_interopDefault(Dispatcher1Wrapper);
12
+ var Dispatcher__default = /*#__PURE__*/_interopDefault(Dispatcher);
13
+ var connect__default = /*#__PURE__*/_interopDefault(connect);
14
+
15
+ var /* eslint-enable import/extensions */ // undici's main entry adds connect() to every dispatcher. ProxyAgent needs it to open the CONNECT
16
+ // tunnel used for https targets, so add it here since the main entry is skipped.
17
+ _Dispatcher_prototype;
18
+ (_Dispatcher_prototype = Dispatcher__default.default.prototype).connect ?? (_Dispatcher_prototype.connect = connect__default.default);
19
+ const isStream = (body)=>body instanceof ReadableStream || typeof body === 'object' && body !== null && Symbol.asyncIterator in body;
20
+ // Node's built-in fetch adds its own Content-Length, and undici 8 dispatchers reject the duplicated
21
+ // header (https://github.com/nodejs/undici/issues/5500), so drop the caller's one when proxying.
22
+ // A stream body has no length of its own and keeps the header, otherwise it would be sent chunked.
23
+ // TODO: remove once https://github.com/nodejs/undici/pull/5502 is released and installed
24
+ const withoutContentLength = (input, init)=>{
25
+ if (isStream(init?.body)) {
26
+ return init;
27
+ }
28
+ const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : undefined));
29
+ if (!headers.has('content-length')) {
30
+ return init;
31
+ }
32
+ headers.delete('content-length');
33
+ return {
34
+ ...init,
35
+ headers
36
+ };
37
+ };
5
38
  // Create a wrapper for Node's Fetch API that applies a global proxy
6
39
  const createStrapiFetch = (strapi, options)=>{
7
40
  const { logs = true } = options ?? {};
8
41
  const strapiFetch = (url, options)=>{
9
- const fetchOptions = {
10
- ...strapiFetch.dispatcher ? {
11
- dispatcher: strapiFetch.dispatcher
12
- } : {},
13
- ...options
14
- };
42
+ const { dispatcher } = strapiFetch;
43
+ // Cast: the global RequestInit types its dispatcher with Node's bundled undici types, which
44
+ // differ from the installed undici version; Dispatcher1Wrapper makes them compatible at runtime
45
+ const fetchOptions = dispatcher ? {
46
+ dispatcher,
47
+ ...withoutContentLength(url, options)
48
+ } : options;
15
49
  if (logs) {
16
50
  strapi.log.debug(`Making request for ${url}`);
17
51
  }
@@ -22,7 +56,9 @@ const createStrapiFetch = (strapi, options)=>{
22
56
  if (logs) {
23
57
  strapi.log.info(`Using proxy for Fetch requests: ${proxy}`);
24
58
  }
25
- strapiFetch.dispatcher = new undici.ProxyAgent(proxy);
59
+ // Node's built-in fetch runs its own bundled undici, which may still use the legacy (v1)
60
+ // dispatcher handler API that undici 8 removed. Dispatcher1Wrapper bridges both APIs.
61
+ strapiFetch.dispatcher = new Dispatcher1Wrapper__default.default(new ProxyAgent__default.default(proxy));
26
62
  }
27
63
  return strapiFetch;
28
64
  };
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.js","sources":["../../src/utils/fetch.ts"],"sourcesContent":["import type { Core, Modules } from '@strapi/types';\nimport { ProxyAgent } from 'undici';\n\n// TODO: once core Node exposes a stable way to create a ProxyAgent we will use that instead of undici\n\ninterface StrapiFetchOptions {\n logs?: boolean;\n}\n\n// Create a wrapper for Node's Fetch API that applies a global proxy\nexport const createStrapiFetch = (strapi: Core.Strapi, options?: StrapiFetchOptions): Fetch => {\n const { logs = true } = options ?? {};\n\n const strapiFetch: Fetch = (url, options) => {\n const fetchOptions: RequestInit = {\n ...(strapiFetch.dispatcher ? { dispatcher: strapiFetch.dispatcher } : {}),\n ...options,\n };\n\n if (logs) {\n strapi.log.debug(`Making request for ${url}`);\n }\n\n return fetch(url, fetchOptions);\n };\n\n const proxy =\n strapi.config.get<ConstructorParameters<typeof ProxyAgent>[0]>('server.proxy.fetch') ||\n strapi.config.get<string>('server.proxy.global');\n\n if (proxy) {\n if (logs) {\n strapi.log.info(`Using proxy for Fetch requests: ${proxy}`);\n }\n strapiFetch.dispatcher = new ProxyAgent(proxy);\n }\n\n return strapiFetch;\n};\n\nexport type Fetch = Modules.Fetch.Fetch;\n"],"names":["createStrapiFetch","strapi","options","logs","strapiFetch","url","fetchOptions","dispatcher","log","debug","fetch","proxy","config","get","info","ProxyAgent"],"mappings":";;;;AASA;AACO,MAAMA,iBAAAA,GAAoB,CAACC,MAAAA,EAAqBC,OAAAA,GAAAA;AACrD,IAAA,MAAM,EAAEC,IAAAA,GAAO,IAAI,EAAE,GAAGD,WAAW,EAAC;IAEpC,MAAME,WAAAA,GAAqB,CAACC,GAAAA,EAAKH,OAAAA,GAAAA;AAC/B,QAAA,MAAMI,YAAAA,GAA4B;YAChC,GAAIF,WAAAA,CAAYG,UAAU,GAAG;AAAEA,gBAAAA,UAAAA,EAAYH,YAAYG;AAAW,aAAA,GAAI,EAAE;AACxE,YAAA,GAAGL;AACL,SAAA;AAEA,QAAA,IAAIC,IAAAA,EAAM;AACRF,YAAAA,MAAAA,CAAOO,GAAG,CAACC,KAAK,CAAC,CAAC,mBAAmB,EAAEJ,GAAAA,CAAAA,CAAK,CAAA;AAC9C,QAAA;AAEA,QAAA,OAAOK,MAAML,GAAAA,EAAKC,YAAAA,CAAAA;AACpB,IAAA,CAAA;IAEA,MAAMK,KAAAA,GACJV,MAAAA,CAAOW,MAAM,CAACC,GAAG,CAA8C,oBAAA,CAAA,IAC/DZ,MAAAA,CAAOW,MAAM,CAACC,GAAG,CAAS,qBAAA,CAAA;AAE5B,IAAA,IAAIF,KAAAA,EAAO;AACT,QAAA,IAAIR,IAAAA,EAAM;AACRF,YAAAA,MAAAA,CAAOO,GAAG,CAACM,IAAI,CAAC,CAAC,gCAAgC,EAAEH,KAAAA,CAAAA,CAAO,CAAA;AAC5D,QAAA;QACAP,WAAAA,CAAYG,UAAU,GAAG,IAAIQ,iBAAAA,CAAWJ,KAAAA,CAAAA;AAC1C,IAAA;IAEA,OAAOP,WAAAA;AACT;;;;"}
1
+ {"version":3,"file":"fetch.js","sources":["../../src/utils/fetch.ts"],"sourcesContent":["import type { Core, Modules } from '@strapi/types';\n// Import undici's dispatchers from their own files: loading undici's main entry replaces the\n// dispatcher of Node's built-in fetch, which then rejects requests that set their own\n// Content-Length on Node 22/24 (https://github.com/nodejs/undici/issues/5500)\n/* eslint-disable import/extensions -- required by the ESM build: undici has no exports map */\nimport ProxyAgent from 'undici/lib/dispatcher/proxy-agent.js';\nimport Dispatcher1Wrapper from 'undici/lib/dispatcher/dispatcher1-wrapper.js';\nimport Dispatcher from 'undici/lib/dispatcher/dispatcher.js';\nimport connect from 'undici/lib/api/api-connect.js';\n/* eslint-enable import/extensions */\n\n// undici's main entry adds connect() to every dispatcher. ProxyAgent needs it to open the CONNECT\n// tunnel used for https targets, so add it here since the main entry is skipped.\nDispatcher.prototype.connect ??= connect;\n\n// TODO: once core Node exposes a stable way to create a ProxyAgent we will use that instead of undici\n\ninterface StrapiFetchOptions {\n logs?: boolean;\n}\n\nconst isStream = (body: RequestInit['body']) =>\n body instanceof ReadableStream ||\n (typeof body === 'object' && body !== null && Symbol.asyncIterator in body);\n\n// Node's built-in fetch adds its own Content-Length, and undici 8 dispatchers reject the duplicated\n// header (https://github.com/nodejs/undici/issues/5500), so drop the caller's one when proxying.\n// A stream body has no length of its own and keeps the header, otherwise it would be sent chunked.\n// TODO: remove once https://github.com/nodejs/undici/pull/5502 is released and installed\nconst withoutContentLength = (\n input: Parameters<Fetch>[0],\n init?: RequestInit\n): RequestInit | undefined => {\n if (isStream(init?.body)) {\n return init;\n }\n\n const headers = new Headers(\n init?.headers ?? (input instanceof Request ? input.headers : undefined)\n );\n\n if (!headers.has('content-length')) {\n return init;\n }\n\n headers.delete('content-length');\n\n return { ...init, headers };\n};\n\n// Create a wrapper for Node's Fetch API that applies a global proxy\nexport const createStrapiFetch = (strapi: Core.Strapi, options?: StrapiFetchOptions): Fetch => {\n const { logs = true } = options ?? {};\n\n const strapiFetch: Fetch = (url, options) => {\n const { dispatcher } = strapiFetch;\n\n // Cast: the global RequestInit types its dispatcher with Node's bundled undici types, which\n // differ from the installed undici version; Dispatcher1Wrapper makes them compatible at runtime\n const fetchOptions = (\n dispatcher ? { dispatcher, ...withoutContentLength(url, options) } : options\n ) as RequestInit | undefined;\n\n if (logs) {\n strapi.log.debug(`Making request for ${url}`);\n }\n\n return fetch(url, fetchOptions);\n };\n\n const proxy =\n strapi.config.get<ConstructorParameters<typeof ProxyAgent>[0]>('server.proxy.fetch') ||\n strapi.config.get<string>('server.proxy.global');\n\n if (proxy) {\n if (logs) {\n strapi.log.info(`Using proxy for Fetch requests: ${proxy}`);\n }\n // Node's built-in fetch runs its own bundled undici, which may still use the legacy (v1)\n // dispatcher handler API that undici 8 removed. Dispatcher1Wrapper bridges both APIs.\n strapiFetch.dispatcher = new Dispatcher1Wrapper(new ProxyAgent(proxy));\n }\n\n return strapiFetch;\n};\n\nexport type Fetch = Modules.Fetch.Fetch;\n"],"names":["Dispatcher","prototype","connect","isStream","body","ReadableStream","Symbol","asyncIterator","withoutContentLength","input","init","headers","Headers","Request","undefined","has","delete","createStrapiFetch","strapi","options","logs","strapiFetch","url","dispatcher","fetchOptions","log","debug","fetch","proxy","config","get","info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AGf,oBAAAA,CAAqBc,KAAKH,OAAAA;SAAS,GAAIA,OAAAA;AAGvE,QAAA,IAAIC,IAAAA,EAAM;AACRF,YAAAA,MAAAA,CAAOO,GAAG,CAACC,KAAK,CAAC,CAAC,mBAAmB,EAAEJ,GAAAA,CAAAA,CAAK,CAAA;AAC9C,QAAA;AAEA,QAAA,OAAOK,MAAML,GAAAA,EAAKE,YAAAA,CAAAA;AACpB,IAAA,CAAA;IAEA,MAAMI,KAAAA,GACJV,MAAAA,CAAOW,MAAM,CAACC,GAAG,CAA8C,oBAAA,CAAA,IAC/DZ,MAAAA,CAAOW,MAAM,CAACC,GAAG,CAAS,qBAAA,CAAA;AAE5B,IAAA,IAAIF,KAAAA,EAAO;AACT,QAAA,IAAIR,IAAAA,EAAM;AACRF,YAAAA,MAAAA,CAAOO,GAAG,CAACM,IAAI,CAAC,CAAC,gCAAgC,EAAEH,KAAAA,CAAAA,CAAO,CAAA;AAC5D,QAAA;;;AAGAP,QAAAA,WAAAA,CAAYE,UAAU,GAAG,IAAIS,mCAAAA,CAAmB,IAAIC,2BAAAA,CAAWL,KAAAA,CAAAA,CAAAA;AACjE,IAAA;IAEA,OAAOP,WAAAA;AACT;;;;"}
@@ -1,15 +1,42 @@
1
- import { ProxyAgent } from 'undici';
1
+ import ProxyAgent from 'undici/lib/dispatcher/proxy-agent.js';
2
+ import Dispatcher1Wrapper from 'undici/lib/dispatcher/dispatcher1-wrapper.js';
3
+ import Dispatcher from 'undici/lib/dispatcher/dispatcher.js';
4
+ import connect from 'undici/lib/api/api-connect.js';
2
5
 
6
+ var /* eslint-enable import/extensions */ // undici's main entry adds connect() to every dispatcher. ProxyAgent needs it to open the CONNECT
7
+ // tunnel used for https targets, so add it here since the main entry is skipped.
8
+ _Dispatcher_prototype;
9
+ (_Dispatcher_prototype = Dispatcher.prototype).connect ?? (_Dispatcher_prototype.connect = connect);
10
+ const isStream = (body)=>body instanceof ReadableStream || typeof body === 'object' && body !== null && Symbol.asyncIterator in body;
11
+ // Node's built-in fetch adds its own Content-Length, and undici 8 dispatchers reject the duplicated
12
+ // header (https://github.com/nodejs/undici/issues/5500), so drop the caller's one when proxying.
13
+ // A stream body has no length of its own and keeps the header, otherwise it would be sent chunked.
14
+ // TODO: remove once https://github.com/nodejs/undici/pull/5502 is released and installed
15
+ const withoutContentLength = (input, init)=>{
16
+ if (isStream(init?.body)) {
17
+ return init;
18
+ }
19
+ const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : undefined));
20
+ if (!headers.has('content-length')) {
21
+ return init;
22
+ }
23
+ headers.delete('content-length');
24
+ return {
25
+ ...init,
26
+ headers
27
+ };
28
+ };
3
29
  // Create a wrapper for Node's Fetch API that applies a global proxy
4
30
  const createStrapiFetch = (strapi, options)=>{
5
31
  const { logs = true } = options ?? {};
6
32
  const strapiFetch = (url, options)=>{
7
- const fetchOptions = {
8
- ...strapiFetch.dispatcher ? {
9
- dispatcher: strapiFetch.dispatcher
10
- } : {},
11
- ...options
12
- };
33
+ const { dispatcher } = strapiFetch;
34
+ // Cast: the global RequestInit types its dispatcher with Node's bundled undici types, which
35
+ // differ from the installed undici version; Dispatcher1Wrapper makes them compatible at runtime
36
+ const fetchOptions = dispatcher ? {
37
+ dispatcher,
38
+ ...withoutContentLength(url, options)
39
+ } : options;
13
40
  if (logs) {
14
41
  strapi.log.debug(`Making request for ${url}`);
15
42
  }
@@ -20,7 +47,9 @@ const createStrapiFetch = (strapi, options)=>{
20
47
  if (logs) {
21
48
  strapi.log.info(`Using proxy for Fetch requests: ${proxy}`);
22
49
  }
23
- strapiFetch.dispatcher = new ProxyAgent(proxy);
50
+ // Node's built-in fetch runs its own bundled undici, which may still use the legacy (v1)
51
+ // dispatcher handler API that undici 8 removed. Dispatcher1Wrapper bridges both APIs.
52
+ strapiFetch.dispatcher = new Dispatcher1Wrapper(new ProxyAgent(proxy));
24
53
  }
25
54
  return strapiFetch;
26
55
  };
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.mjs","sources":["../../src/utils/fetch.ts"],"sourcesContent":["import type { Core, Modules } from '@strapi/types';\nimport { ProxyAgent } from 'undici';\n\n// TODO: once core Node exposes a stable way to create a ProxyAgent we will use that instead of undici\n\ninterface StrapiFetchOptions {\n logs?: boolean;\n}\n\n// Create a wrapper for Node's Fetch API that applies a global proxy\nexport const createStrapiFetch = (strapi: Core.Strapi, options?: StrapiFetchOptions): Fetch => {\n const { logs = true } = options ?? {};\n\n const strapiFetch: Fetch = (url, options) => {\n const fetchOptions: RequestInit = {\n ...(strapiFetch.dispatcher ? { dispatcher: strapiFetch.dispatcher } : {}),\n ...options,\n };\n\n if (logs) {\n strapi.log.debug(`Making request for ${url}`);\n }\n\n return fetch(url, fetchOptions);\n };\n\n const proxy =\n strapi.config.get<ConstructorParameters<typeof ProxyAgent>[0]>('server.proxy.fetch') ||\n strapi.config.get<string>('server.proxy.global');\n\n if (proxy) {\n if (logs) {\n strapi.log.info(`Using proxy for Fetch requests: ${proxy}`);\n }\n strapiFetch.dispatcher = new ProxyAgent(proxy);\n }\n\n return strapiFetch;\n};\n\nexport type Fetch = Modules.Fetch.Fetch;\n"],"names":["createStrapiFetch","strapi","options","logs","strapiFetch","url","fetchOptions","dispatcher","log","debug","fetch","proxy","config","get","info","ProxyAgent"],"mappings":";;AASA;AACO,MAAMA,iBAAAA,GAAoB,CAACC,MAAAA,EAAqBC,OAAAA,GAAAA;AACrD,IAAA,MAAM,EAAEC,IAAAA,GAAO,IAAI,EAAE,GAAGD,WAAW,EAAC;IAEpC,MAAME,WAAAA,GAAqB,CAACC,GAAAA,EAAKH,OAAAA,GAAAA;AAC/B,QAAA,MAAMI,YAAAA,GAA4B;YAChC,GAAIF,WAAAA,CAAYG,UAAU,GAAG;AAAEA,gBAAAA,UAAAA,EAAYH,YAAYG;AAAW,aAAA,GAAI,EAAE;AACxE,YAAA,GAAGL;AACL,SAAA;AAEA,QAAA,IAAIC,IAAAA,EAAM;AACRF,YAAAA,MAAAA,CAAOO,GAAG,CAACC,KAAK,CAAC,CAAC,mBAAmB,EAAEJ,GAAAA,CAAAA,CAAK,CAAA;AAC9C,QAAA;AAEA,QAAA,OAAOK,MAAML,GAAAA,EAAKC,YAAAA,CAAAA;AACpB,IAAA,CAAA;IAEA,MAAMK,KAAAA,GACJV,MAAAA,CAAOW,MAAM,CAACC,GAAG,CAA8C,oBAAA,CAAA,IAC/DZ,MAAAA,CAAOW,MAAM,CAACC,GAAG,CAAS,qBAAA,CAAA;AAE5B,IAAA,IAAIF,KAAAA,EAAO;AACT,QAAA,IAAIR,IAAAA,EAAM;AACRF,YAAAA,MAAAA,CAAOO,GAAG,CAACM,IAAI,CAAC,CAAC,gCAAgC,EAAEH,KAAAA,CAAAA,CAAO,CAAA;AAC5D,QAAA;QACAP,WAAAA,CAAYG,UAAU,GAAG,IAAIQ,UAAAA,CAAWJ,KAAAA,CAAAA;AAC1C,IAAA;IAEA,OAAOP,WAAAA;AACT;;;;"}
1
+ {"version":3,"file":"fetch.mjs","sources":["../../src/utils/fetch.ts"],"sourcesContent":["import type { Core, Modules } from '@strapi/types';\n// Import undici's dispatchers from their own files: loading undici's main entry replaces the\n// dispatcher of Node's built-in fetch, which then rejects requests that set their own\n// Content-Length on Node 22/24 (https://github.com/nodejs/undici/issues/5500)\n/* eslint-disable import/extensions -- required by the ESM build: undici has no exports map */\nimport ProxyAgent from 'undici/lib/dispatcher/proxy-agent.js';\nimport Dispatcher1Wrapper from 'undici/lib/dispatcher/dispatcher1-wrapper.js';\nimport Dispatcher from 'undici/lib/dispatcher/dispatcher.js';\nimport connect from 'undici/lib/api/api-connect.js';\n/* eslint-enable import/extensions */\n\n// undici's main entry adds connect() to every dispatcher. ProxyAgent needs it to open the CONNECT\n// tunnel used for https targets, so add it here since the main entry is skipped.\nDispatcher.prototype.connect ??= connect;\n\n// TODO: once core Node exposes a stable way to create a ProxyAgent we will use that instead of undici\n\ninterface StrapiFetchOptions {\n logs?: boolean;\n}\n\nconst isStream = (body: RequestInit['body']) =>\n body instanceof ReadableStream ||\n (typeof body === 'object' && body !== null && Symbol.asyncIterator in body);\n\n// Node's built-in fetch adds its own Content-Length, and undici 8 dispatchers reject the duplicated\n// header (https://github.com/nodejs/undici/issues/5500), so drop the caller's one when proxying.\n// A stream body has no length of its own and keeps the header, otherwise it would be sent chunked.\n// TODO: remove once https://github.com/nodejs/undici/pull/5502 is released and installed\nconst withoutContentLength = (\n input: Parameters<Fetch>[0],\n init?: RequestInit\n): RequestInit | undefined => {\n if (isStream(init?.body)) {\n return init;\n }\n\n const headers = new Headers(\n init?.headers ?? (input instanceof Request ? input.headers : undefined)\n );\n\n if (!headers.has('content-length')) {\n return init;\n }\n\n headers.delete('content-length');\n\n return { ...init, headers };\n};\n\n// Create a wrapper for Node's Fetch API that applies a global proxy\nexport const createStrapiFetch = (strapi: Core.Strapi, options?: StrapiFetchOptions): Fetch => {\n const { logs = true } = options ?? {};\n\n const strapiFetch: Fetch = (url, options) => {\n const { dispatcher } = strapiFetch;\n\n // Cast: the global RequestInit types its dispatcher with Node's bundled undici types, which\n // differ from the installed undici version; Dispatcher1Wrapper makes them compatible at runtime\n const fetchOptions = (\n dispatcher ? { dispatcher, ...withoutContentLength(url, options) } : options\n ) as RequestInit | undefined;\n\n if (logs) {\n strapi.log.debug(`Making request for ${url}`);\n }\n\n return fetch(url, fetchOptions);\n };\n\n const proxy =\n strapi.config.get<ConstructorParameters<typeof ProxyAgent>[0]>('server.proxy.fetch') ||\n strapi.config.get<string>('server.proxy.global');\n\n if (proxy) {\n if (logs) {\n strapi.log.info(`Using proxy for Fetch requests: ${proxy}`);\n }\n // Node's built-in fetch runs its own bundled undici, which may still use the legacy (v1)\n // dispatcher handler API that undici 8 removed. Dispatcher1Wrapper bridges both APIs.\n strapiFetch.dispatcher = new Dispatcher1Wrapper(new ProxyAgent(proxy));\n }\n\n return strapiFetch;\n};\n\nexport type Fetch = Modules.Fetch.Fetch;\n"],"names":["Dispatcher","prototype","connect","isStream","body","ReadableStream","Symbol","asyncIterator","withoutContentLength","input","init","headers","Headers","Request","undefined","has","delete","createStrapiFetch","strapi","options","logs","strapiFetch","url","dispatcher","fetchOptions","log","debug","fetch","proxy","config","get","info","Dispatcher1Wrapper","ProxyAgent"],"mappings":";;;;;AASA;AAGA;AACAA,qBAAAA;AAAAA,CAAAA,wBAAAA,UAAAA,CAAWC,SAAS,EAACC,OAAAA,KAArBF,sBAAqBE,OAAAA,GAAYA,OAAAA,CAAAA;AAQjC,MAAMC,QAAAA,GAAW,CAACC,IAAAA,GAChBA,IAAAA,YAAgBC,cAAAA,IACf,OAAOD,IAAAA,KAAS,QAAA,IAAYA,IAAAA,KAAS,IAAA,IAAQE,MAAAA,CAAOC,aAAa,IAAIH,IAAAA;AAExE;AACA;AACA;AACA;AACA,MAAMI,oBAAAA,GAAuB,CAC3BC,KAAAA,EACAC,IAAAA,GAAAA;IAEA,IAAIP,QAAAA,CAASO,MAAMN,IAAAA,CAAAA,EAAO;QACxB,OAAOM,IAAAA;AACT,IAAA;IAEA,MAAMC,OAAAA,GAAU,IAAIC,OAAAA,CAClBF,IAAAA,EAAMC,OAAAA,KAAYF,KAAAA,YAAiBI,OAAAA,GAAUJ,KAAAA,CAAME,OAAO,GAAGG,SAAQ,CAAA,CAAA;AAGvE,IAAA,IAAI,CAACH,OAAAA,CAAQI,GAAG,CAAC,gBAAA,CAAA,EAAmB;QAClC,OAAOL,IAAAA;AACT,IAAA;AAEAC,IAAAA,OAAAA,CAAQK,MAAM,CAAC,gBAAA,CAAA;IAEf,OAAO;AAAE,QAAA,GAAGN,IAAI;AAAEC,QAAAA;AAAQ,KAAA;AAC5B,CAAA;AAEA;AACO,MAAMM,iBAAAA,GAAoB,CAACC,MAAAA,EAAqBC,OAAAA,GAAAA;AACrD,IAAA,MAAM,EAAEC,IAAAA,GAAO,IAAI,EAAE,GAAGD,WAAW,EAAC;IAEpC,MAAME,WAAAA,GAAqB,CAACC,GAAAA,EAAKH,OAAAA,GAAAA;QAC/B,MAAM,EAAEI,UAAU,EAAE,GAAGF,WAAAA;;;AAIvB,QAAA,MAAMG,eACJD,UAAAA,GAAa;AAAEA,YAAAA,UAAAA;YAAY,GAAGf,oBAAAA,CAAqBc,KAAKH,OAAAA;SAAS,GAAIA,OAAAA;AAGvE,QAAA,IAAIC,IAAAA,EAAM;AACRF,YAAAA,MAAAA,CAAOO,GAAG,CAACC,KAAK,CAAC,CAAC,mBAAmB,EAAEJ,GAAAA,CAAAA,CAAK,CAAA;AAC9C,QAAA;AAEA,QAAA,OAAOK,MAAML,GAAAA,EAAKE,YAAAA,CAAAA;AACpB,IAAA,CAAA;IAEA,MAAMI,KAAAA,GACJV,MAAAA,CAAOW,MAAM,CAACC,GAAG,CAA8C,oBAAA,CAAA,IAC/DZ,MAAAA,CAAOW,MAAM,CAACC,GAAG,CAAS,qBAAA,CAAA;AAE5B,IAAA,IAAIF,KAAAA,EAAO;AACT,QAAA,IAAIR,IAAAA,EAAM;AACRF,YAAAA,MAAAA,CAAOO,GAAG,CAACM,IAAI,CAAC,CAAC,gCAAgC,EAAEH,KAAAA,CAAAA,CAAO,CAAA;AAC5D,QAAA;;;AAGAP,QAAAA,WAAAA,CAAYE,UAAU,GAAG,IAAIS,kBAAAA,CAAmB,IAAIC,UAAAA,CAAWL,KAAAA,CAAAA,CAAAA;AACjE,IAAA;IAEA,OAAOP,WAAAA;AACT;;;;"}
@@ -302,6 +302,10 @@ const createCompoLinkModel = (contentType, identifiers)=>{
302
302
  };
303
303
  const transformContentTypesToModels = (contentTypes, identifiers)=>{
304
304
  const models = [];
305
+ const reservedAttributeNames = new Set([
306
+ 'document_id',
307
+ identifiers.ID_COLUMN
308
+ ]);
305
309
  contentTypes.forEach((contentType)=>{
306
310
  assert__default.default(contentType.collectionName, 'Content type "collectionName" is required');
307
311
  assert__default.default(contentType.modelName, 'Content type "modelName" is required');
@@ -316,13 +320,9 @@ const transformContentTypesToModels = (contentTypes, identifiers)=>{
316
320
  } : {};
317
321
  // TODO: this needs to be combined with getReservedNames, we should not be maintaining two lists
318
322
  // Prevent user from creating a documentId attribute
319
- const reservedAttributeNames = [
320
- 'document_id',
321
- identifiers.ID_COLUMN
322
- ];
323
323
  Object.keys(contentType.attributes || {}).forEach((attributeName)=>{
324
324
  const snakeCasedAttributeName = ___default.default.snakeCase(attributeName);
325
- if (reservedAttributeNames.includes(snakeCasedAttributeName)) {
325
+ if (reservedAttributeNames.has(snakeCasedAttributeName)) {
326
326
  throw new Error(`The attribute "${attributeName}" is reserved and cannot be used in a model. Please rename "${contentType.modelName}" attribute "${attributeName}" to something else.`);
327
327
  }
328
328
  });
@@ -1 +1 @@
1
- {"version":3,"file":"transform-content-types-to-models.js","sources":["../../src/utils/transform-content-types-to-models.ts"],"sourcesContent":["import { type Model, type Identifiers } from '@strapi/database';\nimport type { Struct, Schema } from '@strapi/types';\nimport { createId } from '@paralleldrive/cuid2';\nimport assert from 'node:assert';\nimport _ from 'lodash';\n\n/**\n * Because strapi/database models don't know about things like components or dynamic zones, we use this file to convert them\n * to a relations format that it recognizes\n *\n * Therefore we have to keep an additional set of helpers/extensions to the database naming methods\n *\n * IMPORTANT!\n * If we use short versions of anything, we MUST call getNameFromTokens directly; attempting to shorten them ourselves\n * prevents the unshortened name map from being filled properly, so for example it will think that the short name\n * 'collection4f3a_cmps' maps to the unshortened 'collectionname_cmps' rather than 'collectionname_components'\n * Therefore, we only use the identifiers helpers in cases where we do not do any of our own shortening\n */\n\nexport const getComponentJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getDzJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnEntityName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'entity', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnInverseName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'component', shortName: 'cmp', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentTypeColumn = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([{ name: 'component_type', compressible: false }]);\n};\n\nexport const getComponentFkIndexName = (contentType: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: contentType, compressible: true },\n { name: 'entity', compressible: false },\n { name: 'fk', compressible: false },\n ]);\n};\n\n// const { ID_COLUMN: id, FIELD_COLUMN: field, ORDER_COLUMN: order } = identifiers;\n\nexport type LoadedContentTypeModel = Struct.ContentTypeSchema &\n Required<Pick<Struct.ContentTypeSchema, 'collectionName' | 'uid' | 'modelName'>> &\n Pick<Model, 'lifecycles'>;\n\n// Transforms an attribute (particularly for relation types) into the format that strapi/database accepts\nexport const transformAttribute = (\n name: string,\n attribute: Schema.Attribute.AnyAttribute,\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n switch (attribute.type) {\n case 'media': {\n return {\n type: 'relation',\n relation: attribute.multiple === true ? 'morphMany' : 'morphOne',\n target: 'plugin::upload.file',\n morphBy: 'related',\n };\n }\n case 'component': {\n const joinTableName = getComponentJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n return {\n type: 'relation',\n relation: attribute.repeatable === true ? 'oneToMany' : 'oneToOne',\n target: attribute.component,\n\n // We need the join table name to be deterministic,\n // We need to allow passing the join table name as an option\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n inverseJoinColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n on: {\n field: name,\n },\n orderColumnName: identifiers.ORDER_COLUMN,\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n case 'dynamiczone': {\n const joinTableName = getDzJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n\n return {\n type: 'relation',\n relation: 'morphToMany',\n // TODO: handle restrictions at some point\n // target: attribute.components,\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n morphColumn: {\n idColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n typeColumn: {\n name: compTypeColumn,\n },\n typeField: '__component',\n },\n on: {\n field: name,\n },\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n default: {\n return attribute;\n }\n }\n};\n\nexport const transformAttributes = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n return Object.keys(contentType.attributes! || {}).reduce((attrs, attrName) => {\n return {\n ...attrs,\n [attrName]: transformAttribute(\n attrName,\n contentType.attributes[attrName]!,\n contentType,\n identifiers\n ),\n };\n }, {});\n};\n\nexport const hasComponentsOrDz = (\n contentType: LoadedContentTypeModel\n): contentType is LoadedContentTypeModel & { type: 'dynamiczone' | 'component' } => {\n return Object.values(contentType.attributes || {}).some(\n (({ type }: { type: string }) => type === 'dynamiczone' || type === 'component') as any\n );\n};\n\nexport const createDocumentId = createId;\n\nconst createCompoLinkModel = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n): Model => {\n const name = getComponentJoinTableName(contentType.collectionName, identifiers);\n\n const entityId = getComponentJoinColumnEntityName(identifiers);\n const componentId = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n const fkIndex = getComponentFkIndexName(contentType.collectionName, identifiers);\n\n return {\n // TODO: make sure there can't be any conflicts with a prefix\n singularName: name,\n uid: name,\n tableName: name,\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n [entityId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [componentId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [compTypeColumn]: {\n type: 'string',\n },\n [identifiers.FIELD_COLUMN]: {\n type: 'string',\n },\n [identifiers.ORDER_COLUMN]: {\n type: 'float',\n column: {\n unsigned: true,\n defaultTo: null,\n },\n },\n },\n indexes: [\n {\n name: identifiers.getIndexName([contentType.collectionName, identifiers.FIELD_COLUMN]),\n columns: [identifiers.FIELD_COLUMN],\n },\n {\n name: identifiers.getIndexName([contentType.collectionName, compTypeColumn]),\n columns: [compTypeColumn],\n },\n {\n name: fkIndex,\n columns: [entityId],\n },\n {\n // NOTE: since we don't include attribute names, we need to be careful not to create another unique index\n name: identifiers.getUniqueIndexName([contentType.collectionName]),\n columns: [entityId, componentId, identifiers.FIELD_COLUMN, compTypeColumn],\n type: 'unique',\n },\n ],\n foreignKeys: [\n {\n name: fkIndex,\n columns: [entityId],\n referencedColumns: [identifiers.ID_COLUMN],\n referencedTable: identifiers.getTableName(contentType.collectionName),\n onDelete: 'CASCADE',\n },\n ],\n };\n};\n\nexport const transformContentTypesToModels = (\n contentTypes: LoadedContentTypeModel[],\n identifiers: Identifiers\n): Model[] => {\n const models: Model[] = [];\n\n contentTypes.forEach((contentType) => {\n assert(contentType.collectionName, 'Content type \"collectionName\" is required');\n assert(contentType.modelName, 'Content type \"modelName\" is required');\n assert(contentType.uid, 'Content type \"uid\" is required');\n\n // Add document id to content types\n // as it is not documented\n const documentIdAttribute: Record<string, Schema.Attribute.AnyAttribute> =\n contentType.modelType === 'contentType'\n ? { documentId: { type: 'string', default: createDocumentId } }\n : {};\n\n // TODO: this needs to be combined with getReservedNames, we should not be maintaining two lists\n // Prevent user from creating a documentId attribute\n const reservedAttributeNames = ['document_id', identifiers.ID_COLUMN];\n Object.keys(contentType.attributes || {}).forEach((attributeName) => {\n const snakeCasedAttributeName = _.snakeCase(attributeName);\n if (reservedAttributeNames.includes(snakeCasedAttributeName)) {\n throw new Error(\n `The attribute \"${attributeName}\" is reserved and cannot be used in a model. Please rename \"${contentType.modelName}\" attribute \"${attributeName}\" to something else.`\n );\n }\n });\n\n if (hasComponentsOrDz(contentType)) {\n const compoLinkModel = createCompoLinkModel(contentType, identifiers);\n models.push(compoLinkModel);\n }\n\n const model: Model = {\n uid: contentType.uid,\n singularName: contentType.modelName,\n tableName: contentType.collectionName, // This gets shortened in metadata.loadModels(), so we don't shorten here or it will happen twice\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n ...documentIdAttribute,\n ...transformAttributes(contentType, identifiers),\n },\n indexes: contentType.indexes as Model['indexes'],\n foreignKeys: contentType.foreignKeys as Model['foreignKeys'],\n lifecycles: contentType?.lifecycles ?? {},\n };\n\n // Document lookups: secondary btree index declared here so syncSchema owns it\n // (instead of DDL in internal migration `5.0.0-06-add-document-id-indexes`, now a no-op).\n // Keep the exact same name/columns schema sync already produced so existing databases\n // see no index diff on upgrade (a rename would orphan the old index, since the schema\n // builder's dropIndex is a silent no-op unless forceMigration is enabled).\n if (contentType.modelType === 'contentType') {\n model.indexes = [\n ...(model.indexes || []),\n {\n name: identifiers.getIndexName([contentType.collectionName, 'documents']),\n // Filter attributes that are not in the schema\n columns: ['documentId', 'locale', 'publishedAt']\n .filter((n) => model.attributes[n])\n .map((name) => identifiers.getColumnName(_.snakeCase(name))),\n },\n ];\n }\n\n models.push(model);\n });\n\n return models;\n};\n"],"names":["getComponentJoinTableName","collectionName","identifiers","getNameFromTokens","name","compressible","shortName","getDzJoinTableName","getComponentJoinColumnEntityName","getComponentJoinColumnInverseName","getComponentTypeColumn","getComponentFkIndexName","contentType","transformAttribute","attribute","type","relation","multiple","target","morphBy","joinTableName","joinColumnEntityName","joinColumnInverseName","compTypeColumn","repeatable","component","joinTable","joinColumn","referencedColumn","ID_COLUMN","inverseJoinColumn","on","field","orderColumnName","ORDER_COLUMN","orderBy","order","pivotColumns","FIELD_COLUMN","morphColumn","idColumn","typeColumn","typeField","transformAttributes","Object","keys","attributes","reduce","attrs","attrName","hasComponentsOrDz","values","some","createDocumentId","createId","createCompoLinkModel","entityId","componentId","fkIndex","singularName","uid","tableName","column","unsigned","defaultTo","indexes","getIndexName","columns","getUniqueIndexName","foreignKeys","referencedColumns","referencedTable","getTableName","onDelete","transformContentTypesToModels","contentTypes","models","forEach","assert","modelName","documentIdAttribute","modelType","documentId","default","reservedAttributeNames","attributeName","snakeCasedAttributeName","_","snakeCase","includes","Error","compoLinkModel","push","model","lifecycles","filter","n","map","getColumnName"],"mappings":";;;;;;;;;;;AAMA;;;;;;;;;;;AAWC,IAEM,MAAMA,yBAAAA,GAA4B,CAACC,cAAAA,EAAwBC,WAAAA,GAAAA;IAChE,OAAOA,WAAAA,CAAYC,iBAAiB,CAAC;AACnC,QAAA;YAAEC,IAAAA,EAAMH,cAAAA;YAAgBI,YAAAA,EAAc;AAAK,SAAA;AAC3C,QAAA;YAAED,IAAAA,EAAM,YAAA;YAAcE,SAAAA,EAAW,MAAA;YAAQD,YAAAA,EAAc;AAAM;AAC9D,KAAA,CAAA;AACH;AAEO,MAAME,kBAAAA,GAAqB,CAACN,cAAAA,EAAwBC,WAAAA,GAAAA;IACzD,OAAOA,WAAAA,CAAYC,iBAAiB,CAAC;AACnC,QAAA;YAAEC,IAAAA,EAAMH,cAAAA;YAAgBI,YAAAA,EAAc;AAAK,SAAA;AAC3C,QAAA;YAAED,IAAAA,EAAM,YAAA;YAAcE,SAAAA,EAAW,MAAA;YAAQD,YAAAA,EAAc;AAAM;AAC9D,KAAA,CAAA;AACH;AAEO,MAAMG,mCAAmC,CAACN,WAAAA,GAAAA;IA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MH,KAAAA,CAAM/C,UAAU,CAACkD,CAAAA,CAAE,CAAA,CACjCC,GAAG,CAAC,CAAC7F,IAAAA,GAASF,WAAAA,CAAYgG,aAAa,CAACX,kBAAAA,CAAEC,SAAS,CAACpF,IAAAA,CAAAA,CAAAA;AACzD;AACD,aAAA;AACH,QAAA;AAEAwE,QAAAA,MAAAA,CAAOgB,IAAI,CAACC,KAAAA,CAAAA;AACd,IAAA,CAAA,CAAA;IAEA,OAAOjB,MAAAA;AACT;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"transform-content-types-to-models.js","sources":["../../src/utils/transform-content-types-to-models.ts"],"sourcesContent":["import { type Model, type Identifiers } from '@strapi/database';\nimport type { Struct, Schema } from '@strapi/types';\nimport { createId } from '@paralleldrive/cuid2';\nimport assert from 'node:assert';\nimport _ from 'lodash';\n\n/**\n * Because strapi/database models don't know about things like components or dynamic zones, we use this file to convert them\n * to a relations format that it recognizes\n *\n * Therefore we have to keep an additional set of helpers/extensions to the database naming methods\n *\n * IMPORTANT!\n * If we use short versions of anything, we MUST call getNameFromTokens directly; attempting to shorten them ourselves\n * prevents the unshortened name map from being filled properly, so for example it will think that the short name\n * 'collection4f3a_cmps' maps to the unshortened 'collectionname_cmps' rather than 'collectionname_components'\n * Therefore, we only use the identifiers helpers in cases where we do not do any of our own shortening\n */\n\nexport const getComponentJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getDzJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnEntityName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'entity', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnInverseName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'component', shortName: 'cmp', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentTypeColumn = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([{ name: 'component_type', compressible: false }]);\n};\n\nexport const getComponentFkIndexName = (contentType: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: contentType, compressible: true },\n { name: 'entity', compressible: false },\n { name: 'fk', compressible: false },\n ]);\n};\n\n// const { ID_COLUMN: id, FIELD_COLUMN: field, ORDER_COLUMN: order } = identifiers;\n\nexport type LoadedContentTypeModel = Struct.ContentTypeSchema &\n Required<Pick<Struct.ContentTypeSchema, 'collectionName' | 'uid' | 'modelName'>> &\n Pick<Model, 'lifecycles'>;\n\n// Transforms an attribute (particularly for relation types) into the format that strapi/database accepts\nexport const transformAttribute = (\n name: string,\n attribute: Schema.Attribute.AnyAttribute,\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n switch (attribute.type) {\n case 'media': {\n return {\n type: 'relation',\n relation: attribute.multiple === true ? 'morphMany' : 'morphOne',\n target: 'plugin::upload.file',\n morphBy: 'related',\n };\n }\n case 'component': {\n const joinTableName = getComponentJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n return {\n type: 'relation',\n relation: attribute.repeatable === true ? 'oneToMany' : 'oneToOne',\n target: attribute.component,\n\n // We need the join table name to be deterministic,\n // We need to allow passing the join table name as an option\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n inverseJoinColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n on: {\n field: name,\n },\n orderColumnName: identifiers.ORDER_COLUMN,\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n case 'dynamiczone': {\n const joinTableName = getDzJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n\n return {\n type: 'relation',\n relation: 'morphToMany',\n // TODO: handle restrictions at some point\n // target: attribute.components,\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n morphColumn: {\n idColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n typeColumn: {\n name: compTypeColumn,\n },\n typeField: '__component',\n },\n on: {\n field: name,\n },\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n default: {\n return attribute;\n }\n }\n};\n\nexport const transformAttributes = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n return Object.keys(contentType.attributes! || {}).reduce((attrs, attrName) => {\n return {\n ...attrs,\n [attrName]: transformAttribute(\n attrName,\n contentType.attributes[attrName]!,\n contentType,\n identifiers\n ),\n };\n }, {});\n};\n\nexport const hasComponentsOrDz = (\n contentType: LoadedContentTypeModel\n): contentType is LoadedContentTypeModel & { type: 'dynamiczone' | 'component' } => {\n return Object.values(contentType.attributes || {}).some(\n (({ type }: { type: string }) => type === 'dynamiczone' || type === 'component') as any\n );\n};\n\nexport const createDocumentId = createId;\n\nconst createCompoLinkModel = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n): Model => {\n const name = getComponentJoinTableName(contentType.collectionName, identifiers);\n\n const entityId = getComponentJoinColumnEntityName(identifiers);\n const componentId = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n const fkIndex = getComponentFkIndexName(contentType.collectionName, identifiers);\n\n return {\n // TODO: make sure there can't be any conflicts with a prefix\n singularName: name,\n uid: name,\n tableName: name,\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n [entityId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [componentId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [compTypeColumn]: {\n type: 'string',\n },\n [identifiers.FIELD_COLUMN]: {\n type: 'string',\n },\n [identifiers.ORDER_COLUMN]: {\n type: 'float',\n column: {\n unsigned: true,\n defaultTo: null,\n },\n },\n },\n indexes: [\n {\n name: identifiers.getIndexName([contentType.collectionName, identifiers.FIELD_COLUMN]),\n columns: [identifiers.FIELD_COLUMN],\n },\n {\n name: identifiers.getIndexName([contentType.collectionName, compTypeColumn]),\n columns: [compTypeColumn],\n },\n {\n name: fkIndex,\n columns: [entityId],\n },\n {\n // NOTE: since we don't include attribute names, we need to be careful not to create another unique index\n name: identifiers.getUniqueIndexName([contentType.collectionName]),\n columns: [entityId, componentId, identifiers.FIELD_COLUMN, compTypeColumn],\n type: 'unique',\n },\n ],\n foreignKeys: [\n {\n name: fkIndex,\n columns: [entityId],\n referencedColumns: [identifiers.ID_COLUMN],\n referencedTable: identifiers.getTableName(contentType.collectionName),\n onDelete: 'CASCADE',\n },\n ],\n };\n};\n\nexport const transformContentTypesToModels = (\n contentTypes: LoadedContentTypeModel[],\n identifiers: Identifiers\n): Model[] => {\n const models: Model[] = [];\n const reservedAttributeNames = new Set(['document_id', identifiers.ID_COLUMN]);\n\n contentTypes.forEach((contentType) => {\n assert(contentType.collectionName, 'Content type \"collectionName\" is required');\n assert(contentType.modelName, 'Content type \"modelName\" is required');\n assert(contentType.uid, 'Content type \"uid\" is required');\n\n // Add document id to content types\n // as it is not documented\n const documentIdAttribute: Record<string, Schema.Attribute.AnyAttribute> =\n contentType.modelType === 'contentType'\n ? { documentId: { type: 'string', default: createDocumentId } }\n : {};\n\n // TODO: this needs to be combined with getReservedNames, we should not be maintaining two lists\n // Prevent user from creating a documentId attribute\n Object.keys(contentType.attributes || {}).forEach((attributeName) => {\n const snakeCasedAttributeName = _.snakeCase(attributeName);\n if (reservedAttributeNames.has(snakeCasedAttributeName)) {\n throw new Error(\n `The attribute \"${attributeName}\" is reserved and cannot be used in a model. Please rename \"${contentType.modelName}\" attribute \"${attributeName}\" to something else.`\n );\n }\n });\n\n if (hasComponentsOrDz(contentType)) {\n const compoLinkModel = createCompoLinkModel(contentType, identifiers);\n models.push(compoLinkModel);\n }\n\n const model: Model = {\n uid: contentType.uid,\n singularName: contentType.modelName,\n tableName: contentType.collectionName, // This gets shortened in metadata.loadModels(), so we don't shorten here or it will happen twice\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n ...documentIdAttribute,\n ...transformAttributes(contentType, identifiers),\n },\n indexes: contentType.indexes as Model['indexes'],\n foreignKeys: contentType.foreignKeys as Model['foreignKeys'],\n lifecycles: contentType?.lifecycles ?? {},\n };\n\n // Document lookups: secondary btree index declared here so syncSchema owns it\n // (instead of DDL in internal migration `5.0.0-06-add-document-id-indexes`, now a no-op).\n // Keep the exact same name/columns schema sync already produced so existing databases\n // see no index diff on upgrade (a rename would orphan the old index, since the schema\n // builder's dropIndex is a silent no-op unless forceMigration is enabled).\n if (contentType.modelType === 'contentType') {\n model.indexes = [\n ...(model.indexes || []),\n {\n name: identifiers.getIndexName([contentType.collectionName, 'documents']),\n // Filter attributes that are not in the schema\n columns: ['documentId', 'locale', 'publishedAt']\n .filter((n) => model.attributes[n])\n .map((name) => identifiers.getColumnName(_.snakeCase(name))),\n },\n ];\n }\n\n models.push(model);\n });\n\n return models;\n};\n"],"names":["getComponentJoinTableName","collectionName","identifiers","getNameFromTokens","name","compressible","shortName","getDzJoinTableName","getComponentJoinColumnEntityName","getComponentJoinColumnInverseName","getComponentTypeColumn","getComponentFkIndexName","contentType","transformAttribute","attribute","type","relation","multiple","target","morphBy","joinTableName","joinColumnEntityName","joinColumnInverseName","compTypeColumn","repeatable","component","joinTable","joinColumn","referencedColumn","ID_COLUMN","inverseJoinColumn","on","field","orderColumnName","ORDER_COLUMN","orderBy","order","pivotColumns","FIELD_COLUMN","morphColumn","idColumn","typeColumn","typeField","transformAttributes","Object","keys","attributes","reduce","attrs","attrName","hasComponentsOrDz","values","some","createDocumentId","createId","createCompoLinkModel","entityId","componentId","fkIndex","singularName","uid","tableName","column","unsigned","defaultTo","indexes","getIndexName","columns","getUniqueIndexName","foreignKeys","referencedColumns","referencedTable","getTableName","onDelete","transformContentTypesToModels","contentTypes","models","reservedAttributeNames","Set","forEach","assert","modelName","documentIdAttribute","modelType","documentId","default","attributeName","snakeCasedAttributeName","_","snakeCase","has","Error","compoLinkModel","push","model","lifecycles","filter","n","map","getColumnName"],"mappings":";;;;;;;;;;;AAMA;;;;;;;;;;;AAWC,IAEM,MAAMA,yBAAAA,GAA4B,CAACC,cAAAA,EAAwBC,WAAAA,GAAAA;IAChE,OAAOA,WAAAA,CAAYC,iBAAiB,CAAC;AACnC,QAAA;YAAEC,IAAAA,EAAMH,cAAAA;YAAgBI,YAAAA,EAAc;AAAK,SAAA;AAC3C,QAAA;YAAED,IAAAA,EAAM,YAAA;YAAcE,SAAAA,EAAW,MAAA;YAAQD,YAAAA,EAAc;AAAM;AAC9D,KAAA,CAAA;AACH;AAEO,MAAME,kBAAAA,GAAqB,CAACN,cAAAA,EAAwBC,WAAAA,GAAAA;IACzD,OAAOA,WAAAA,CAAYC,iBAAiB,CAAC;AACnC,QAAA;YAAEC,IAAAA,EAAMH,cAAAA;YAAgBI,YAAAA,EAAc;AAAK,SAAA;AAC3C,QAAA;YAAED,IAAAA,EAAM,YAAA;YAAcE,SAAAA,EAAW,MAAA;YAAQD,YAAAA,EAAc;AAAM;AAC9D,KAAA,CAAA;AACH;AAEO,MAAMG,mCAAmC,CAACN,WAAAA,GAAAA;IAC/C,OAAOA,WAAAA,CAAYC,iBAAiB,CAAC;AACnC,QA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D,CAAAA,CAAE,CAAA,CACjCC,GAAG,CAAC,CAAC9F,IAAAA,GAASF,WAAAA,CAAYiG,aAAa,CAACX,kBAAAA,CAAEC,SAAS,CAACrF,IAAAA,CAAAA,CAAAA;AACzD;AACD,aAAA;AACH,QAAA;AAEAwE,QAAAA,MAAAA,CAAOiB,IAAI,CAACC,KAAAA,CAAAA;AACd,IAAA,CAAA,CAAA;IAEA,OAAOlB,MAAAA;AACT;;;;;;;;;;;;;;"}
@@ -295,6 +295,10 @@ const createCompoLinkModel = (contentType, identifiers)=>{
295
295
  };
296
296
  const transformContentTypesToModels = (contentTypes, identifiers)=>{
297
297
  const models = [];
298
+ const reservedAttributeNames = new Set([
299
+ 'document_id',
300
+ identifiers.ID_COLUMN
301
+ ]);
298
302
  contentTypes.forEach((contentType)=>{
299
303
  assert(contentType.collectionName, 'Content type "collectionName" is required');
300
304
  assert(contentType.modelName, 'Content type "modelName" is required');
@@ -309,13 +313,9 @@ const transformContentTypesToModels = (contentTypes, identifiers)=>{
309
313
  } : {};
310
314
  // TODO: this needs to be combined with getReservedNames, we should not be maintaining two lists
311
315
  // Prevent user from creating a documentId attribute
312
- const reservedAttributeNames = [
313
- 'document_id',
314
- identifiers.ID_COLUMN
315
- ];
316
316
  Object.keys(contentType.attributes || {}).forEach((attributeName)=>{
317
317
  const snakeCasedAttributeName = _.snakeCase(attributeName);
318
- if (reservedAttributeNames.includes(snakeCasedAttributeName)) {
318
+ if (reservedAttributeNames.has(snakeCasedAttributeName)) {
319
319
  throw new Error(`The attribute "${attributeName}" is reserved and cannot be used in a model. Please rename "${contentType.modelName}" attribute "${attributeName}" to something else.`);
320
320
  }
321
321
  });
@@ -1 +1 @@
1
- {"version":3,"file":"transform-content-types-to-models.mjs","sources":["../../src/utils/transform-content-types-to-models.ts"],"sourcesContent":["import { type Model, type Identifiers } from '@strapi/database';\nimport type { Struct, Schema } from '@strapi/types';\nimport { createId } from '@paralleldrive/cuid2';\nimport assert from 'node:assert';\nimport _ from 'lodash';\n\n/**\n * Because strapi/database models don't know about things like components or dynamic zones, we use this file to convert them\n * to a relations format that it recognizes\n *\n * Therefore we have to keep an additional set of helpers/extensions to the database naming methods\n *\n * IMPORTANT!\n * If we use short versions of anything, we MUST call getNameFromTokens directly; attempting to shorten them ourselves\n * prevents the unshortened name map from being filled properly, so for example it will think that the short name\n * 'collection4f3a_cmps' maps to the unshortened 'collectionname_cmps' rather than 'collectionname_components'\n * Therefore, we only use the identifiers helpers in cases where we do not do any of our own shortening\n */\n\nexport const getComponentJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getDzJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnEntityName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'entity', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnInverseName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'component', shortName: 'cmp', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentTypeColumn = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([{ name: 'component_type', compressible: false }]);\n};\n\nexport const getComponentFkIndexName = (contentType: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: contentType, compressible: true },\n { name: 'entity', compressible: false },\n { name: 'fk', compressible: false },\n ]);\n};\n\n// const { ID_COLUMN: id, FIELD_COLUMN: field, ORDER_COLUMN: order } = identifiers;\n\nexport type LoadedContentTypeModel = Struct.ContentTypeSchema &\n Required<Pick<Struct.ContentTypeSchema, 'collectionName' | 'uid' | 'modelName'>> &\n Pick<Model, 'lifecycles'>;\n\n// Transforms an attribute (particularly for relation types) into the format that strapi/database accepts\nexport const transformAttribute = (\n name: string,\n attribute: Schema.Attribute.AnyAttribute,\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n switch (attribute.type) {\n case 'media': {\n return {\n type: 'relation',\n relation: attribute.multiple === true ? 'morphMany' : 'morphOne',\n target: 'plugin::upload.file',\n morphBy: 'related',\n };\n }\n case 'component': {\n const joinTableName = getComponentJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n return {\n type: 'relation',\n relation: attribute.repeatable === true ? 'oneToMany' : 'oneToOne',\n target: attribute.component,\n\n // We need the join table name to be deterministic,\n // We need to allow passing the join table name as an option\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n inverseJoinColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n on: {\n field: name,\n },\n orderColumnName: identifiers.ORDER_COLUMN,\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n case 'dynamiczone': {\n const joinTableName = getDzJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n\n return {\n type: 'relation',\n relation: 'morphToMany',\n // TODO: handle restrictions at some point\n // target: attribute.components,\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n morphColumn: {\n idColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n typeColumn: {\n name: compTypeColumn,\n },\n typeField: '__component',\n },\n on: {\n field: name,\n },\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n default: {\n return attribute;\n }\n }\n};\n\nexport const transformAttributes = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n return Object.keys(contentType.attributes! || {}).reduce((attrs, attrName) => {\n return {\n ...attrs,\n [attrName]: transformAttribute(\n attrName,\n contentType.attributes[attrName]!,\n contentType,\n identifiers\n ),\n };\n }, {});\n};\n\nexport const hasComponentsOrDz = (\n contentType: LoadedContentTypeModel\n): contentType is LoadedContentTypeModel & { type: 'dynamiczone' | 'component' } => {\n return Object.values(contentType.attributes || {}).some(\n (({ type }: { type: string }) => type === 'dynamiczone' || type === 'component') as any\n );\n};\n\nexport const createDocumentId = createId;\n\nconst createCompoLinkModel = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n): Model => {\n const name = getComponentJoinTableName(contentType.collectionName, identifiers);\n\n const entityId = getComponentJoinColumnEntityName(identifiers);\n const componentId = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n const fkIndex = getComponentFkIndexName(contentType.collectionName, identifiers);\n\n return {\n // TODO: make sure there can't be any conflicts with a prefix\n singularName: name,\n uid: name,\n tableName: name,\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n [entityId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [componentId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [compTypeColumn]: {\n type: 'string',\n },\n [identifiers.FIELD_COLUMN]: {\n type: 'string',\n },\n [identifiers.ORDER_COLUMN]: {\n type: 'float',\n column: {\n unsigned: true,\n defaultTo: null,\n },\n },\n },\n indexes: [\n {\n name: identifiers.getIndexName([contentType.collectionName, identifiers.FIELD_COLUMN]),\n columns: [identifiers.FIELD_COLUMN],\n },\n {\n name: identifiers.getIndexName([contentType.collectionName, compTypeColumn]),\n columns: [compTypeColumn],\n },\n {\n name: fkIndex,\n columns: [entityId],\n },\n {\n // NOTE: since we don't include attribute names, we need to be careful not to create another unique index\n name: identifiers.getUniqueIndexName([contentType.collectionName]),\n columns: [entityId, componentId, identifiers.FIELD_COLUMN, compTypeColumn],\n type: 'unique',\n },\n ],\n foreignKeys: [\n {\n name: fkIndex,\n columns: [entityId],\n referencedColumns: [identifiers.ID_COLUMN],\n referencedTable: identifiers.getTableName(contentType.collectionName),\n onDelete: 'CASCADE',\n },\n ],\n };\n};\n\nexport const transformContentTypesToModels = (\n contentTypes: LoadedContentTypeModel[],\n identifiers: Identifiers\n): Model[] => {\n const models: Model[] = [];\n\n contentTypes.forEach((contentType) => {\n assert(contentType.collectionName, 'Content type \"collectionName\" is required');\n assert(contentType.modelName, 'Content type \"modelName\" is required');\n assert(contentType.uid, 'Content type \"uid\" is required');\n\n // Add document id to content types\n // as it is not documented\n const documentIdAttribute: Record<string, Schema.Attribute.AnyAttribute> =\n contentType.modelType === 'contentType'\n ? { documentId: { type: 'string', default: createDocumentId } }\n : {};\n\n // TODO: this needs to be combined with getReservedNames, we should not be maintaining two lists\n // Prevent user from creating a documentId attribute\n const reservedAttributeNames = ['document_id', identifiers.ID_COLUMN];\n Object.keys(contentType.attributes || {}).forEach((attributeName) => {\n const snakeCasedAttributeName = _.snakeCase(attributeName);\n if (reservedAttributeNames.includes(snakeCasedAttributeName)) {\n throw new Error(\n `The attribute \"${attributeName}\" is reserved and cannot be used in a model. Please rename \"${contentType.modelName}\" attribute \"${attributeName}\" to something else.`\n );\n }\n });\n\n if (hasComponentsOrDz(contentType)) {\n const compoLinkModel = createCompoLinkModel(contentType, identifiers);\n models.push(compoLinkModel);\n }\n\n const model: Model = {\n uid: contentType.uid,\n singularName: contentType.modelName,\n tableName: contentType.collectionName, // This gets shortened in metadata.loadModels(), so we don't shorten here or it will happen twice\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n ...documentIdAttribute,\n ...transformAttributes(contentType, identifiers),\n },\n indexes: contentType.indexes as Model['indexes'],\n foreignKeys: contentType.foreignKeys as Model['foreignKeys'],\n lifecycles: contentType?.lifecycles ?? {},\n };\n\n // Document lookups: secondary btree index declared here so syncSchema owns it\n // (instead of DDL in internal migration `5.0.0-06-add-document-id-indexes`, now a no-op).\n // Keep the exact same name/columns schema sync already produced so existing databases\n // see no index diff on upgrade (a rename would orphan the old index, since the schema\n // builder's dropIndex is a silent no-op unless forceMigration is enabled).\n if (contentType.modelType === 'contentType') {\n model.indexes = [\n ...(model.indexes || []),\n {\n name: identifiers.getIndexName([contentType.collectionName, 'documents']),\n // Filter attributes that are not in the schema\n columns: ['documentId', 'locale', 'publishedAt']\n .filter((n) => model.attributes[n])\n .map((name) => identifiers.getColumnName(_.snakeCase(name))),\n },\n ];\n }\n\n models.push(model);\n });\n\n return models;\n};\n"],"names":["getComponentJoinTableName","collectionName","identifiers","getNameFromTokens","name","compressible","shortName","getDzJoinTableName","getComponentJoinColumnEntityName","getComponentJoinColumnInverseName","getComponentTypeColumn","getComponentFkIndexName","contentType","transformAttribute","attribute","type","relation","multiple","target","morphBy","joinTableName","joinColumnEntityName","joinColumnInverseName","compTypeColumn","repeatable","component","joinTable","joinColumn","referencedColumn","ID_COLUMN","inverseJoinColumn","on","field","orderColumnName","ORDER_COLUMN","orderBy","order","pivotColumns","FIELD_COLUMN","morphColumn","idColumn","typeColumn","typeField","transformAttributes","Object","keys","attributes","reduce","attrs","attrName","hasComponentsOrDz","values","some","createDocumentId","createId","createCompoLinkModel","entityId","componentId","fkIndex","singularName","uid","tableName","column","unsigned","defaultTo","indexes","getIndexName","columns","getUniqueIndexName","foreignKeys","referencedColumns","referencedTable","getTableName","onDelete","transformContentTypesToModels","contentTypes","models","forEach","assert","modelName","documentIdAttribute","modelType","documentId","default","reservedAttributeNames","attributeName","snakeCasedAttributeName","_","snakeCase","includes","Error","compoLinkModel","push","model","lifecycles","filter","n","map","getColumnName"],"mappings":";;;;A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AAAA,EAAM;AACR,iBAAA;AACA,gBAAA,GAAGiE,mBAAmB;gBACtB,GAAGrC,mBAAAA,CAAoB/B,aAAaV,WAAAA;AACtC,aAAA;AACA+D,YAAAA,OAAAA,EAASrD,YAAYqD,OAAO;AAC5BI,YAAAA,WAAAA,EAAazD,YAAYyD,WAAW;YACpCyB,UAAAA,EAAYlF,WAAAA,EAAakF,cAAc;AACzC,SAAA;;;;;;QAOA,IAAIlF,WAAAA,CAAYqE,SAAS,KAAK,aAAA,EAAe;AAC3CY,YAAAA,KAAAA,CAAM5B,OAAO,GAAG;mBACV4B,KAAAA,CAAM5B,OAAO,IAAI,EAAE;AACvB,gBAAA;oBACE7D,IAAAA,EAAMF,WAAAA,CAAYgE,YAAY,CAAC;AAACtD,wBAAAA,WAAAA,CAAYX,cAAc;AAAE,wBAAA;AAAY,qBAAA,CAAA;;oBAExEkE,OAAAA,EAAS;AAAC,wBAAA,YAAA;AAAc,wBAAA,QAAA;AAAU,wBAAA;AAAc,qBAAA,CAC7C4B,MAAM,CAAC,CAACC,IAAMH,KAAAA,CAAM/C,UAAU,CAACkD,CAAAA,CAAE,CAAA,CACjCC,GAAG,CAAC,CAAC7F,IAAAA,GAASF,WAAAA,CAAYgG,aAAa,CAACX,CAAAA,CAAEC,SAAS,CAACpF,IAAAA,CAAAA,CAAAA;AACzD;AACD,aAAA;AACH,QAAA;AAEAwE,QAAAA,MAAAA,CAAOgB,IAAI,CAACC,KAAAA,CAAAA;AACd,IAAA,CAAA,CAAA;IAEA,OAAOjB,MAAAA;AACT;;;;"}
1
+ {"version":3,"file":"transform-content-types-to-models.mjs","sources":["../../src/utils/transform-content-types-to-models.ts"],"sourcesContent":["import { type Model, type Identifiers } from '@strapi/database';\nimport type { Struct, Schema } from '@strapi/types';\nimport { createId } from '@paralleldrive/cuid2';\nimport assert from 'node:assert';\nimport _ from 'lodash';\n\n/**\n * Because strapi/database models don't know about things like components or dynamic zones, we use this file to convert them\n * to a relations format that it recognizes\n *\n * Therefore we have to keep an additional set of helpers/extensions to the database naming methods\n *\n * IMPORTANT!\n * If we use short versions of anything, we MUST call getNameFromTokens directly; attempting to shorten them ourselves\n * prevents the unshortened name map from being filled properly, so for example it will think that the short name\n * 'collection4f3a_cmps' maps to the unshortened 'collectionname_cmps' rather than 'collectionname_components'\n * Therefore, we only use the identifiers helpers in cases where we do not do any of our own shortening\n */\n\nexport const getComponentJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getDzJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnEntityName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'entity', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnInverseName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'component', shortName: 'cmp', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentTypeColumn = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([{ name: 'component_type', compressible: false }]);\n};\n\nexport const getComponentFkIndexName = (contentType: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: contentType, compressible: true },\n { name: 'entity', compressible: false },\n { name: 'fk', compressible: false },\n ]);\n};\n\n// const { ID_COLUMN: id, FIELD_COLUMN: field, ORDER_COLUMN: order } = identifiers;\n\nexport type LoadedContentTypeModel = Struct.ContentTypeSchema &\n Required<Pick<Struct.ContentTypeSchema, 'collectionName' | 'uid' | 'modelName'>> &\n Pick<Model, 'lifecycles'>;\n\n// Transforms an attribute (particularly for relation types) into the format that strapi/database accepts\nexport const transformAttribute = (\n name: string,\n attribute: Schema.Attribute.AnyAttribute,\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n switch (attribute.type) {\n case 'media': {\n return {\n type: 'relation',\n relation: attribute.multiple === true ? 'morphMany' : 'morphOne',\n target: 'plugin::upload.file',\n morphBy: 'related',\n };\n }\n case 'component': {\n const joinTableName = getComponentJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n return {\n type: 'relation',\n relation: attribute.repeatable === true ? 'oneToMany' : 'oneToOne',\n target: attribute.component,\n\n // We need the join table name to be deterministic,\n // We need to allow passing the join table name as an option\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n inverseJoinColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n on: {\n field: name,\n },\n orderColumnName: identifiers.ORDER_COLUMN,\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n case 'dynamiczone': {\n const joinTableName = getDzJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n\n return {\n type: 'relation',\n relation: 'morphToMany',\n // TODO: handle restrictions at some point\n // target: attribute.components,\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n morphColumn: {\n idColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n typeColumn: {\n name: compTypeColumn,\n },\n typeField: '__component',\n },\n on: {\n field: name,\n },\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n default: {\n return attribute;\n }\n }\n};\n\nexport const transformAttributes = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n return Object.keys(contentType.attributes! || {}).reduce((attrs, attrName) => {\n return {\n ...attrs,\n [attrName]: transformAttribute(\n attrName,\n contentType.attributes[attrName]!,\n contentType,\n identifiers\n ),\n };\n }, {});\n};\n\nexport const hasComponentsOrDz = (\n contentType: LoadedContentTypeModel\n): contentType is LoadedContentTypeModel & { type: 'dynamiczone' | 'component' } => {\n return Object.values(contentType.attributes || {}).some(\n (({ type }: { type: string }) => type === 'dynamiczone' || type === 'component') as any\n );\n};\n\nexport const createDocumentId = createId;\n\nconst createCompoLinkModel = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n): Model => {\n const name = getComponentJoinTableName(contentType.collectionName, identifiers);\n\n const entityId = getComponentJoinColumnEntityName(identifiers);\n const componentId = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n const fkIndex = getComponentFkIndexName(contentType.collectionName, identifiers);\n\n return {\n // TODO: make sure there can't be any conflicts with a prefix\n singularName: name,\n uid: name,\n tableName: name,\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n [entityId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [componentId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [compTypeColumn]: {\n type: 'string',\n },\n [identifiers.FIELD_COLUMN]: {\n type: 'string',\n },\n [identifiers.ORDER_COLUMN]: {\n type: 'float',\n column: {\n unsigned: true,\n defaultTo: null,\n },\n },\n },\n indexes: [\n {\n name: identifiers.getIndexName([contentType.collectionName, identifiers.FIELD_COLUMN]),\n columns: [identifiers.FIELD_COLUMN],\n },\n {\n name: identifiers.getIndexName([contentType.collectionName, compTypeColumn]),\n columns: [compTypeColumn],\n },\n {\n name: fkIndex,\n columns: [entityId],\n },\n {\n // NOTE: since we don't include attribute names, we need to be careful not to create another unique index\n name: identifiers.getUniqueIndexName([contentType.collectionName]),\n columns: [entityId, componentId, identifiers.FIELD_COLUMN, compTypeColumn],\n type: 'unique',\n },\n ],\n foreignKeys: [\n {\n name: fkIndex,\n columns: [entityId],\n referencedColumns: [identifiers.ID_COLUMN],\n referencedTable: identifiers.getTableName(contentType.collectionName),\n onDelete: 'CASCADE',\n },\n ],\n };\n};\n\nexport const transformContentTypesToModels = (\n contentTypes: LoadedContentTypeModel[],\n identifiers: Identifiers\n): Model[] => {\n const models: Model[] = [];\n const reservedAttributeNames = new Set(['document_id', identifiers.ID_COLUMN]);\n\n contentTypes.forEach((contentType) => {\n assert(contentType.collectionName, 'Content type \"collectionName\" is required');\n assert(contentType.modelName, 'Content type \"modelName\" is required');\n assert(contentType.uid, 'Content type \"uid\" is required');\n\n // Add document id to content types\n // as it is not documented\n const documentIdAttribute: Record<string, Schema.Attribute.AnyAttribute> =\n contentType.modelType === 'contentType'\n ? { documentId: { type: 'string', default: createDocumentId } }\n : {};\n\n // TODO: this needs to be combined with getReservedNames, we should not be maintaining two lists\n // Prevent user from creating a documentId attribute\n Object.keys(contentType.attributes || {}).forEach((attributeName) => {\n const snakeCasedAttributeName = _.snakeCase(attributeName);\n if (reservedAttributeNames.has(snakeCasedAttributeName)) {\n throw new Error(\n `The attribute \"${attributeName}\" is reserved and cannot be used in a model. Please rename \"${contentType.modelName}\" attribute \"${attributeName}\" to something else.`\n );\n }\n });\n\n if (hasComponentsOrDz(contentType)) {\n const compoLinkModel = createCompoLinkModel(contentType, identifiers);\n models.push(compoLinkModel);\n }\n\n const model: Model = {\n uid: contentType.uid,\n singularName: contentType.modelName,\n tableName: contentType.collectionName, // This gets shortened in metadata.loadModels(), so we don't shorten here or it will happen twice\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n ...documentIdAttribute,\n ...transformAttributes(contentType, identifiers),\n },\n indexes: contentType.indexes as Model['indexes'],\n foreignKeys: contentType.foreignKeys as Model['foreignKeys'],\n lifecycles: contentType?.lifecycles ?? {},\n };\n\n // Document lookups: secondary btree index declared here so syncSchema owns it\n // (instead of DDL in internal migration `5.0.0-06-add-document-id-indexes`, now a no-op).\n // Keep the exact same name/columns schema sync already produced so existing databases\n // see no index diff on upgrade (a rename would orphan the old index, since the schema\n // builder's dropIndex is a silent no-op unless forceMigration is enabled).\n if (contentType.modelType === 'contentType') {\n model.indexes = [\n ...(model.indexes || []),\n {\n name: identifiers.getIndexName([contentType.collectionName, 'documents']),\n // Filter attributes that are not in the schema\n columns: ['documentId', 'locale', 'publishedAt']\n .filter((n) => model.attributes[n])\n .map((name) => identifiers.getColumnName(_.snakeCase(name))),\n },\n ];\n }\n\n models.push(model);\n });\n\n return models;\n};\n"],"names":["getComponentJoinTableName","collectionName","identifiers","getNameFromTokens","name","compressible","shortName","getDzJoinTableName","getComponentJoinColumnEntityName","getComponentJoinColumnInverseName","getComponentTypeColumn","getComponentFkIndexName","contentType","transformAttribute","attribute","type","relation","multiple","target","morphBy","joinTableName","joinColumnEntityName","joinColumnInverseName","compTypeColumn","repeatable","component","joinTable","joinColumn","referencedColumn","ID_COLUMN","inverseJoinColumn","on","field","orderColumnName","ORDER_COLUMN","orderBy","order","pivotColumns","FIELD_COLUMN","morphColumn","idColumn","typeColumn","typeField","transformAttributes","Object","keys","attributes","reduce","attrs","attrName","hasComponentsOrDz","values","some","createDocumentId","createId","createCompoLinkModel","entityId","componentId","fkIndex","singularName","uid","tableName","column","unsigned","defaultTo","indexes","getIndexName","columns","getUniqueIndexName","foreignKeys","referencedColumns","referencedTable","getTableName","onDelete","transformContentTypesToModels","contentTypes","models","reservedAttributeNames","Set","forEach","assert","modelName","documentIdAttribute","modelType","documentId","default","attributeName","snakeCasedAttributeName","_","snakeCase","has","Error","compoLinkModel","push","model","lifecycles","filter","n","map","getColumnName"],"mappings":";;;;AAMA;;;;;;;;;;;AAWC,IAEM,MAAMA,yBAAAA,GAA4B,CAACC,cAAAA,EAAwBC,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