@strapi/core 0.0.0-experimental.f31889311d753b5f7d95198ae84d8fce1d156cd6 → 0.0.0-experimental.f49f46a1c17445a39e8af3f63124bcccf73842e6

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 (156) hide show
  1. package/dist/Strapi.d.ts.map +1 -1
  2. package/dist/Strapi.js +10 -6
  3. package/dist/Strapi.js.map +1 -1
  4. package/dist/Strapi.mjs +9 -6
  5. package/dist/Strapi.mjs.map +1 -1
  6. package/dist/core-api/service/collection-type.d.ts +2 -2
  7. package/dist/ee/index.d.ts.map +1 -1
  8. package/dist/ee/index.js +6 -1
  9. package/dist/ee/index.js.map +1 -1
  10. package/dist/ee/index.mjs +6 -1
  11. package/dist/ee/index.mjs.map +1 -1
  12. package/dist/factories.js.map +1 -1
  13. package/dist/factories.mjs.map +1 -1
  14. package/dist/loaders/plugins/get-enabled-plugins.d.ts.map +1 -1
  15. package/dist/loaders/plugins/get-enabled-plugins.js +6 -3
  16. package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
  17. package/dist/loaders/plugins/get-enabled-plugins.mjs +6 -3
  18. package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
  19. package/dist/loaders/plugins/index.d.ts.map +1 -1
  20. package/dist/loaders/plugins/index.js +28 -1
  21. package/dist/loaders/plugins/index.js.map +1 -1
  22. package/dist/loaders/plugins/index.mjs +9 -1
  23. package/dist/loaders/plugins/index.mjs.map +1 -1
  24. package/dist/middlewares/query.js.map +1 -1
  25. package/dist/middlewares/query.mjs.map +1 -1
  26. package/dist/middlewares/security.d.ts.map +1 -1
  27. package/dist/middlewares/security.js +1 -1
  28. package/dist/middlewares/security.js.map +1 -1
  29. package/dist/middlewares/security.mjs +1 -1
  30. package/dist/middlewares/security.mjs.map +1 -1
  31. package/dist/migrations/database/5.0.0-discard-drafts.d.ts +12 -9
  32. package/dist/migrations/database/5.0.0-discard-drafts.d.ts.map +1 -1
  33. package/dist/migrations/database/5.0.0-discard-drafts.js +67 -11
  34. package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
  35. package/dist/migrations/database/5.0.0-discard-drafts.mjs +68 -12
  36. package/dist/migrations/database/5.0.0-discard-drafts.mjs.map +1 -1
  37. package/dist/migrations/draft-publish.d.ts +1 -1
  38. package/dist/migrations/draft-publish.d.ts.map +1 -1
  39. package/dist/migrations/draft-publish.js.map +1 -1
  40. package/dist/migrations/draft-publish.mjs.map +1 -1
  41. package/dist/migrations/i18n.d.ts +5 -0
  42. package/dist/migrations/i18n.d.ts.map +1 -0
  43. package/dist/migrations/i18n.js +54 -0
  44. package/dist/migrations/i18n.js.map +1 -0
  45. package/dist/migrations/i18n.mjs +54 -0
  46. package/dist/migrations/i18n.mjs.map +1 -0
  47. package/dist/migrations/index.d.ts +5 -0
  48. package/dist/migrations/index.d.ts.map +1 -0
  49. package/dist/migrations/index.js +15 -0
  50. package/dist/migrations/index.js.map +1 -0
  51. package/dist/migrations/index.mjs +15 -0
  52. package/dist/migrations/index.mjs.map +1 -0
  53. package/dist/providers/admin.d.ts.map +1 -1
  54. package/dist/providers/admin.js.map +1 -1
  55. package/dist/providers/admin.mjs.map +1 -1
  56. package/dist/providers/registries.js +3 -3
  57. package/dist/providers/registries.js.map +1 -1
  58. package/dist/providers/registries.mjs +3 -3
  59. package/dist/providers/registries.mjs.map +1 -1
  60. package/dist/registries/policies.d.ts +1 -1
  61. package/dist/registries/policies.d.ts.map +1 -1
  62. package/dist/registries/policies.js +1 -1
  63. package/dist/registries/policies.js.map +1 -1
  64. package/dist/registries/policies.mjs +1 -1
  65. package/dist/registries/policies.mjs.map +1 -1
  66. package/dist/services/content-api/index.d.ts +10 -12
  67. package/dist/services/content-api/index.d.ts.map +1 -1
  68. package/dist/services/content-api/permissions/index.d.ts +10 -12
  69. package/dist/services/content-api/permissions/index.d.ts.map +1 -1
  70. package/dist/services/content-api/permissions/providers/action.d.ts +5 -6
  71. package/dist/services/content-api/permissions/providers/action.d.ts.map +1 -1
  72. package/dist/services/content-api/permissions/providers/condition.d.ts +5 -6
  73. package/dist/services/content-api/permissions/providers/condition.d.ts.map +1 -1
  74. package/dist/services/cron.d.ts +3 -3
  75. package/dist/services/cron.d.ts.map +1 -1
  76. package/dist/services/cron.js +9 -4
  77. package/dist/services/cron.js.map +1 -1
  78. package/dist/services/cron.mjs +9 -4
  79. package/dist/services/cron.mjs.map +1 -1
  80. package/dist/services/document-service/common.d.ts +1 -1
  81. package/dist/services/document-service/common.d.ts.map +1 -1
  82. package/dist/services/document-service/common.js.map +1 -1
  83. package/dist/services/document-service/common.mjs.map +1 -1
  84. package/dist/services/document-service/entries.d.ts +2 -2
  85. package/dist/services/document-service/entries.d.ts.map +1 -1
  86. package/dist/services/document-service/entries.js +6 -7
  87. package/dist/services/document-service/entries.js.map +1 -1
  88. package/dist/services/document-service/entries.mjs +1 -2
  89. package/dist/services/document-service/entries.mjs.map +1 -1
  90. package/dist/services/document-service/index.d.ts +2 -1
  91. package/dist/services/document-service/index.d.ts.map +1 -1
  92. package/dist/services/document-service/index.js +3 -2
  93. package/dist/services/document-service/index.js.map +1 -1
  94. package/dist/services/document-service/index.mjs +3 -2
  95. package/dist/services/document-service/index.mjs.map +1 -1
  96. package/dist/services/document-service/repository.d.ts.map +1 -1
  97. package/dist/services/document-service/repository.js +60 -9
  98. package/dist/services/document-service/repository.js.map +1 -1
  99. package/dist/services/document-service/repository.mjs +61 -10
  100. package/dist/services/document-service/repository.mjs.map +1 -1
  101. package/dist/services/document-service/transform/id-map.d.ts.map +1 -1
  102. package/dist/services/document-service/transform/id-map.js +13 -4
  103. package/dist/services/document-service/transform/id-map.js.map +1 -1
  104. package/dist/services/document-service/transform/id-map.mjs +14 -5
  105. package/dist/services/document-service/transform/id-map.mjs.map +1 -1
  106. package/dist/services/document-service/transform/relations/extract/data-ids.d.ts.map +1 -1
  107. package/dist/services/document-service/transform/relations/extract/data-ids.js +13 -6
  108. package/dist/services/document-service/transform/relations/extract/data-ids.js.map +1 -1
  109. package/dist/services/document-service/transform/relations/extract/data-ids.mjs +13 -6
  110. package/dist/services/document-service/transform/relations/extract/data-ids.mjs.map +1 -1
  111. package/dist/services/document-service/transform/relations/transform/data-ids.d.ts.map +1 -1
  112. package/dist/services/document-service/transform/relations/transform/data-ids.js +16 -6
  113. package/dist/services/document-service/transform/relations/transform/data-ids.js.map +1 -1
  114. package/dist/services/document-service/transform/relations/transform/data-ids.mjs +17 -7
  115. package/dist/services/document-service/transform/relations/transform/data-ids.mjs.map +1 -1
  116. package/dist/services/document-service/transform/relations/utils/map-relation.d.ts.map +1 -1
  117. package/dist/services/document-service/transform/relations/utils/map-relation.js +0 -4
  118. package/dist/services/document-service/transform/relations/utils/map-relation.js.map +1 -1
  119. package/dist/services/document-service/transform/relations/utils/map-relation.mjs +0 -4
  120. package/dist/services/document-service/transform/relations/utils/map-relation.mjs.map +1 -1
  121. package/dist/services/document-service/utils/populate.d.ts.map +1 -1
  122. package/dist/services/document-service/utils/populate.js +4 -2
  123. package/dist/services/document-service/utils/populate.js.map +1 -1
  124. package/dist/services/document-service/utils/populate.mjs +4 -2
  125. package/dist/services/document-service/utils/populate.mjs.map +1 -1
  126. package/dist/services/document-service/utils/unidirectional-relations.d.ts +36 -0
  127. package/dist/services/document-service/utils/unidirectional-relations.d.ts.map +1 -0
  128. package/dist/services/document-service/utils/unidirectional-relations.js +69 -0
  129. package/dist/services/document-service/utils/unidirectional-relations.js.map +1 -0
  130. package/dist/services/document-service/utils/unidirectional-relations.mjs +69 -0
  131. package/dist/services/document-service/utils/unidirectional-relations.mjs.map +1 -0
  132. package/dist/services/entity-validator/blocks-validator.d.ts +1 -2
  133. package/dist/services/entity-validator/blocks-validator.d.ts.map +1 -1
  134. package/dist/services/entity-validator/blocks-validator.js +4 -3
  135. package/dist/services/entity-validator/blocks-validator.js.map +1 -1
  136. package/dist/services/entity-validator/blocks-validator.mjs +3 -3
  137. package/dist/services/entity-validator/blocks-validator.mjs.map +1 -1
  138. package/dist/services/entity-validator/index.d.ts +2 -1
  139. package/dist/services/entity-validator/index.d.ts.map +1 -1
  140. package/dist/services/entity-validator/index.js +16 -17
  141. package/dist/services/entity-validator/index.js.map +1 -1
  142. package/dist/services/entity-validator/index.mjs +20 -21
  143. package/dist/services/entity-validator/index.mjs.map +1 -1
  144. package/dist/services/entity-validator/validators.d.ts +32 -23
  145. package/dist/services/entity-validator/validators.d.ts.map +1 -1
  146. package/dist/services/entity-validator/validators.js +136 -63
  147. package/dist/services/entity-validator/validators.js.map +1 -1
  148. package/dist/services/entity-validator/validators.mjs +135 -63
  149. package/dist/services/entity-validator/validators.mjs.map +1 -1
  150. package/dist/utils/transform-content-types-to-models.d.ts +355 -23
  151. package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
  152. package/dist/utils/transform-content-types-to-models.js +2 -1
  153. package/dist/utils/transform-content-types-to-models.js.map +1 -1
  154. package/dist/utils/transform-content-types-to-models.mjs +2 -1
  155. package/dist/utils/transform-content-types-to-models.mjs.map +1 -1
  156. package/package.json +19 -19
@@ -1,4 +1,49 @@
1
- import { contentTypes, async } from "@strapi/utils";
1
+ import { async, contentTypes } from "@strapi/utils";
2
+ import { createDocumentService } from "../../services/document-service/index.mjs";
3
+ const hasDraftAndPublish = async (trx, meta) => {
4
+ const hasTable = await trx.schema.hasTable(meta.tableName);
5
+ if (!hasTable) {
6
+ return false;
7
+ }
8
+ const uid = meta.uid;
9
+ const model = strapi.getModel(uid);
10
+ const hasDP = contentTypes.hasDraftAndPublish(model);
11
+ if (!hasDP) {
12
+ return false;
13
+ }
14
+ return true;
15
+ };
16
+ async function copyPublishedEntriesToDraft({
17
+ db,
18
+ trx,
19
+ uid
20
+ }) {
21
+ const meta = db.metadata.get(uid);
22
+ const scalarAttributes = Object.values(meta.attributes).reduce((acc, attribute) => {
23
+ if (["id"].includes(attribute.columnName)) {
24
+ return acc;
25
+ }
26
+ if (contentTypes.isScalarAttribute(attribute)) {
27
+ acc.push(attribute.columnName);
28
+ }
29
+ return acc;
30
+ }, []);
31
+ await trx.into(
32
+ trx.raw(`?? (${scalarAttributes.map(() => `??`).join(", ")})`, [
33
+ meta.tableName,
34
+ ...scalarAttributes
35
+ ])
36
+ ).insert((subQb) => {
37
+ subQb.select(
38
+ ...scalarAttributes.map((att) => {
39
+ if (att === "published_at") {
40
+ return trx.raw("NULL as ??", "published_at");
41
+ }
42
+ return att;
43
+ })
44
+ ).from(meta.tableName).whereNotNull("published_at");
45
+ });
46
+ }
2
47
  async function* getBatchToDiscard({
3
48
  db,
4
49
  trx,
@@ -17,20 +62,31 @@ async function* getBatchToDiscard({
17
62
  }
18
63
  }
19
64
  const migrateUp = async (trx, db) => {
65
+ const dpModels = [];
20
66
  for (const meta of db.metadata.values()) {
21
- const hasTable = await trx.schema.hasTable(meta.tableName);
22
- if (!hasTable) {
23
- continue;
67
+ const hasDP = await hasDraftAndPublish(trx, meta);
68
+ if (hasDP) {
69
+ dpModels.push(meta);
24
70
  }
25
- const uid = meta.uid;
26
- const model = strapi.getModel(uid);
27
- const hasDP = contentTypes.hasDraftAndPublish(model);
28
- if (!hasDP) {
29
- continue;
71
+ }
72
+ for (const model of dpModels) {
73
+ await copyPublishedEntriesToDraft({ db, trx, uid: model.uid });
74
+ }
75
+ const documentService = createDocumentService(strapi, {
76
+ async validateEntityCreation(_, data) {
77
+ return data;
78
+ },
79
+ async validateEntityUpdate(_, data) {
80
+ return data;
30
81
  }
31
- const discardDraft = async (entry) => strapi.documents(uid).discardDraft({ documentId: entry.documentId, locale: entry.locale });
32
- for await (const batch of getBatchToDiscard({ db, trx, uid: meta.uid })) {
33
- await async.map(batch, discardDraft, { concurrency: 10 });
82
+ });
83
+ for (const model of dpModels) {
84
+ const discardDraft = async (entry) => documentService(model.uid).discardDraft({
85
+ documentId: entry.documentId,
86
+ locale: entry.locale
87
+ });
88
+ for await (const batch of getBatchToDiscard({ db, trx, uid: model.uid })) {
89
+ await async.map(batch, discardDraft, { concurrency: 1 });
34
90
  }
35
91
  }
36
92
  };
@@ -1 +1 @@
1
- {"version":3,"file":"5.0.0-discard-drafts.mjs","sources":["../../../src/migrations/database/5.0.0-discard-drafts.ts"],"sourcesContent":["/* eslint-disable no-continue */\nimport type { UID } from '@strapi/types';\nimport type { Database, Migration } from '@strapi/database';\nimport { async, contentTypes } from '@strapi/utils';\n\ntype DocumentVersion = { documentId: string; locale: string };\ntype Knex = Parameters<Migration['up']>[0];\n\n/**\n * Load a batch of versions to discard.\n *\n * Versions with only a draft version will be ignored.\n * Only versions with a published version (which always have a draft version) will be discarded.\n */\nexport async function* getBatchToDiscard({\n db,\n trx,\n uid,\n batchSize = 1000,\n}: {\n db: Database;\n trx: Knex;\n uid: string;\n batchSize?: number;\n}) {\n let offset = 0;\n let hasMore = true;\n\n while (hasMore) {\n // Look for the published entries to discard\n const batch: DocumentVersion[] = await db\n .queryBuilder(uid)\n .select(['id', 'documentId', 'locale'])\n .where({ publishedAt: { $ne: null } })\n .limit(batchSize)\n .offset(offset)\n .orderBy('id')\n .transacting(trx)\n .execute();\n\n if (batch.length < batchSize) {\n hasMore = false;\n }\n\n offset += batchSize;\n yield batch;\n }\n}\n\nconst migrateUp = async (trx: Knex, db: Database) => {\n for (const meta of db.metadata.values()) {\n const hasTable = await trx.schema.hasTable(meta.tableName);\n\n if (!hasTable) {\n continue;\n }\n\n const uid = meta.uid as UID.ContentType;\n const model = strapi.getModel(uid);\n const hasDP = contentTypes.hasDraftAndPublish(model);\n if (!hasDP) {\n continue;\n }\n\n const discardDraft = async (entry: DocumentVersion) =>\n strapi\n .documents(uid)\n // Discard draft by referencing the documentId and locale\n .discardDraft({ documentId: entry.documentId, locale: entry.locale });\n\n /**\n * Load a batch of entries (batched to prevent loading millions of rows at once ),\n * and discard them using the document service.\n */\n for await (const batch of getBatchToDiscard({ db, trx, uid: meta.uid })) {\n await async.map(batch, discardDraft, { concurrency: 10 });\n }\n }\n};\n\n/**\n * On V4 there was no concept of document, and an entry could be in a draft or published state.\n * But not both at the same time.\n *\n * On V5 we introduced the concept of document, and an entry can be in a draft or published state,\n * with the requirement that a document must always have a draft.\n *\n * This migration creates the document draft counterpart for all the entries that were in a published state.\n */\nexport const discardDocumentDrafts: Migration = {\n name: 'core::5.0.0-discard-drafts',\n async up(trx, db) {\n // TODO: Log to inform the user that the migration is running in the background\n await migrateUp(trx, db);\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":[],"mappings":";AAcA,gBAAuB,kBAAkB;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY;AACd,GAKG;AACD,MAAI,SAAS;AACb,MAAI,UAAU;AAEd,SAAO,SAAS;AAEd,UAAM,QAA2B,MAAM,GACpC,aAAa,GAAG,EAChB,OAAO,CAAC,MAAM,cAAc,QAAQ,CAAC,EACrC,MAAM,EAAE,aAAa,EAAE,KAAK,KAAO,EAAA,CAAC,EACpC,MAAM,SAAS,EACf,OAAO,MAAM,EACb,QAAQ,IAAI,EACZ,YAAY,GAAG,EACf,QAAQ;AAEP,QAAA,MAAM,SAAS,WAAW;AAClB,gBAAA;AAAA,IACZ;AAEU,cAAA;AACJ,UAAA;AAAA,EACR;AACF;AAEA,MAAM,YAAY,OAAO,KAAW,OAAiB;AACnD,aAAW,QAAQ,GAAG,SAAS,OAAA,GAAU;AACvC,UAAM,WAAW,MAAM,IAAI,OAAO,SAAS,KAAK,SAAS;AAEzD,QAAI,CAAC,UAAU;AACb;AAAA,IACF;AAEA,UAAM,MAAM,KAAK;AACX,UAAA,QAAQ,OAAO,SAAS,GAAG;AAC3B,UAAA,QAAQ,aAAa,mBAAmB,KAAK;AACnD,QAAI,CAAC,OAAO;AACV;AAAA,IACF;AAEA,UAAM,eAAe,OAAO,UAC1B,OACG,UAAU,GAAG,EAEb,aAAa,EAAE,YAAY,MAAM,YAAY,QAAQ,MAAM,QAAQ;AAMvD,qBAAA,SAAS,kBAAkB,EAAE,IAAI,KAAK,KAAK,KAAK,IAAI,CAAC,GAAG;AACvE,YAAM,MAAM,IAAI,OAAO,cAAc,EAAE,aAAa,IAAI;AAAA,IAC1D;AAAA,EACF;AACF;AAWO,MAAM,wBAAmC;AAAA,EAC9C,MAAM;AAAA,EACN,MAAM,GAAG,KAAK,IAAI;AAEV,UAAA,UAAU,KAAK,EAAE;AAAA,EACzB;AAAA,EACA,MAAM,OAAO;AACL,UAAA,IAAI,MAAM,iBAAiB;AAAA,EACnC;AACF;"}
1
+ {"version":3,"file":"5.0.0-discard-drafts.mjs","sources":["../../../src/migrations/database/5.0.0-discard-drafts.ts"],"sourcesContent":["/**\n * This migration is responsible for creating the draft counterpart for all the entries that were in a published state.\n *\n * In v4, entries could either be in a draft or published state, but not both at the same time.\n * In v5, we introduced the concept of document, and an entry can be in a draft or published state.\n *\n * This means the migration needs to create the draft counterpart if an entry was published.\n *\n * This migration performs the following steps:\n * 1. Creates draft entries for all published entries, without it's components, dynamic zones or relations.\n * 2. Using the document service, discard those same drafts to copy its relations.\n */\n\n/* eslint-disable no-continue */\nimport type { UID } from '@strapi/types';\nimport type { Database, Migration } from '@strapi/database';\nimport { async, contentTypes } from '@strapi/utils';\nimport { createDocumentService } from '../../services/document-service';\n\ntype DocumentVersion = { documentId: string; locale: string };\ntype Knex = Parameters<Migration['up']>[0];\n\n/**\n * Check if the model has draft and publish enabled.\n */\nconst hasDraftAndPublish = async (trx: Knex, meta: any) => {\n const hasTable = await trx.schema.hasTable(meta.tableName);\n\n if (!hasTable) {\n return false;\n }\n\n const uid = meta.uid as UID.ContentType;\n const model = strapi.getModel(uid);\n const hasDP = contentTypes.hasDraftAndPublish(model);\n if (!hasDP) {\n return false;\n }\n\n return true;\n};\n\n/**\n * Copy all the published entries to draft entries, without it's components, dynamic zones or relations.\n * This ensures all necessary draft's exist before copying it's relations.\n */\nasync function copyPublishedEntriesToDraft({\n db,\n trx,\n uid,\n}: {\n db: Database;\n trx: Knex;\n uid: string;\n}) {\n // Extract all scalar attributes to use in the insert query\n const meta = db.metadata.get(uid);\n\n // Get scalar attributes that will be copied over the new draft\n const scalarAttributes = Object.values(meta.attributes).reduce((acc, attribute: any) => {\n if (['id'].includes(attribute.columnName)) {\n return acc;\n }\n\n if (contentTypes.isScalarAttribute(attribute)) {\n acc.push(attribute.columnName);\n }\n\n return acc;\n }, [] as string[]);\n\n /**\n * Query to copy the published entries into draft entries.\n *\n * INSERT INTO tableName (columnName1, columnName2, columnName3, ...)\n * SELECT columnName1, columnName2, columnName3, ...\n * FROM tableName\n */\n await trx\n // INSERT INTO tableName (columnName1, columnName2, columnName3, ...)\n .into(\n trx.raw(`?? (${scalarAttributes.map(() => `??`).join(', ')})`, [\n meta.tableName,\n ...scalarAttributes,\n ])\n )\n .insert((subQb: typeof trx) => {\n // SELECT columnName1, columnName2, columnName3, ...\n subQb\n .select(\n ...scalarAttributes.map((att: string) => {\n // Override 'publishedAt' and 'updatedAt' attributes\n if (att === 'published_at') {\n return trx.raw('NULL as ??', 'published_at');\n }\n\n return att;\n })\n )\n .from(meta.tableName)\n // Only select entries that were published\n .whereNotNull('published_at');\n });\n}\n\n/**\n * Load a batch of versions to discard.\n *\n * Versions with only a draft version will be ignored.\n * Only versions with a published version (which always have a draft version) will be discarded.\n */\nexport async function* getBatchToDiscard({\n db,\n trx,\n uid,\n batchSize = 1000,\n}: {\n db: Database;\n trx: Knex;\n uid: string;\n batchSize?: number;\n}) {\n let offset = 0;\n let hasMore = true;\n\n while (hasMore) {\n // Look for the published entries to discard\n const batch: DocumentVersion[] = await db\n .queryBuilder(uid)\n .select(['id', 'documentId', 'locale'])\n .where({ publishedAt: { $ne: null } })\n .limit(batchSize)\n .offset(offset)\n .orderBy('id')\n .transacting(trx)\n .execute();\n\n if (batch.length < batchSize) {\n hasMore = false;\n }\n\n offset += batchSize;\n yield batch;\n }\n}\n\n/**\n * 2 pass migration to create the draft entries for all the published entries.\n * And then discard the drafts to copy the relations.\n */\nconst migrateUp = async (trx: Knex, db: Database) => {\n const dpModels = [];\n for (const meta of db.metadata.values()) {\n const hasDP = await hasDraftAndPublish(trx, meta);\n if (hasDP) {\n dpModels.push(meta);\n }\n }\n\n /**\n * Create plain draft entries for all the entries that were published.\n */\n for (const model of dpModels) {\n await copyPublishedEntriesToDraft({ db, trx, uid: model.uid });\n }\n\n /**\n * Discard the drafts will copy the relations from the published entries to the newly created drafts.\n *\n * Load a batch of entries (batched to prevent loading millions of rows at once ),\n * and discard them using the document service.\n *\n * NOTE: This is using a custom document service without any validations,\n * to prevent the migration from failing if users already had invalid data in V4.\n * E.g. @see https://github.com/strapi/strapi/issues/21583\n */\n const documentService = createDocumentService(strapi, {\n async validateEntityCreation(_, data) {\n return data;\n },\n async validateEntityUpdate(_, data) {\n // Data can be partially empty on partial updates\n // This migration doesn't trigger any update (or partial update),\n // so it's safe to return the data as is.\n return data as any;\n },\n });\n\n for (const model of dpModels) {\n const discardDraft = async (entry: DocumentVersion) =>\n documentService(model.uid as UID.ContentType).discardDraft({\n documentId: entry.documentId,\n locale: entry.locale,\n });\n\n for await (const batch of getBatchToDiscard({ db, trx, uid: model.uid })) {\n // NOTE: concurrency had to be disabled to prevent a race condition with self-references\n // TODO: improve performance in a safe way\n await async.map(batch, discardDraft, { concurrency: 1 });\n }\n }\n};\n\nexport const discardDocumentDrafts: Migration = {\n name: 'core::5.0.0-discard-drafts',\n async up(trx, db) {\n await migrateUp(trx, db);\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":[],"mappings":";;AAyBA,MAAM,qBAAqB,OAAO,KAAW,SAAc;AACzD,QAAM,WAAW,MAAM,IAAI,OAAO,SAAS,KAAK,SAAS;AAEzD,MAAI,CAAC,UAAU;AACN,WAAA;AAAA,EACT;AAEA,QAAM,MAAM,KAAK;AACX,QAAA,QAAQ,OAAO,SAAS,GAAG;AAC3B,QAAA,QAAQ,aAAa,mBAAmB,KAAK;AACnD,MAAI,CAAC,OAAO;AACH,WAAA;AAAA,EACT;AAEO,SAAA;AACT;AAMA,eAAe,4BAA4B;AAAA,EACzC;AAA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EACR;AACF;AAMA,MAAM,YAAY,OAAO,KAAW,OAAiB;AACnD,QAAM,WAAW,CAAA;AACjB,aAAW,QAAQ,GAAG,SAAS,OAAA,GAAU;AACvC,UAAM,QAAQ,MAAM,mBAAmB,KAAK,IAAI;AAChD,QAAI,OAAO;AACT,eAAS,KAAK,IAAI;AAAA,IACpB;AAAA,EACF;AAKA,aAAW,SAAS,UAAU;AAC5B,UAAM,4BAA4B,EAAE,IAAI,KAAK,KAAK,MAAM,KAAK;AAAA,EAC/D;AAYM,QAAA,kBAAkB,sBAAsB,QAAQ;AAAA,IACpD,MAAM,uBAAuB,GAAG,MAAM;AAC7B,aAAA;AAAA,IACT;AAAA,IACA,MAAM,qBAAqB,GAAG,MAAM;AAI3B,aAAA;AAAA,IACT;AAAA,EAAA,CACD;AAED,aAAW,SAAS,UAAU;AAC5B,UAAM,eAAe,OAAO,UAC1B,gBAAgB,MAAM,GAAsB,EAAE,aAAa;AAAA,MACzD,YAAY,MAAM;AAAA,MAClB,QAAQ,MAAM;AAAA,IAAA,CACf;AAEc,qBAAA,SAAS,kBAAkB,EAAE,IAAI,KAAK,KAAK,MAAM,IAAI,CAAC,GAAG;AAGxE,YAAM,MAAM,IAAI,OAAO,cAAc,EAAE,aAAa,GAAG;AAAA,IACzD;AAAA,EACF;AACF;AAEO,MAAM,wBAAmC;AAAA,EAC9C,MAAM;AAAA,EACN,MAAM,GAAG,KAAK,IAAI;AACV,UAAA,UAAU,KAAK,EAAE;AAAA,EACzB;AAAA,EACA,MAAM,OAAO;AACL,UAAA,IAAI,MAAM,iBAAiB;AAAA,EACnC;AACF;"}
@@ -1,5 +1,5 @@
1
1
  import { Schema } from '@strapi/types';
2
- interface Input {
2
+ export interface Input {
3
3
  oldContentTypes: Record<string, Schema.ContentType>;
4
4
  contentTypes: Record<string, Schema.ContentType>;
5
5
  }
@@ -1 +1 @@
1
- {"version":3,"file":"draft-publish.d.ts","sourceRoot":"","sources":["../../src/migrations/draft-publish.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAIvC,UAAU,KAAK;IACb,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IACpD,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;CAClD;AAED;;;;;;;GAOG;AACH,QAAA,MAAM,qBAAqB,sCAA6C,KAAK,kBAoC5E,CAAC;AAEF,QAAA,MAAM,sBAAsB,sCAA6C,KAAK,kBAqB7E,CAAC;AAEF,OAAO,EAAE,qBAAqB,IAAI,MAAM,EAAE,sBAAsB,IAAI,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"draft-publish.d.ts","sourceRoot":"","sources":["../../src/migrations/draft-publish.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAIvC,MAAM,WAAW,KAAK;IACpB,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IACpD,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;CAClD;AAED;;;;;;;GAOG;AACH,QAAA,MAAM,qBAAqB,sCAA6C,KAAK,kBAoC5E,CAAC;AAEF,QAAA,MAAM,sBAAsB,sCAA6C,KAAK,kBAqB7E,CAAC;AAEF,OAAO,EAAE,qBAAqB,IAAI,MAAM,EAAE,sBAAsB,IAAI,OAAO,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"draft-publish.js","sources":["../../src/migrations/draft-publish.ts"],"sourcesContent":["import { contentTypes as contentTypesUtils, async } from '@strapi/utils';\nimport { Schema } from '@strapi/types';\n\nimport { getBatchToDiscard } from './database/5.0.0-discard-drafts';\n\ninterface Input {\n oldContentTypes: Record<string, Schema.ContentType>;\n contentTypes: Record<string, Schema.ContentType>;\n}\n\n/**\n * Enable draft and publish for content types.\n *\n * Draft and publish disabled content types will have their entries published,\n * this migration clones those entries as drafts.\n *\n * TODO: Clone components, dynamic zones and relations\n */\nconst enableDraftAndPublish = async ({ oldContentTypes, contentTypes }: Input) => {\n if (!oldContentTypes) {\n return;\n }\n\n // run the after content types migrations\n return strapi.db.transaction(async (trx) => {\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n // if d&p was enabled set publishedAt to eq createdAt\n if (\n !contentTypesUtils.hasDraftAndPublish(oldContentType) &&\n contentTypesUtils.hasDraftAndPublish(contentType)\n ) {\n const discardDraft = async (entry: { documentId: string; locale: string }) =>\n strapi\n .documents(uid as any)\n // Discard draft by referencing the documentId and locale\n .discardDraft({ documentId: entry.documentId, locale: entry.locale });\n\n /**\n * Load a batch of entries (batched to prevent loading millions of rows at once ),\n * and discard them using the document service.\n */\n for await (const batch of getBatchToDiscard({ db: strapi.db, trx, uid })) {\n await async.map(batch, discardDraft, { concurrency: 10 });\n }\n }\n }\n });\n};\n\nconst disableDraftAndPublish = async ({ oldContentTypes, contentTypes }: Input) => {\n if (!oldContentTypes) {\n return;\n }\n\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n // if d&p was disabled remove unpublish content before sync\n if (\n contentTypesUtils.hasDraftAndPublish(oldContentType) &&\n !contentTypesUtils.hasDraftAndPublish(contentType)\n ) {\n await strapi.db?.queryBuilder(uid).delete().where({ published_at: null }).execute();\n }\n }\n};\n\nexport { enableDraftAndPublish as enable, disableDraftAndPublish as disable };\n"],"names":["contentTypesUtils","getBatchToDiscard","async"],"mappings":";;;;AAkBA,MAAM,wBAAwB,OAAO,EAAE,iBAAiB,mBAA0B;AAChF,MAAI,CAAC,iBAAiB;AACpB;AAAA,EACF;AAGA,SAAO,OAAO,GAAG,YAAY,OAAO,QAAQ;AAC1C,eAAW,OAAO,cAAc;AAC1B,UAAA,CAAC,gBAAgB,GAAG,GAAG;AACzB;AAAA,MACF;AAEM,YAAA,iBAAiB,gBAAgB,GAAG;AACpC,YAAA,cAAc,aAAa,GAAG;AAIlC,UAAA,CAACA,yBAAkB,mBAAmB,cAAc,KACpDA,yBAAkB,mBAAmB,WAAW,GAChD;AACA,cAAM,eAAe,OAAO,UAC1B,OACG,UAAU,GAAU,EAEpB,aAAa,EAAE,YAAY,MAAM,YAAY,QAAQ,MAAM,QAAQ;AAMvD,yBAAA,SAASC,sCAAkB,EAAE,IAAI,OAAO,IAAI,KAAK,IAAI,CAAC,GAAG;AACxE,gBAAMC,YAAAA,MAAM,IAAI,OAAO,cAAc,EAAE,aAAa,IAAI;AAAA,QAC1D;AAAA,MACF;AAAA,IACF;AAAA,EAAA,CACD;AACH;AAEA,MAAM,yBAAyB,OAAO,EAAE,iBAAiB,mBAA0B;AACjF,MAAI,CAAC,iBAAiB;AACpB;AAAA,EACF;AAEA,aAAW,OAAO,cAAc;AAC1B,QAAA,CAAC,gBAAgB,GAAG,GAAG;AACzB;AAAA,IACF;AAEM,UAAA,iBAAiB,gBAAgB,GAAG;AACpC,UAAA,cAAc,aAAa,GAAG;AAIlC,QAAAF,YAAAA,aAAkB,mBAAmB,cAAc,KACnD,CAACA,yBAAkB,mBAAmB,WAAW,GACjD;AACA,YAAM,OAAO,IAAI,aAAa,GAAG,EAAE,OAAA,EAAS,MAAM,EAAE,cAAc,MAAM,EAAE,QAAQ;AAAA,IACpF;AAAA,EACF;AACF;;;"}
1
+ {"version":3,"file":"draft-publish.js","sources":["../../src/migrations/draft-publish.ts"],"sourcesContent":["import { contentTypes as contentTypesUtils, async } from '@strapi/utils';\nimport { Schema } from '@strapi/types';\n\nimport { getBatchToDiscard } from './database/5.0.0-discard-drafts';\n\nexport interface Input {\n oldContentTypes: Record<string, Schema.ContentType>;\n contentTypes: Record<string, Schema.ContentType>;\n}\n\n/**\n * Enable draft and publish for content types.\n *\n * Draft and publish disabled content types will have their entries published,\n * this migration clones those entries as drafts.\n *\n * TODO: Clone components, dynamic zones and relations\n */\nconst enableDraftAndPublish = async ({ oldContentTypes, contentTypes }: Input) => {\n if (!oldContentTypes) {\n return;\n }\n\n // run the after content types migrations\n return strapi.db.transaction(async (trx) => {\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n // if d&p was enabled set publishedAt to eq createdAt\n if (\n !contentTypesUtils.hasDraftAndPublish(oldContentType) &&\n contentTypesUtils.hasDraftAndPublish(contentType)\n ) {\n const discardDraft = async (entry: { documentId: string; locale: string }) =>\n strapi\n .documents(uid as any)\n // Discard draft by referencing the documentId and locale\n .discardDraft({ documentId: entry.documentId, locale: entry.locale });\n\n /**\n * Load a batch of entries (batched to prevent loading millions of rows at once ),\n * and discard them using the document service.\n */\n for await (const batch of getBatchToDiscard({ db: strapi.db, trx, uid })) {\n await async.map(batch, discardDraft, { concurrency: 10 });\n }\n }\n }\n });\n};\n\nconst disableDraftAndPublish = async ({ oldContentTypes, contentTypes }: Input) => {\n if (!oldContentTypes) {\n return;\n }\n\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n // if d&p was disabled remove unpublish content before sync\n if (\n contentTypesUtils.hasDraftAndPublish(oldContentType) &&\n !contentTypesUtils.hasDraftAndPublish(contentType)\n ) {\n await strapi.db?.queryBuilder(uid).delete().where({ published_at: null }).execute();\n }\n }\n};\n\nexport { enableDraftAndPublish as enable, disableDraftAndPublish as disable };\n"],"names":["contentTypesUtils","getBatchToDiscard","async"],"mappings":";;;;AAkBA,MAAM,wBAAwB,OAAO,EAAE,iBAAiB,mBAA0B;AAChF,MAAI,CAAC,iBAAiB;AACpB;AAAA,EACF;AAGA,SAAO,OAAO,GAAG,YAAY,OAAO,QAAQ;AAC1C,eAAW,OAAO,cAAc;AAC1B,UAAA,CAAC,gBAAgB,GAAG,GAAG;AACzB;AAAA,MACF;AAEM,YAAA,iBAAiB,gBAAgB,GAAG;AACpC,YAAA,cAAc,aAAa,GAAG;AAIlC,UAAA,CAACA,yBAAkB,mBAAmB,cAAc,KACpDA,yBAAkB,mBAAmB,WAAW,GAChD;AACA,cAAM,eAAe,OAAO,UAC1B,OACG,UAAU,GAAU,EAEpB,aAAa,EAAE,YAAY,MAAM,YAAY,QAAQ,MAAM,QAAQ;AAMvD,yBAAA,SAASC,sCAAkB,EAAE,IAAI,OAAO,IAAI,KAAK,IAAI,CAAC,GAAG;AACxE,gBAAMC,YAAAA,MAAM,IAAI,OAAO,cAAc,EAAE,aAAa,IAAI;AAAA,QAC1D;AAAA,MACF;AAAA,IACF;AAAA,EAAA,CACD;AACH;AAEA,MAAM,yBAAyB,OAAO,EAAE,iBAAiB,mBAA0B;AACjF,MAAI,CAAC,iBAAiB;AACpB;AAAA,EACF;AAEA,aAAW,OAAO,cAAc;AAC1B,QAAA,CAAC,gBAAgB,GAAG,GAAG;AACzB;AAAA,IACF;AAEM,UAAA,iBAAiB,gBAAgB,GAAG;AACpC,UAAA,cAAc,aAAa,GAAG;AAIlC,QAAAF,YAAAA,aAAkB,mBAAmB,cAAc,KACnD,CAACA,yBAAkB,mBAAmB,WAAW,GACjD;AACA,YAAM,OAAO,IAAI,aAAa,GAAG,EAAE,OAAA,EAAS,MAAM,EAAE,cAAc,MAAM,EAAE,QAAQ;AAAA,IACpF;AAAA,EACF;AACF;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"draft-publish.mjs","sources":["../../src/migrations/draft-publish.ts"],"sourcesContent":["import { contentTypes as contentTypesUtils, async } from '@strapi/utils';\nimport { Schema } from '@strapi/types';\n\nimport { getBatchToDiscard } from './database/5.0.0-discard-drafts';\n\ninterface Input {\n oldContentTypes: Record<string, Schema.ContentType>;\n contentTypes: Record<string, Schema.ContentType>;\n}\n\n/**\n * Enable draft and publish for content types.\n *\n * Draft and publish disabled content types will have their entries published,\n * this migration clones those entries as drafts.\n *\n * TODO: Clone components, dynamic zones and relations\n */\nconst enableDraftAndPublish = async ({ oldContentTypes, contentTypes }: Input) => {\n if (!oldContentTypes) {\n return;\n }\n\n // run the after content types migrations\n return strapi.db.transaction(async (trx) => {\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n // if d&p was enabled set publishedAt to eq createdAt\n if (\n !contentTypesUtils.hasDraftAndPublish(oldContentType) &&\n contentTypesUtils.hasDraftAndPublish(contentType)\n ) {\n const discardDraft = async (entry: { documentId: string; locale: string }) =>\n strapi\n .documents(uid as any)\n // Discard draft by referencing the documentId and locale\n .discardDraft({ documentId: entry.documentId, locale: entry.locale });\n\n /**\n * Load a batch of entries (batched to prevent loading millions of rows at once ),\n * and discard them using the document service.\n */\n for await (const batch of getBatchToDiscard({ db: strapi.db, trx, uid })) {\n await async.map(batch, discardDraft, { concurrency: 10 });\n }\n }\n }\n });\n};\n\nconst disableDraftAndPublish = async ({ oldContentTypes, contentTypes }: Input) => {\n if (!oldContentTypes) {\n return;\n }\n\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n // if d&p was disabled remove unpublish content before sync\n if (\n contentTypesUtils.hasDraftAndPublish(oldContentType) &&\n !contentTypesUtils.hasDraftAndPublish(contentType)\n ) {\n await strapi.db?.queryBuilder(uid).delete().where({ published_at: null }).execute();\n }\n }\n};\n\nexport { enableDraftAndPublish as enable, disableDraftAndPublish as disable };\n"],"names":["contentTypes","contentTypesUtils"],"mappings":";;AAkBA,MAAM,wBAAwB,OAAO,EAAE,iBAAiBA,cAAAA,qBAA0B;AAChF,MAAI,CAAC,iBAAiB;AACpB;AAAA,EACF;AAGA,SAAO,OAAO,GAAG,YAAY,OAAO,QAAQ;AAC1C,eAAW,OAAOA,gBAAc;AAC1B,UAAA,CAAC,gBAAgB,GAAG,GAAG;AACzB;AAAA,MACF;AAEM,YAAA,iBAAiB,gBAAgB,GAAG;AACpC,YAAA,cAAcA,eAAa,GAAG;AAIlC,UAAA,CAACC,aAAkB,mBAAmB,cAAc,KACpDA,aAAkB,mBAAmB,WAAW,GAChD;AACA,cAAM,eAAe,OAAO,UAC1B,OACG,UAAU,GAAU,EAEpB,aAAa,EAAE,YAAY,MAAM,YAAY,QAAQ,MAAM,QAAQ;AAMvD,yBAAA,SAAS,kBAAkB,EAAE,IAAI,OAAO,IAAI,KAAK,IAAI,CAAC,GAAG;AACxE,gBAAM,MAAM,IAAI,OAAO,cAAc,EAAE,aAAa,IAAI;AAAA,QAC1D;AAAA,MACF;AAAA,IACF;AAAA,EAAA,CACD;AACH;AAEA,MAAM,yBAAyB,OAAO,EAAE,iBAAiBD,cAAAA,qBAA0B;AACjF,MAAI,CAAC,iBAAiB;AACpB;AAAA,EACF;AAEA,aAAW,OAAOA,gBAAc;AAC1B,QAAA,CAAC,gBAAgB,GAAG,GAAG;AACzB;AAAA,IACF;AAEM,UAAA,iBAAiB,gBAAgB,GAAG;AACpC,UAAA,cAAcA,eAAa,GAAG;AAIlC,QAAAC,aAAkB,mBAAmB,cAAc,KACnD,CAACA,aAAkB,mBAAmB,WAAW,GACjD;AACA,YAAM,OAAO,IAAI,aAAa,GAAG,EAAE,OAAA,EAAS,MAAM,EAAE,cAAc,MAAM,EAAE,QAAQ;AAAA,IACpF;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"draft-publish.mjs","sources":["../../src/migrations/draft-publish.ts"],"sourcesContent":["import { contentTypes as contentTypesUtils, async } from '@strapi/utils';\nimport { Schema } from '@strapi/types';\n\nimport { getBatchToDiscard } from './database/5.0.0-discard-drafts';\n\nexport interface Input {\n oldContentTypes: Record<string, Schema.ContentType>;\n contentTypes: Record<string, Schema.ContentType>;\n}\n\n/**\n * Enable draft and publish for content types.\n *\n * Draft and publish disabled content types will have their entries published,\n * this migration clones those entries as drafts.\n *\n * TODO: Clone components, dynamic zones and relations\n */\nconst enableDraftAndPublish = async ({ oldContentTypes, contentTypes }: Input) => {\n if (!oldContentTypes) {\n return;\n }\n\n // run the after content types migrations\n return strapi.db.transaction(async (trx) => {\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n // if d&p was enabled set publishedAt to eq createdAt\n if (\n !contentTypesUtils.hasDraftAndPublish(oldContentType) &&\n contentTypesUtils.hasDraftAndPublish(contentType)\n ) {\n const discardDraft = async (entry: { documentId: string; locale: string }) =>\n strapi\n .documents(uid as any)\n // Discard draft by referencing the documentId and locale\n .discardDraft({ documentId: entry.documentId, locale: entry.locale });\n\n /**\n * Load a batch of entries (batched to prevent loading millions of rows at once ),\n * and discard them using the document service.\n */\n for await (const batch of getBatchToDiscard({ db: strapi.db, trx, uid })) {\n await async.map(batch, discardDraft, { concurrency: 10 });\n }\n }\n }\n });\n};\n\nconst disableDraftAndPublish = async ({ oldContentTypes, contentTypes }: Input) => {\n if (!oldContentTypes) {\n return;\n }\n\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n // if d&p was disabled remove unpublish content before sync\n if (\n contentTypesUtils.hasDraftAndPublish(oldContentType) &&\n !contentTypesUtils.hasDraftAndPublish(contentType)\n ) {\n await strapi.db?.queryBuilder(uid).delete().where({ published_at: null }).execute();\n }\n }\n};\n\nexport { enableDraftAndPublish as enable, disableDraftAndPublish as disable };\n"],"names":["contentTypes","contentTypesUtils"],"mappings":";;AAkBA,MAAM,wBAAwB,OAAO,EAAE,iBAAiBA,cAAAA,qBAA0B;AAChF,MAAI,CAAC,iBAAiB;AACpB;AAAA,EACF;AAGA,SAAO,OAAO,GAAG,YAAY,OAAO,QAAQ;AAC1C,eAAW,OAAOA,gBAAc;AAC1B,UAAA,CAAC,gBAAgB,GAAG,GAAG;AACzB;AAAA,MACF;AAEM,YAAA,iBAAiB,gBAAgB,GAAG;AACpC,YAAA,cAAcA,eAAa,GAAG;AAIlC,UAAA,CAACC,aAAkB,mBAAmB,cAAc,KACpDA,aAAkB,mBAAmB,WAAW,GAChD;AACA,cAAM,eAAe,OAAO,UAC1B,OACG,UAAU,GAAU,EAEpB,aAAa,EAAE,YAAY,MAAM,YAAY,QAAQ,MAAM,QAAQ;AAMvD,yBAAA,SAAS,kBAAkB,EAAE,IAAI,OAAO,IAAI,KAAK,IAAI,CAAC,GAAG;AACxE,gBAAM,MAAM,IAAI,OAAO,cAAc,EAAE,aAAa,IAAI;AAAA,QAC1D;AAAA,MACF;AAAA,IACF;AAAA,EAAA,CACD;AACH;AAEA,MAAM,yBAAyB,OAAO,EAAE,iBAAiBD,cAAAA,qBAA0B;AACjF,MAAI,CAAC,iBAAiB;AACpB;AAAA,EACF;AAEA,aAAW,OAAOA,gBAAc;AAC1B,QAAA,CAAC,gBAAgB,GAAG,GAAG;AACzB;AAAA,IACF;AAEM,UAAA,iBAAiB,gBAAgB,GAAG;AACpC,UAAA,cAAcA,eAAa,GAAG;AAIlC,QAAAC,aAAkB,mBAAmB,cAAc,KACnD,CAACA,aAAkB,mBAAmB,WAAW,GACjD;AACA,YAAM,OAAO,IAAI,aAAa,GAAG,EAAE,OAAA,EAAS,MAAM,EAAE,cAAc,MAAM,EAAE,QAAQ;AAAA,IACpF;AAAA,EACF;AACF;"}
@@ -0,0 +1,5 @@
1
+ import { Input } from './draft-publish';
2
+ declare const enableI18n: ({ oldContentTypes, contentTypes }: Input) => Promise<void>;
3
+ declare const disableI18n: ({ oldContentTypes, contentTypes }: Input) => Promise<void>;
4
+ export { enableI18n as enable, disableI18n as disable };
5
+ //# sourceMappingURL=i18n.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../../src/migrations/i18n.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,QAAA,MAAM,UAAU,sCAA6C,KAAK,kBAyBjE,CAAC;AAEF,QAAA,MAAM,WAAW,sCAA6C,KAAK,kBAiClE,CAAC;AAEF,OAAO,EAAE,UAAU,IAAI,MAAM,EAAE,WAAW,IAAI,OAAO,EAAE,CAAC"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const enableI18n = async ({ oldContentTypes, contentTypes }) => {
4
+ const { isLocalizedContentType } = strapi.plugin("i18n")?.service("content-types") ?? {};
5
+ const { getDefaultLocale } = strapi.plugin("i18n")?.service("locales") ?? {};
6
+ if (!oldContentTypes) {
7
+ return;
8
+ }
9
+ for (const uid in contentTypes) {
10
+ if (!oldContentTypes[uid]) {
11
+ continue;
12
+ }
13
+ const oldContentType = oldContentTypes[uid];
14
+ const contentType = contentTypes[uid];
15
+ if (!isLocalizedContentType(oldContentType) && isLocalizedContentType(contentType)) {
16
+ const defaultLocale = await getDefaultLocale();
17
+ await strapi.db.query(uid).updateMany({
18
+ where: { locale: null },
19
+ data: { locale: defaultLocale }
20
+ });
21
+ }
22
+ }
23
+ };
24
+ const disableI18n = async ({ oldContentTypes, contentTypes }) => {
25
+ const { isLocalizedContentType } = strapi.plugin("i18n")?.service("content-types") ?? {};
26
+ const { getDefaultLocale } = strapi.plugin("i18n")?.service("locales") ?? {};
27
+ if (!oldContentTypes) {
28
+ return;
29
+ }
30
+ for (const uid in contentTypes) {
31
+ if (!oldContentTypes[uid]) {
32
+ continue;
33
+ }
34
+ const oldContentType = oldContentTypes[uid];
35
+ const contentType = contentTypes[uid];
36
+ if (isLocalizedContentType(oldContentType) && !isLocalizedContentType(contentType)) {
37
+ const defaultLocale = await getDefaultLocale();
38
+ await Promise.all([
39
+ // Delete all entities that are not in the default locale
40
+ strapi.db.query(uid).deleteMany({
41
+ where: { locale: { $ne: defaultLocale } }
42
+ }),
43
+ // Set locale to null for the rest
44
+ strapi.db.query(uid).updateMany({
45
+ where: { locale: { $eq: defaultLocale } },
46
+ data: { locale: null }
47
+ })
48
+ ]);
49
+ }
50
+ }
51
+ };
52
+ exports.disable = disableI18n;
53
+ exports.enable = enableI18n;
54
+ //# sourceMappingURL=i18n.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.js","sources":["../../src/migrations/i18n.ts"],"sourcesContent":["import { Input } from './draft-publish';\n\n// if i18N enabled set default locale\nconst enableI18n = async ({ oldContentTypes, contentTypes }: Input) => {\n const { isLocalizedContentType } = strapi.plugin('i18n')?.service('content-types') ?? {};\n const { getDefaultLocale } = strapi.plugin('i18n')?.service('locales') ?? {};\n\n if (!oldContentTypes) {\n return;\n }\n\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n if (!isLocalizedContentType(oldContentType) && isLocalizedContentType(contentType)) {\n const defaultLocale = await getDefaultLocale();\n\n await strapi.db.query(uid).updateMany({\n where: { locale: null },\n data: { locale: defaultLocale },\n });\n }\n }\n};\n\nconst disableI18n = async ({ oldContentTypes, contentTypes }: Input) => {\n const { isLocalizedContentType } = strapi.plugin('i18n')?.service('content-types') ?? {};\n const { getDefaultLocale } = strapi.plugin('i18n')?.service('locales') ?? {};\n\n if (!oldContentTypes) {\n return;\n }\n\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n // if i18N is disabled remove non default locales before sync\n if (isLocalizedContentType(oldContentType) && !isLocalizedContentType(contentType)) {\n const defaultLocale = await getDefaultLocale();\n\n await Promise.all([\n // Delete all entities that are not in the default locale\n strapi.db.query(uid).deleteMany({\n where: { locale: { $ne: defaultLocale } },\n }),\n // Set locale to null for the rest\n strapi.db.query(uid).updateMany({\n where: { locale: { $eq: defaultLocale } },\n data: { locale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MAAM,GAAG,EAAE,WAAW;AAAA,UAC9B,OAAO,EAAE,QAAQ,EAAE,KAAK,gBAAgB;AAAA,QAAA,CACzC;AAAA;AAAA,QAED,OAAO,GAAG,MAAM,GAAG,EAAE,WAAW;AAAA,UAC9B,OAAO,EAAE,QAAQ,EAAE,KAAK,gBAAgB;AAAA,UACxC,MAAM,EAAE,QAAQ,KAAK;AAAA,QAAA,CACtB;AAAA,MAAA,CACF;AAAA,IACH;AAAA,EACF;AACF;;;"}
@@ -0,0 +1,54 @@
1
+ const enableI18n = async ({ oldContentTypes, contentTypes }) => {
2
+ const { isLocalizedContentType } = strapi.plugin("i18n")?.service("content-types") ?? {};
3
+ const { getDefaultLocale } = strapi.plugin("i18n")?.service("locales") ?? {};
4
+ if (!oldContentTypes) {
5
+ return;
6
+ }
7
+ for (const uid in contentTypes) {
8
+ if (!oldContentTypes[uid]) {
9
+ continue;
10
+ }
11
+ const oldContentType = oldContentTypes[uid];
12
+ const contentType = contentTypes[uid];
13
+ if (!isLocalizedContentType(oldContentType) && isLocalizedContentType(contentType)) {
14
+ const defaultLocale = await getDefaultLocale();
15
+ await strapi.db.query(uid).updateMany({
16
+ where: { locale: null },
17
+ data: { locale: defaultLocale }
18
+ });
19
+ }
20
+ }
21
+ };
22
+ const disableI18n = async ({ oldContentTypes, contentTypes }) => {
23
+ const { isLocalizedContentType } = strapi.plugin("i18n")?.service("content-types") ?? {};
24
+ const { getDefaultLocale } = strapi.plugin("i18n")?.service("locales") ?? {};
25
+ if (!oldContentTypes) {
26
+ return;
27
+ }
28
+ for (const uid in contentTypes) {
29
+ if (!oldContentTypes[uid]) {
30
+ continue;
31
+ }
32
+ const oldContentType = oldContentTypes[uid];
33
+ const contentType = contentTypes[uid];
34
+ if (isLocalizedContentType(oldContentType) && !isLocalizedContentType(contentType)) {
35
+ const defaultLocale = await getDefaultLocale();
36
+ await Promise.all([
37
+ // Delete all entities that are not in the default locale
38
+ strapi.db.query(uid).deleteMany({
39
+ where: { locale: { $ne: defaultLocale } }
40
+ }),
41
+ // Set locale to null for the rest
42
+ strapi.db.query(uid).updateMany({
43
+ where: { locale: { $eq: defaultLocale } },
44
+ data: { locale: null }
45
+ })
46
+ ]);
47
+ }
48
+ }
49
+ };
50
+ export {
51
+ disableI18n as disable,
52
+ enableI18n as enable
53
+ };
54
+ //# sourceMappingURL=i18n.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.mjs","sources":["../../src/migrations/i18n.ts"],"sourcesContent":["import { Input } from './draft-publish';\n\n// if i18N enabled set default locale\nconst enableI18n = async ({ oldContentTypes, contentTypes }: Input) => {\n const { isLocalizedContentType } = strapi.plugin('i18n')?.service('content-types') ?? {};\n const { getDefaultLocale } = strapi.plugin('i18n')?.service('locales') ?? {};\n\n if (!oldContentTypes) {\n return;\n }\n\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n if (!isLocalizedContentType(oldContentType) && isLocalizedContentType(contentType)) {\n const defaultLocale = await getDefaultLocale();\n\n await strapi.db.query(uid).updateMany({\n where: { locale: null },\n data: { locale: defaultLocale },\n });\n }\n }\n};\n\nconst disableI18n = async ({ oldContentTypes, contentTypes }: Input) => {\n const { isLocalizedContentType } = strapi.plugin('i18n')?.service('content-types') ?? {};\n const { getDefaultLocale } = strapi.plugin('i18n')?.service('locales') ?? {};\n\n if (!oldContentTypes) {\n return;\n }\n\n for (const uid in contentTypes) {\n if (!oldContentTypes[uid]) {\n continue;\n }\n\n const oldContentType = oldContentTypes[uid];\n const contentType = contentTypes[uid];\n\n // if i18N is disabled remove non default locales before sync\n if (isLocalizedContentType(oldContentType) && !isLocalizedContentType(contentType)) {\n const defaultLocale = await getDefaultLocale();\n\n await Promise.all([\n // Delete all entities that are not in the default locale\n strapi.db.query(uid).deleteMany({\n where: { locale: { $ne: defaultLocale } },\n }),\n // Set locale to null for the rest\n strapi.db.query(uid).updateMany({\n where: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A;AAAA,QAEhB,OAAO,GAAG,MAAM,GAAG,EAAE,WAAW;AAAA,UAC9B,OAAO,EAAE,QAAQ,EAAE,KAAK,gBAAgB;AAAA,QAAA,CACzC;AAAA;AAAA,QAED,OAAO,GAAG,MAAM,GAAG,EAAE,WAAW;AAAA,UAC9B,OAAO,EAAE,QAAQ,EAAE,KAAK,gBAAgB;AAAA,UACxC,MAAM,EAAE,QAAQ,KAAK;AAAA,QAAA,CACtB;AAAA,MAAA,CACF;AAAA,IACH;AAAA,EACF;AACF;"}
@@ -0,0 +1,5 @@
1
+ import type { Input } from './draft-publish';
2
+ declare const enable: ({ oldContentTypes, contentTypes }: Input) => Promise<void>;
3
+ declare const disable: ({ oldContentTypes, contentTypes }: Input) => Promise<void>;
4
+ export { enable, disable };
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/migrations/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE7C,QAAA,MAAM,MAAM,sCAA6C,KAAK,kBAG7D,CAAC;AAEF,QAAA,MAAM,OAAO,sCAA6C,KAAK,kBAG9D,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const draftPublish = require("./draft-publish.js");
4
+ const i18n = require("./i18n.js");
5
+ const enable = async ({ oldContentTypes, contentTypes }) => {
6
+ await i18n.enable({ oldContentTypes, contentTypes });
7
+ await draftPublish.enable({ oldContentTypes, contentTypes });
8
+ };
9
+ const disable = async ({ oldContentTypes, contentTypes }) => {
10
+ await i18n.disable({ oldContentTypes, contentTypes });
11
+ await draftPublish.disable({ oldContentTypes, contentTypes });
12
+ };
13
+ exports.disable = disable;
14
+ exports.enable = enable;
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/migrations/index.ts"],"sourcesContent":["import * as draftPublishMigrations from './draft-publish';\nimport * as i18nMigrations from './i18n';\nimport type { Input } from './draft-publish';\n\nconst enable = async ({ oldContentTypes, contentTypes }: Input) => {\n await i18nMigrations.enable({ oldContentTypes, contentTypes });\n await draftPublishMigrations.enable({ oldContentTypes, contentTypes });\n};\n\nconst disable = async ({ oldContentTypes, contentTypes }: Input) => {\n await i18nMigrations.disable({ oldContentTypes, contentTypes });\n await draftPublishMigrations.disable({ oldContentTypes, contentTypes });\n};\n\nexport { enable, disable };\n"],"names":["i18nMigrations.enable","draftPublishMigrations.enable","i18nMigrations.disable","draftPublishMigrations.disable"],"mappings":";;;;AAIA,MAAM,SAAS,OAAO,EAAE,iBAAiB,mBAA0B;AACjE,QAAMA,YAAsB,EAAE,iBAAiB,aAAc,CAAA;AAC7D,QAAMC,oBAA8B,EAAE,iBAAiB,aAAc,CAAA;AACvE;AAEA,MAAM,UAAU,OAAO,EAAE,iBAAiB,mBAA0B;AAClE,QAAMC,aAAuB,EAAE,iBAAiB,aAAc,CAAA;AAC9D,QAAMC,qBAA+B,EAAE,iBAAiB,aAAc,CAAA;AACxE;;;"}
@@ -0,0 +1,15 @@
1
+ import { enable as enableDraftAndPublish, disable as disableDraftAndPublish } from "./draft-publish.mjs";
2
+ import { enable as enableI18n, disable as disableI18n } from "./i18n.mjs";
3
+ const enable = async ({ oldContentTypes, contentTypes }) => {
4
+ await enableI18n({ oldContentTypes, contentTypes });
5
+ await enableDraftAndPublish({ oldContentTypes, contentTypes });
6
+ };
7
+ const disable = async ({ oldContentTypes, contentTypes }) => {
8
+ await disableI18n({ oldContentTypes, contentTypes });
9
+ await disableDraftAndPublish({ oldContentTypes, contentTypes });
10
+ };
11
+ export {
12
+ disable,
13
+ enable
14
+ };
15
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../../src/migrations/index.ts"],"sourcesContent":["import * as draftPublishMigrations from './draft-publish';\nimport * as i18nMigrations from './i18n';\nimport type { Input } from './draft-publish';\n\nconst enable = async ({ oldContentTypes, contentTypes }: Input) => {\n await i18nMigrations.enable({ oldContentTypes, contentTypes });\n await draftPublishMigrations.enable({ oldContentTypes, contentTypes });\n};\n\nconst disable = async ({ oldContentTypes, contentTypes }: Input) => {\n await i18nMigrations.disable({ oldContentTypes, contentTypes });\n await draftPublishMigrations.disable({ oldContentTypes, contentTypes });\n};\n\nexport { enable, disable };\n"],"names":["i18nMigrations.enable","draftPublishMigrations.enable","i18nMigrations.disable","draftPublishMigrations.disable"],"mappings":";;AAIA,MAAM,SAAS,OAAO,EAAE,iBAAiB,mBAA0B;AACjE,QAAMA,WAAsB,EAAE,iBAAiB,aAAc,CAAA;AAC7D,QAAMC,sBAA8B,EAAE,iBAAiB,aAAc,CAAA;AACvE;AAEA,MAAM,UAAU,OAAO,EAAE,iBAAiB,mBAA0B;AAClE,QAAMC,YAAuB,EAAE,iBAAiB,aAAc,CAAA;AAC9D,QAAMC,uBAA+B,EAAE,iBAAiB,aAAc,CAAA;AACxE;"}
@@ -1 +1 @@
1
- {"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../src/providers/admin.ts"],"names":[],"mappings":";AAGA,wBAkBG"}
1
+ {"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../src/providers/admin.ts"],"names":[],"mappings":";AAGA,wBAmBG"}
@@ -1 +1 @@
1
- {"version":3,"file":"admin.js","sources":["../../src/providers/admin.ts"],"sourcesContent":["import { defineProvider } from './provider';\nimport loadAdmin from '../loaders/admin';\n\nexport default defineProvider({\n init(strapi) {\n strapi.add('admin', () => require('@strapi/admin/strapi-server'));\n },\n\n async register(strapi) {\n await loadAdmin(strapi);\n\n await strapi.get('admin')?.register({ strapi });\n },\n\n async bootstrap(strapi) {\n await strapi.get('admin')?.bootstrap({ strapi });\n },\n\n async destroy(strapi) {\n await strapi.get('admin')?.destroy({ strapi });\n },\n});\n"],"names":["defineProvider","loadAdmin"],"mappings":";;;AAGA,MAAA,QAAeA,wBAAe;AAAA,EAC5B,KAAK,QAAQ;AACX,WAAO,IAAI,SAAS,MAAM,QAAQ,6BAA6B,CAAC;AAAA,EAClE;AAAA,EAEA,MAAM,SAAS,QAAQ;AACrB,UAAMC,QAAU,MAAM;AAEtB,UAAM,OAAO,IAAI,OAAO,GAAG,SAAS,EAAE,QAAQ;AAAA,EAChD;AAAA,EAEA,MAAM,UAAU,QAAQ;AACtB,UAAM,OAAO,IAAI,OAAO,GAAG,UAAU,EAAE,QAAQ;AAAA,EACjD;AAAA,EAEA,MAAM,QAAQ,QAAQ;AACpB,UAAM,OAAO,IAAI,OAAO,GAAG,QAAQ,EAAE,QAAQ;AAAA,EAC/C;AACF,CAAC;;"}
1
+ {"version":3,"file":"admin.js","sources":["../../src/providers/admin.ts"],"sourcesContent":["import { defineProvider } from './provider';\nimport loadAdmin from '../loaders/admin';\n\nexport default defineProvider({\n init(strapi) {\n // eslint-disable-next-line node/no-missing-require\n strapi.add('admin', () => require('@strapi/admin/strapi-server'));\n },\n\n async register(strapi) {\n await loadAdmin(strapi);\n\n await strapi.get('admin')?.register({ strapi });\n },\n\n async bootstrap(strapi) {\n await strapi.get('admin')?.bootstrap({ strapi });\n },\n\n async destroy(strapi) {\n await strapi.get('admin')?.destroy({ strapi });\n },\n});\n"],"names":["defineProvider","loadAdmin"],"mappings":";;;AAGA,MAAA,QAAeA,wBAAe;AAAA,EAC5B,KAAK,QAAQ;AAEX,WAAO,IAAI,SAAS,MAAM,QAAQ,6BAA6B,CAAC;AAAA,EAClE;AAAA,EAEA,MAAM,SAAS,QAAQ;AACrB,UAAMC,QAAU,MAAM;AAEtB,UAAM,OAAO,IAAI,OAAO,GAAG,SAAS,EAAE,QAAQ;AAAA,EAChD;AAAA,EAEA,MAAM,UAAU,QAAQ;AACtB,UAAM,OAAO,IAAI,OAAO,GAAG,UAAU,EAAE,QAAQ;AAAA,EACjD;AAAA,EAEA,MAAM,QAAQ,QAAQ;AACpB,UAAM,OAAO,IAAI,OAAO,GAAG,QAAQ,EAAE,QAAQ;AAAA,EAC/C;AACF,CAAC;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"admin.mjs","sources":["../../src/providers/admin.ts"],"sourcesContent":["import { defineProvider } from './provider';\nimport loadAdmin from '../loaders/admin';\n\nexport default defineProvider({\n init(strapi) {\n strapi.add('admin', () => require('@strapi/admin/strapi-server'));\n },\n\n async register(strapi) {\n await loadAdmin(strapi);\n\n await strapi.get('admin')?.register({ strapi });\n },\n\n async bootstrap(strapi) {\n await strapi.get('admin')?.bootstrap({ strapi });\n },\n\n async destroy(strapi) {\n await strapi.get('admin')?.destroy({ strapi });\n },\n});\n"],"names":[],"mappings":";;AAGA,MAAA,QAAe,eAAe;AAAA,EAC5B,KAAK,QAAQ;AACX,WAAO,IAAI,SAAS,MAAM,QAAQ,6BAA6B,CAAC;AAAA,EAClE;AAAA,EAEA,MAAM,SAAS,QAAQ;AACrB,UAAM,UAAU,MAAM;AAEtB,UAAM,OAAO,IAAI,OAAO,GAAG,SAAS,EAAE,QAAQ;AAAA,EAChD;AAAA,EAEA,MAAM,UAAU,QAAQ;AACtB,UAAM,OAAO,IAAI,OAAO,GAAG,UAAU,EAAE,QAAQ;AAAA,EACjD;AAAA,EAEA,MAAM,QAAQ,QAAQ;AACpB,UAAM,OAAO,IAAI,OAAO,GAAG,QAAQ,EAAE,QAAQ;AAAA,EAC/C;AACF,CAAC;"}
1
+ {"version":3,"file":"admin.mjs","sources":["../../src/providers/admin.ts"],"sourcesContent":["import { defineProvider } from './provider';\nimport loadAdmin from '../loaders/admin';\n\nexport default defineProvider({\n init(strapi) {\n // eslint-disable-next-line node/no-missing-require\n strapi.add('admin', () => require('@strapi/admin/strapi-server'));\n },\n\n async register(strapi) {\n await loadAdmin(strapi);\n\n await strapi.get('admin')?.register({ strapi });\n },\n\n async bootstrap(strapi) {\n await strapi.get('admin')?.bootstrap({ strapi });\n },\n\n async destroy(strapi) {\n await strapi.get('admin')?.destroy({ strapi });\n },\n});\n"],"names":[],"mappings":";;AAGA,MAAA,QAAe,eAAe;AAAA,EAC5B,KAAK,QAAQ;AAEX,WAAO,IAAI,SAAS,MAAM,QAAQ,6BAA6B,CAAC;AAAA,EAClE;AAAA,EAEA,MAAM,SAAS,QAAQ;AACrB,UAAM,UAAU,MAAM;AAEtB,UAAM,OAAO,IAAI,OAAO,GAAG,SAAS,EAAE,QAAQ;AAAA,EAChD;AAAA,EAEA,MAAM,UAAU,QAAQ;AACtB,UAAM,OAAO,IAAI,OAAO,GAAG,UAAU,EAAE,QAAQ;AAAA,EACjD;AAAA,EAEA,MAAM,QAAQ,QAAQ;AACpB,UAAM,OAAO,IAAI,OAAO,GAAG,QAAQ,EAAE,QAAQ;AAAA,EAC/C;AACF,CAAC;"}
@@ -16,7 +16,7 @@ const sanitizers = require("../registries/sanitizers.js");
16
16
  const validators = require("../registries/validators.js");
17
17
  const models = require("../registries/models.js");
18
18
  const index = require("../loaders/index.js");
19
- const draftPublish = require("../migrations/draft-publish.js");
19
+ const index$1 = require("../migrations/index.js");
20
20
  const _5_0_0DiscardDrafts = require("../migrations/database/5.0.0-discard-drafts.js");
21
21
  const registries = provider.defineProvider({
22
22
  init(strapi) {
@@ -26,8 +26,8 @@ const registries = provider.defineProvider({
26
26
  await index.loadApplicationContext(strapi);
27
27
  strapi.get("hooks").set("strapi::content-types.beforeSync", strapiUtils.hooks.createAsyncParallelHook());
28
28
  strapi.get("hooks").set("strapi::content-types.afterSync", strapiUtils.hooks.createAsyncParallelHook());
29
- strapi.hook("strapi::content-types.beforeSync").register(draftPublish.disable);
30
- strapi.hook("strapi::content-types.afterSync").register(draftPublish.enable);
29
+ strapi.hook("strapi::content-types.beforeSync").register(index$1.disable);
30
+ strapi.hook("strapi::content-types.afterSync").register(index$1.enable);
31
31
  strapi.db.migrations.providers.internal.register(_5_0_0DiscardDrafts.discardDocumentDrafts);
32
32
  }
33
33
  });
@@ -1 +1 @@
1
- {"version":3,"file":"registries.js","sources":["../../src/providers/registries.ts"],"sourcesContent":["import { hooks } from '@strapi/utils';\n\nimport { defineProvider } from './provider';\nimport * as registries from '../registries';\nimport { loadApplicationContext } from '../loaders';\nimport * as draftAndPublishSync from '../migrations/draft-publish';\nimport { discardDocumentDrafts } from '../migrations/database/5.0.0-discard-drafts';\n\nexport default defineProvider({\n init(strapi) {\n strapi\n .add('content-types', () => registries.contentTypes())\n .add('components', () => registries.components())\n .add('services', () => registries.services(strapi))\n .add('policies', () => registries.policies())\n .add('middlewares', () => registries.middlewares())\n .add('hooks', () => registries.hooks())\n .add('controllers', () => registries.controllers(strapi))\n .add('modules', () => registries.modules(strapi))\n .add('plugins', () => registries.plugins(strapi))\n .add('custom-fields', () => registries.customFields(strapi))\n .add('apis', () => registries.apis(strapi))\n .add('models', () => registries.models())\n .add('sanitizers', registries.sanitizers())\n .add('validators', registries.validators());\n },\n async register(strapi) {\n await loadApplicationContext(strapi);\n\n strapi.get('hooks').set('strapi::content-types.beforeSync', hooks.createAsyncParallelHook());\n strapi.get('hooks').set('strapi::content-types.afterSync', hooks.createAsyncParallelHook());\n\n // Content migration to enable draft and publish\n strapi.hook('strapi::content-types.beforeSync').register(draftAndPublishSync.disable);\n strapi.hook('strapi::content-types.afterSync').register(draftAndPublishSync.enable);\n\n // Database migrations\n strapi.db.migrations.providers.internal.register(discardDocumentDrafts);\n },\n});\n"],"names":["defineProvider","registries.contentTypes","registries.components","registries.services","registries.policies","registries.middlewares","registries.hooks","registries.controllers","registries.modules","registries.plugins","registries.customFields","registries.apis","registries.models","registries.sanitizers","registries.validators","loadApplicationContext","hooks","draftAndPublishSync.disable","draftAndPublishSync.enable","discardDocumentDrafts"],"mappings":";;;;;;;;;;;;;;;;;;;;AAQA,MAAA,aAAeA,wBAAe;AAAA,EAC5B,KAAK,QAAQ;AAER,WAAA,IAAI,iBAAiB,MAAMC,aAAyB,CAAA,EACpD,IAAI,cAAc,MAAMC,WAAuB,CAAA,EAC/C,IAAI,YAAY,MAAMC,SAAoB,MAAM,CAAC,EACjD,IAAI,YAAY,MAAMC,SAAqB,CAAA,EAC3C,IAAI,eAAe,MAAMC,YAAuB,CAAC,EACjD,IAAI,SAAS,MAAMC,OAAkB,EACrC,IAAI,eAAe,MAAMC,YAAuB,MAAM,CAAC,EACvD,IAAI,WAAW,MAAMC,QAAmB,MAAM,CAAC,EAC/C,IAAI,WAAW,MAAMC,QAAmB,MAAM,CAAC,EAC/C,IAAI,iBAAiB,MAAMC,aAAwB,MAAM,CAAC,EAC1D,IAAI,QAAQ,MAAMC,KAAgB,MAAM,CAAC,EACzC,IAAI,UAAU,MAAMC,gBAAmB,CAAA,EACvC,IAAI,cAAcC,YAAuB,EACzC,IAAI,cAAcC,WAAW,CAAY;AAAA,EAC9C;AAAA,EACA,MAAM,SAAS,QAAQ;AACrB,UAAMC,MAAAA,uBAAuB,MAAM;AAEnC,WAAO,IAAI,OAAO,EAAE,IAAI,oCAAoCC,YAAA,MAAM,yBAAyB;AAC3F,WAAO,IAAI,OAAO,EAAE,IAAI,mCAAmCA,YAAA,MAAM,yBAAyB;AAG1F,WAAO,KAAK,kCAAkC,EAAE,SAASC,aAA2B,OAAA;AACpF,WAAO,KAAK,iCAAiC,EAAE,SAASC,aAA0B,MAAA;AAGlF,WAAO,GAAG,WAAW,UAAU,SAAS,SAASC,oBAAAA,qBAAqB;AAAA,EACxE;AACF,CAAC;;"}
1
+ {"version":3,"file":"registries.js","sources":["../../src/providers/registries.ts"],"sourcesContent":["import { hooks } from '@strapi/utils';\n\nimport { defineProvider } from './provider';\nimport * as registries from '../registries';\nimport { loadApplicationContext } from '../loaders';\nimport * as syncMigrations from '../migrations';\nimport { discardDocumentDrafts } from '../migrations/database/5.0.0-discard-drafts';\n\nexport default defineProvider({\n init(strapi) {\n strapi\n .add('content-types', () => registries.contentTypes())\n .add('components', () => registries.components())\n .add('services', () => registries.services(strapi))\n .add('policies', () => registries.policies())\n .add('middlewares', () => registries.middlewares())\n .add('hooks', () => registries.hooks())\n .add('controllers', () => registries.controllers(strapi))\n .add('modules', () => registries.modules(strapi))\n .add('plugins', () => registries.plugins(strapi))\n .add('custom-fields', () => registries.customFields(strapi))\n .add('apis', () => registries.apis(strapi))\n .add('models', () => registries.models())\n .add('sanitizers', registries.sanitizers())\n .add('validators', registries.validators());\n },\n async register(strapi) {\n await loadApplicationContext(strapi);\n\n strapi.get('hooks').set('strapi::content-types.beforeSync', hooks.createAsyncParallelHook());\n strapi.get('hooks').set('strapi::content-types.afterSync', hooks.createAsyncParallelHook());\n\n // Content migration to enable draft and publish\n strapi.hook('strapi::content-types.beforeSync').register(syncMigrations.disable);\n strapi.hook('strapi::content-types.afterSync').register(syncMigrations.enable);\n\n // Database migrations\n strapi.db.migrations.providers.internal.register(discardDocumentDrafts);\n },\n});\n"],"names":["defineProvider","registries.contentTypes","registries.components","registries.services","registries.policies","registries.middlewares","registries.hooks","registries.controllers","registries.modules","registries.plugins","registries.customFields","registries.apis","registries.models","registries.sanitizers","registries.validators","loadApplicationContext","hooks","syncMigrations.disable","syncMigrations.enable","discardDocumentDrafts"],"mappings":";;;;;;;;;;;;;;;;;;;;AAQA,MAAA,aAAeA,wBAAe;AAAA,EAC5B,KAAK,QAAQ;AAER,WAAA,IAAI,iBAAiB,MAAMC,aAAyB,CAAA,EACpD,IAAI,cAAc,MAAMC,WAAuB,CAAA,EAC/C,IAAI,YAAY,MAAMC,SAAoB,MAAM,CAAC,EACjD,IAAI,YAAY,MAAMC,SAAqB,CAAA,EAC3C,IAAI,eAAe,MAAMC,YAAuB,CAAC,EACjD,IAAI,SAAS,MAAMC,OAAkB,EACrC,IAAI,eAAe,MAAMC,YAAuB,MAAM,CAAC,EACvD,IAAI,WAAW,MAAMC,QAAmB,MAAM,CAAC,EAC/C,IAAI,WAAW,MAAMC,QAAmB,MAAM,CAAC,EAC/C,IAAI,iBAAiB,MAAMC,aAAwB,MAAM,CAAC,EAC1D,IAAI,QAAQ,MAAMC,KAAgB,MAAM,CAAC,EACzC,IAAI,UAAU,MAAMC,gBAAmB,CAAA,EACvC,IAAI,cAAcC,YAAuB,EACzC,IAAI,cAAcC,WAAW,CAAY;AAAA,EAC9C;AAAA,EACA,MAAM,SAAS,QAAQ;AACrB,UAAMC,MAAAA,uBAAuB,MAAM;AAEnC,WAAO,IAAI,OAAO,EAAE,IAAI,oCAAoCC,YAAA,MAAM,yBAAyB;AAC3F,WAAO,IAAI,OAAO,EAAE,IAAI,mCAAmCA,YAAA,MAAM,yBAAyB;AAG1F,WAAO,KAAK,kCAAkC,EAAE,SAASC,QAAsB,OAAA;AAC/E,WAAO,KAAK,iCAAiC,EAAE,SAASC,QAAqB,MAAA;AAG7E,WAAO,GAAG,WAAW,UAAU,SAAS,SAASC,oBAAAA,qBAAqB;AAAA,EACxE;AACF,CAAC;;"}
@@ -15,7 +15,7 @@ import sanitizersRegistry from "../registries/sanitizers.mjs";
15
15
  import validatorsRegistry from "../registries/validators.mjs";
16
16
  import { registry } from "../registries/models.mjs";
17
17
  import { loadApplicationContext } from "../loaders/index.mjs";
18
- import { disable as disableDraftAndPublish, enable as enableDraftAndPublish } from "../migrations/draft-publish.mjs";
18
+ import { disable, enable } from "../migrations/index.mjs";
19
19
  import { discardDocumentDrafts } from "../migrations/database/5.0.0-discard-drafts.mjs";
20
20
  const registries = defineProvider({
21
21
  init(strapi) {
@@ -25,8 +25,8 @@ const registries = defineProvider({
25
25
  await loadApplicationContext(strapi);
26
26
  strapi.get("hooks").set("strapi::content-types.beforeSync", hooks.createAsyncParallelHook());
27
27
  strapi.get("hooks").set("strapi::content-types.afterSync", hooks.createAsyncParallelHook());
28
- strapi.hook("strapi::content-types.beforeSync").register(disableDraftAndPublish);
29
- strapi.hook("strapi::content-types.afterSync").register(enableDraftAndPublish);
28
+ strapi.hook("strapi::content-types.beforeSync").register(disable);
29
+ strapi.hook("strapi::content-types.afterSync").register(enable);
30
30
  strapi.db.migrations.providers.internal.register(discardDocumentDrafts);
31
31
  }
32
32
  });
@@ -1 +1 @@
1
- {"version":3,"file":"registries.mjs","sources":["../../src/providers/registries.ts"],"sourcesContent":["import { hooks } from '@strapi/utils';\n\nimport { defineProvider } from './provider';\nimport * as registries from '../registries';\nimport { loadApplicationContext } from '../loaders';\nimport * as draftAndPublishSync from '../migrations/draft-publish';\nimport { discardDocumentDrafts } from '../migrations/database/5.0.0-discard-drafts';\n\nexport default defineProvider({\n init(strapi) {\n strapi\n .add('content-types', () => registries.contentTypes())\n .add('components', () => registries.components())\n .add('services', () => registries.services(strapi))\n .add('policies', () => registries.policies())\n .add('middlewares', () => registries.middlewares())\n .add('hooks', () => registries.hooks())\n .add('controllers', () => registries.controllers(strapi))\n .add('modules', () => registries.modules(strapi))\n .add('plugins', () => registries.plugins(strapi))\n .add('custom-fields', () => registries.customFields(strapi))\n .add('apis', () => registries.apis(strapi))\n .add('models', () => registries.models())\n .add('sanitizers', registries.sanitizers())\n .add('validators', registries.validators());\n },\n async register(strapi) {\n await loadApplicationContext(strapi);\n\n strapi.get('hooks').set('strapi::content-types.beforeSync', hooks.createAsyncParallelHook());\n strapi.get('hooks').set('strapi::content-types.afterSync', hooks.createAsyncParallelHook());\n\n // Content migration to enable draft and publish\n strapi.hook('strapi::content-types.beforeSync').register(draftAndPublishSync.disable);\n strapi.hook('strapi::content-types.afterSync').register(draftAndPublishSync.enable);\n\n // Database migrations\n strapi.db.migrations.providers.internal.register(discardDocumentDrafts);\n },\n});\n"],"names":["registries.contentTypes","registries.components","registries.services","registries.policies","registries.middlewares","registries.hooks","registries.controllers","registries.modules","registries.plugins","registries.customFields","registries.apis","registries.models","registries.sanitizers","registries.validators","draftAndPublishSync.disable","draftAndPublishSync.enable"],"mappings":";;;;;;;;;;;;;;;;;;;AAQA,MAAA,aAAe,eAAe;AAAA,EAC5B,KAAK,QAAQ;AAER,WAAA,IAAI,iBAAiB,MAAMA,qBAAyB,CAAA,EACpD,IAAI,cAAc,MAAMC,mBAAuB,CAAA,EAC/C,IAAI,YAAY,MAAMC,iBAAoB,MAAM,CAAC,EACjD,IAAI,YAAY,MAAMC,iBAAqB,CAAA,EAC3C,IAAI,eAAe,MAAMC,oBAAuB,CAAC,EACjD,IAAI,SAAS,MAAMC,eAAkB,EACrC,IAAI,eAAe,MAAMC,oBAAuB,MAAM,CAAC,EACvD,IAAI,WAAW,MAAMC,gBAAmB,MAAM,CAAC,EAC/C,IAAI,WAAW,MAAMC,gBAAmB,MAAM,CAAC,EAC/C,IAAI,iBAAiB,MAAMC,qBAAwB,MAAM,CAAC,EAC1D,IAAI,QAAQ,MAAMC,aAAgB,MAAM,CAAC,EACzC,IAAI,UAAU,MAAMC,SAAmB,CAAA,EACvC,IAAI,cAAcC,oBAAuB,EACzC,IAAI,cAAcC,mBAAW,CAAY;AAAA,EAC9C;AAAA,EACA,MAAM,SAAS,QAAQ;AACrB,UAAM,uBAAuB,MAAM;AAEnC,WAAO,IAAI,OAAO,EAAE,IAAI,oCAAoC,MAAM,yBAAyB;AAC3F,WAAO,IAAI,OAAO,EAAE,IAAI,mCAAmC,MAAM,yBAAyB;AAG1F,WAAO,KAAK,kCAAkC,EAAE,SAASC,sBAA2B;AACpF,WAAO,KAAK,iCAAiC,EAAE,SAASC,qBAA0B;AAGlF,WAAO,GAAG,WAAW,UAAU,SAAS,SAAS,qBAAqB;AAAA,EACxE;AACF,CAAC;"}
1
+ {"version":3,"file":"registries.mjs","sources":["../../src/providers/registries.ts"],"sourcesContent":["import { hooks } from '@strapi/utils';\n\nimport { defineProvider } from './provider';\nimport * as registries from '../registries';\nimport { loadApplicationContext } from '../loaders';\nimport * as syncMigrations from '../migrations';\nimport { discardDocumentDrafts } from '../migrations/database/5.0.0-discard-drafts';\n\nexport default defineProvider({\n init(strapi) {\n strapi\n .add('content-types', () => registries.contentTypes())\n .add('components', () => registries.components())\n .add('services', () => registries.services(strapi))\n .add('policies', () => registries.policies())\n .add('middlewares', () => registries.middlewares())\n .add('hooks', () => registries.hooks())\n .add('controllers', () => registries.controllers(strapi))\n .add('modules', () => registries.modules(strapi))\n .add('plugins', () => registries.plugins(strapi))\n .add('custom-fields', () => registries.customFields(strapi))\n .add('apis', () => registries.apis(strapi))\n .add('models', () => registries.models())\n .add('sanitizers', registries.sanitizers())\n .add('validators', registries.validators());\n },\n async register(strapi) {\n await loadApplicationContext(strapi);\n\n strapi.get('hooks').set('strapi::content-types.beforeSync', hooks.createAsyncParallelHook());\n strapi.get('hooks').set('strapi::content-types.afterSync', hooks.createAsyncParallelHook());\n\n // Content migration to enable draft and publish\n strapi.hook('strapi::content-types.beforeSync').register(syncMigrations.disable);\n strapi.hook('strapi::content-types.afterSync').register(syncMigrations.enable);\n\n // Database migrations\n strapi.db.migrations.providers.internal.register(discardDocumentDrafts);\n },\n});\n"],"names":["registries.contentTypes","registries.components","registries.services","registries.policies","registries.middlewares","registries.hooks","registries.controllers","registries.modules","registries.plugins","registries.customFields","registries.apis","registries.models","registries.sanitizers","registries.validators","syncMigrations.disable","syncMigrations.enable"],"mappings":";;;;;;;;;;;;;;;;;;;AAQA,MAAA,aAAe,eAAe;AAAA,EAC5B,KAAK,QAAQ;AAER,WAAA,IAAI,iBAAiB,MAAMA,qBAAyB,CAAA,EACpD,IAAI,cAAc,MAAMC,mBAAuB,CAAA,EAC/C,IAAI,YAAY,MAAMC,iBAAoB,MAAM,CAAC,EACjD,IAAI,YAAY,MAAMC,iBAAqB,CAAA,EAC3C,IAAI,eAAe,MAAMC,oBAAuB,CAAC,EACjD,IAAI,SAAS,MAAMC,eAAkB,EACrC,IAAI,eAAe,MAAMC,oBAAuB,MAAM,CAAC,EACvD,IAAI,WAAW,MAAMC,gBAAmB,MAAM,CAAC,EAC/C,IAAI,WAAW,MAAMC,gBAAmB,MAAM,CAAC,EAC/C,IAAI,iBAAiB,MAAMC,qBAAwB,MAAM,CAAC,EAC1D,IAAI,QAAQ,MAAMC,aAAgB,MAAM,CAAC,EACzC,IAAI,UAAU,MAAMC,SAAmB,CAAA,EACvC,IAAI,cAAcC,oBAAuB,EACzC,IAAI,cAAcC,mBAAW,CAAY;AAAA,EAC9C;AAAA,EACA,MAAM,SAAS,QAAQ;AACrB,UAAM,uBAAuB,MAAM;AAEnC,WAAO,IAAI,OAAO,EAAE,IAAI,oCAAoC,MAAM,yBAAyB;AAC3F,WAAO,IAAI,OAAO,EAAE,IAAI,mCAAmC,MAAM,yBAAyB;AAG1F,WAAO,KAAK,kCAAkC,EAAE,SAASC,OAAsB;AAC/E,WAAO,KAAK,iCAAiC,EAAE,SAASC,MAAqB;AAG7E,WAAO,GAAG,WAAW,UAAU,SAAS,SAAS,qBAAqB;AAAA,EACxE;AACF,CAAC;"}
@@ -13,7 +13,7 @@ declare const policiesRegistry: () => {
13
13
  /**
14
14
  * Returns this list of registered policies uids
15
15
  */
16
- keys(): IterableIterator<string>;
16
+ keys(): string[];
17
17
  /**
18
18
  * Returns the instance of a policy. Instantiate the policy if not already done
19
19
  */
@@ -1 +1 @@
1
- {"version":3,"file":"policies.d.ts","sourceRoot":"","sources":["../../src/registries/policies.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAM1C,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,KAAK,YAAY,GAAG,MAAM,GAAG,UAAU,CAAC;AAExC,UAAU,aAAa;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAWD,QAAA,MAAM,gBAAgB;IAyDlB;;OAEG;;IAKH;;OAEG;cACO,MAAM,kBAAkB,aAAa;IAG/C;;OAEG;cACO,MAAM,kBAAkB,aAAa;IAK/C;;OAEG;sBACe,MAAM;IAIxB;;OAEG;aACM,MAAM,UAAU,KAAK,MAAM;IAKpC;;OAEG;mBACY,MAAM,eAAe,OAAO,MAAM,EAAE,KAAK,MAAM,CAAC;IAa/D;;OAEG;oBACa,YAAY,GAAG,YAAY,EAAE,kBAAkB,aAAa;;;;CAW/E,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"policies.d.ts","sourceRoot":"","sources":["../../src/registries/policies.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAM1C,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,KAAK,YAAY,GAAG,MAAM,GAAG,UAAU,CAAC;AAExC,UAAU,aAAa;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAWD,QAAA,MAAM,gBAAgB;IAyDlB;;OAEG;;IAMH;;OAEG;cACO,MAAM,kBAAkB,aAAa;IAG/C;;OAEG;cACO,MAAM,kBAAkB,aAAa;IAK/C;;OAEG;sBACe,MAAM;IAIxB;;OAEG;aACM,MAAM,UAAU,KAAK,MAAM;IAKpC;;OAEG;mBACY,MAAM,eAAe,OAAO,MAAM,EAAE,KAAK,MAAM,CAAC;IAa/D;;OAEG;oBACa,YAAY,GAAG,YAAY,EAAE,kBAAkB,aAAa;;;;CAW/E,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -49,7 +49,7 @@ const policiesRegistry = () => {
49
49
  * Returns this list of registered policies uids
50
50
  */
51
51
  keys() {
52
- return policies.keys();
52
+ return Array.from(policies.keys());
53
53
  },
54
54
  /**
55
55
  * Returns the instance of a policy. Instantiate the policy if not already done
@@ -1 +1 @@
1
- {"version":3,"file":"policies.js","sources":["../../src/registries/policies.ts"],"sourcesContent":["import { pickBy, has, castArray } from 'lodash/fp';\nimport type { Core } from '@strapi/types';\nimport { addNamespace, hasNamespace } from './namespace';\n\nconst PLUGIN_PREFIX = 'plugin::';\nconst API_PREFIX = 'api::';\n\ninterface PolicyInfo {\n name: string;\n config: unknown;\n}\n\ntype PolicyConfig = string | PolicyInfo;\n\ninterface NamespaceInfo {\n pluginName?: string;\n apiName?: string;\n}\n\nconst parsePolicy = (policy: string | PolicyInfo) => {\n if (typeof policy === 'string') {\n return { policyName: policy, config: {} };\n }\n\n const { name, config } = policy;\n return { policyName: name, config };\n};\n\nconst policiesRegistry = () => {\n const policies = new Map<string, Core.Policy>();\n\n const find = (name: string, namespaceInfo?: NamespaceInfo) => {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n // try to resolve a full name to avoid extra prefixing\n const policy = policies.get(name);\n\n if (policy) {\n return policy;\n }\n\n if (pluginName) {\n return policies.get(`${PLUGIN_PREFIX}${pluginName}.${name}`);\n }\n\n if (apiName) {\n return policies.get(`${API_PREFIX}${apiName}.${name}`);\n }\n };\n\n function resolveHandler(policyConfig: PolicyConfig, namespaceInfo?: NamespaceInfo): Core.Policy;\n function resolveHandler(\n policyConfig: PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy[];\n function resolveHandler(\n policyConfig: PolicyConfig | PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy | Core.Policy[] {\n if (Array.isArray(policyConfig)) {\n return policyConfig.map((config) => {\n return resolveHandler(config, namespaceInfo);\n });\n }\n\n const { policyName, config } = parsePolicy(policyConfig);\n\n const policy = find(policyName, namespaceInfo);\n\n if (!policy) {\n throw new Error(`Policy ${policyName} not found.`);\n }\n\n if (typeof policy === 'function') {\n return policy;\n }\n\n if (policy.validator) {\n policy.validator(config);\n }\n\n return policy.handler;\n }\n\n return {\n /**\n * Returns this list of registered policies uids\n */\n keys() {\n return policies.keys();\n },\n\n /**\n * Returns the instance of a policy. Instantiate the policy if not already done\n */\n get(name: string, namespaceInfo?: NamespaceInfo) {\n return find(name, namespaceInfo);\n },\n /**\n * Checks if a policy is registered\n */\n has(name: string, namespaceInfo?: NamespaceInfo) {\n const res = find(name, namespaceInfo);\n return !!res;\n },\n\n /**\n * Returns a map with all the policies in a namespace\n */\n getAll(namespace: string) {\n return pickBy((_, uid) => hasNamespace(uid, namespace))(Object.fromEntries(policies));\n },\n\n /**\n * Registers a policy\n */\n set(uid: string, policy: Core.Policy) {\n policies.set(uid, policy);\n return this;\n },\n\n /**\n * Registers a map of policies for a specific namespace\n */\n add(namespace: string, newPolicies: Record<string, Core.Policy>) {\n for (const policyName of Object.keys(newPolicies)) {\n const policy = newPolicies[policyName];\n const uid = addNamespace(policyName, namespace);\n\n if (has(uid, policies)) {\n throw new Error(`Policy ${uid} has already been registered.`);\n }\n\n policies.set(uid, policy);\n }\n },\n\n /**\n * Resolves a list of policies\n */\n resolve(config: PolicyConfig | PolicyConfig[], namespaceInfo?: NamespaceInfo) {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n return castArray(config).map((policyConfig) => {\n return {\n handler: resolveHandler(policyConfig, { pluginName, apiName }),\n config: (typeof policyConfig === 'object' && policyConfig.config) || {},\n };\n });\n },\n };\n};\n\nexport default policiesRegistry;\n"],"names":["config","namespace","pickBy","hasNamespace","addNamespace","has","castArray"],"mappings":";;;AAIA,MAAM,gBAAgB;AACtB,MAAM,aAAa;AAcnB,MAAM,cAAc,CAAC,WAAgC;AAC/C,MAAA,OAAO,WAAW,UAAU;AAC9B,WAAO,EAAE,YAAY,QAAQ,QAAQ,CAAG,EAAA;AAAA,EAC1C;AAEM,QAAA,EAAE,MAAM,OAAW,IAAA;AAClB,SAAA,EAAE,YAAY,MAAM;AAC7B;AAEA,MAAM,mBAAmB,MAAM;AACvB,QAAA,+BAAe;AAEf,QAAA,OAAO,CAAC,MAAc,kBAAkC;AAC5D,UAAM,EAAE,YAAY,YAAY,iBAAiB,CAAA;AAG3C,UAAA,SAAS,SAAS,IAAI,IAAI;AAEhC,QAAI,QAAQ;AACH,aAAA;AAAA,IACT;AAEA,QAAI,YAAY;AACP,aAAA,SAAS,IAAI,GAAG,aAAa,GAAG,UAAU,IAAI,IAAI,EAAE;AAAA,IAC7D;AAEA,QAAI,SAAS;AACJ,aAAA,SAAS,IAAI,GAAG,UAAU,G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,YAAYH,WAAS;AAE1C,YAAAI,GAAA,IAAI,KAAK,QAAQ,GAAG;AACtB,gBAAM,IAAI,MAAM,UAAU,GAAG,+BAA+B;AAAA,QAC9D;AAES,iBAAA,IAAI,KAAK,MAAM;AAAA,MAC1B;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,QAAQ,QAAuC,eAA+B;AAC5E,YAAM,EAAE,YAAY,YAAY,iBAAiB,CAAA;AAEjD,aAAOC,GAAU,UAAA,MAAM,EAAE,IAAI,CAAC,iBAAiB;AACtC,eAAA;AAAA,UACL,SAAS,eAAe,cAAc,EAAE,YAAY,SAAS;AAAA,UAC7D,QAAS,OAAO,iBAAiB,YAAY,aAAa,UAAW,CAAC;AAAA,QAAA;AAAA,MACxE,CACD;AAAA,IACH;AAAA,EAAA;AAEJ;;"}
1
+ {"version":3,"file":"policies.js","sources":["../../src/registries/policies.ts"],"sourcesContent":["import { pickBy, has, castArray } from 'lodash/fp';\nimport type { Core } from '@strapi/types';\nimport { addNamespace, hasNamespace } from './namespace';\n\nconst PLUGIN_PREFIX = 'plugin::';\nconst API_PREFIX = 'api::';\n\ninterface PolicyInfo {\n name: string;\n config: unknown;\n}\n\ntype PolicyConfig = string | PolicyInfo;\n\ninterface NamespaceInfo {\n pluginName?: string;\n apiName?: string;\n}\n\nconst parsePolicy = (policy: string | PolicyInfo) => {\n if (typeof policy === 'string') {\n return { policyName: policy, config: {} };\n }\n\n const { name, config } = policy;\n return { policyName: name, config };\n};\n\nconst policiesRegistry = () => {\n const policies = new Map<string, Core.Policy>();\n\n const find = (name: string, namespaceInfo?: NamespaceInfo) => {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n // try to resolve a full name to avoid extra prefixing\n const policy = policies.get(name);\n\n if (policy) {\n return policy;\n }\n\n if (pluginName) {\n return policies.get(`${PLUGIN_PREFIX}${pluginName}.${name}`);\n }\n\n if (apiName) {\n return policies.get(`${API_PREFIX}${apiName}.${name}`);\n }\n };\n\n function resolveHandler(policyConfig: PolicyConfig, namespaceInfo?: NamespaceInfo): Core.Policy;\n function resolveHandler(\n policyConfig: PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy[];\n function resolveHandler(\n policyConfig: PolicyConfig | PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy | Core.Policy[] {\n if (Array.isArray(policyConfig)) {\n return policyConfig.map((config) => {\n return resolveHandler(config, namespaceInfo);\n });\n }\n\n const { policyName, config } = parsePolicy(policyConfig);\n\n const policy = find(policyName, namespaceInfo);\n\n if (!policy) {\n throw new Error(`Policy ${policyName} not found.`);\n }\n\n if (typeof policy === 'function') {\n return policy;\n }\n\n if (policy.validator) {\n policy.validator(config);\n }\n\n return policy.handler;\n }\n\n return {\n /**\n * Returns this list of registered policies uids\n */\n keys() {\n // Return an array so format stays the same as controllers, services, etc\n return Array.from(policies.keys());\n },\n\n /**\n * Returns the instance of a policy. Instantiate the policy if not already done\n */\n get(name: string, namespaceInfo?: NamespaceInfo) {\n return find(name, namespaceInfo);\n },\n /**\n * Checks if a policy is registered\n */\n has(name: string, namespaceInfo?: NamespaceInfo) {\n const res = find(name, namespaceInfo);\n return !!res;\n },\n\n /**\n * Returns a map with all the policies in a namespace\n */\n getAll(namespace: string) {\n return pickBy((_, uid) => hasNamespace(uid, namespace))(Object.fromEntries(policies));\n },\n\n /**\n * Registers a policy\n */\n set(uid: string, policy: Core.Policy) {\n policies.set(uid, policy);\n return this;\n },\n\n /**\n * Registers a map of policies for a specific namespace\n */\n add(namespace: string, newPolicies: Record<string, Core.Policy>) {\n for (const policyName of Object.keys(newPolicies)) {\n const policy = newPolicies[policyName];\n const uid = addNamespace(policyName, namespace);\n\n if (has(uid, policies)) {\n throw new Error(`Policy ${uid} has already been registered.`);\n }\n\n policies.set(uid, policy);\n }\n },\n\n /**\n * Resolves a list of policies\n */\n resolve(config: PolicyConfig | PolicyConfig[], namespaceInfo?: NamespaceInfo) {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n return castArray(config).map((policyConfig) => {\n return {\n handler: resolveHandler(policyConfig, { pluginName, apiName }),\n config: (typeof policyConfig === 'object' && policyConfig.config) || {},\n };\n });\n },\n };\n};\n\nexport default policiesRegistry;\n"],"names":["config","namespace","pickBy","hasNamespace","addNamespace","has","castArray"],"mappings":";;;AAIA,MAAM,gBAAgB;AACtB,MAAM,aAAa;AAcnB,MAAM,cAAc,CAAC,WAAgC;AAC/C,MAAA,OAAO,WAAW,UAAU;AAC9B,WAAO,EAAE,YAAY,QAAQ,QAAQ,CAAG,EAAA;AAAA,EAC1C;AAEM,QAAA,EAAE,MAAM,OAAW,IAAA;AAClB,SAAA,EAAE,YAAY,MAAM;AAC7B;AAEA,MAAM,mBAAmB,MAAM;AACvB,QAAA,+BAAe;AAEf,QAAA,OAAO,CAAC,MAAc,kBAAkC;AAC5D,UAAM,EAAE,YAAY,YAAY,iBAAiB,CAAA;AAG3C,UAAA,SAAS,SAAS,IAAI,IAAI;AAEhC,QAAI,QAAQ;AACH,aAAA;AAAA,IACT;AAEA,QAAI,YAAY;AACP,aAAA,SAAS,IAAI,GAAG,aAAa,GAAG,UAAU,IAAI,IAAI,EAAE;AAAA,IAC7D;AAEA,QAAI,SAAS;AACJ,aAAA,SAAS,IAAI,GAAG,UAAU,GAAG,OAAO,IAAI,IAAI,EAAE;AAAA,IACvD;AAAA,EAAA;AAQO,WAAA,eACP,cACA,eAC6B;AACzB,QAAA,MAAM,QAAQ,YAAY,GAAG;AACxB,aAAA,aAAa,IAAI,CAACA,YAAW;AAC3B,eAAA,eAAeA,SAAQ,aAAa;AAAA,MAAA,CAC5C;AAAA,IACH;AAEA,UAAM,EAAE,YAAY,OAAO,IAAI,YAAY,YAAY;AAEjD,UAAA,SAAS,KAAK,YAAY,aAAa;AAE7C,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,UAAU,UAAU,aAAa;AAAA,IACnD;AAEI,QAAA,OAAO,WAAW,YAAY;AACzB,aAAA;AAAA,IACT;AA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OAAO,iBAAiB,YAAY,aAAa,UAAW,CAAC;AAAA,QAAA;AAAA,MACxE,CACD;AAAA,IACH;AAAA,EAAA;AAEJ;;"}
@@ -48,7 +48,7 @@ const policiesRegistry = () => {
48
48
  * Returns this list of registered policies uids
49
49
  */
50
50
  keys() {
51
- return policies.keys();
51
+ return Array.from(policies.keys());
52
52
  },
53
53
  /**
54
54
  * Returns the instance of a policy. Instantiate the policy if not already done
@@ -1 +1 @@
1
- {"version":3,"file":"policies.mjs","sources":["../../src/registries/policies.ts"],"sourcesContent":["import { pickBy, has, castArray } from 'lodash/fp';\nimport type { Core } from '@strapi/types';\nimport { addNamespace, hasNamespace } from './namespace';\n\nconst PLUGIN_PREFIX = 'plugin::';\nconst API_PREFIX = 'api::';\n\ninterface PolicyInfo {\n name: string;\n config: unknown;\n}\n\ntype PolicyConfig = string | PolicyInfo;\n\ninterface NamespaceInfo {\n pluginName?: string;\n apiName?: string;\n}\n\nconst parsePolicy = (policy: string | PolicyInfo) => {\n if (typeof policy === 'string') {\n return { policyName: policy, config: {} };\n }\n\n const { name, config } = policy;\n return { policyName: name, config };\n};\n\nconst policiesRegistry = () => {\n const policies = new Map<string, Core.Policy>();\n\n const find = (name: string, namespaceInfo?: NamespaceInfo) => {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n // try to resolve a full name to avoid extra prefixing\n const policy = policies.get(name);\n\n if (policy) {\n return policy;\n }\n\n if (pluginName) {\n return policies.get(`${PLUGIN_PREFIX}${pluginName}.${name}`);\n }\n\n if (apiName) {\n return policies.get(`${API_PREFIX}${apiName}.${name}`);\n }\n };\n\n function resolveHandler(policyConfig: PolicyConfig, namespaceInfo?: NamespaceInfo): Core.Policy;\n function resolveHandler(\n policyConfig: PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy[];\n function resolveHandler(\n policyConfig: PolicyConfig | PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy | Core.Policy[] {\n if (Array.isArray(policyConfig)) {\n return policyConfig.map((config) => {\n return resolveHandler(config, namespaceInfo);\n });\n }\n\n const { policyName, config } = parsePolicy(policyConfig);\n\n const policy = find(policyName, namespaceInfo);\n\n if (!policy) {\n throw new Error(`Policy ${policyName} not found.`);\n }\n\n if (typeof policy === 'function') {\n return policy;\n }\n\n if (policy.validator) {\n policy.validator(config);\n }\n\n return policy.handler;\n }\n\n return {\n /**\n * Returns this list of registered policies uids\n */\n keys() {\n return policies.keys();\n },\n\n /**\n * Returns the instance of a policy. Instantiate the policy if not already done\n */\n get(name: string, namespaceInfo?: NamespaceInfo) {\n return find(name, namespaceInfo);\n },\n /**\n * Checks if a policy is registered\n */\n has(name: string, namespaceInfo?: NamespaceInfo) {\n const res = find(name, namespaceInfo);\n return !!res;\n },\n\n /**\n * Returns a map with all the policies in a namespace\n */\n getAll(namespace: string) {\n return pickBy((_, uid) => hasNamespace(uid, namespace))(Object.fromEntries(policies));\n },\n\n /**\n * Registers a policy\n */\n set(uid: string, policy: Core.Policy) {\n policies.set(uid, policy);\n return this;\n },\n\n /**\n * Registers a map of policies for a specific namespace\n */\n add(namespace: string, newPolicies: Record<string, Core.Policy>) {\n for (const policyName of Object.keys(newPolicies)) {\n const policy = newPolicies[policyName];\n const uid = addNamespace(policyName, namespace);\n\n if (has(uid, policies)) {\n throw new Error(`Policy ${uid} has already been registered.`);\n }\n\n policies.set(uid, policy);\n }\n },\n\n /**\n * Resolves a list of policies\n */\n resolve(config: PolicyConfig | PolicyConfig[], namespaceInfo?: NamespaceInfo) {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n return castArray(config).map((policyConfig) => {\n return {\n handler: resolveHandler(policyConfig, { pluginName, apiName }),\n config: (typeof policyConfig === 'object' && policyConfig.config) || {},\n };\n });\n },\n };\n};\n\nexport default policiesRegistry;\n"],"names":["config"],"mappings":";;AAIA,MAAM,gBAAgB;AACtB,MAAM,aAAa;AAcnB,MAAM,cAAc,CAAC,WAAgC;AAC/C,MAAA,OAAO,WAAW,UAAU;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AA+B;AACzC,YAAA,MAAM,KAAK,MAAM,aAAa;AACpC,aAAO,CAAC,CAAC;AAAA,IACX;AAAA;AAAA;AAAA;AAAA,IAKA,OAAO,WAAmB;AACxB,aAAO,OAAO,CAAC,GAAG,QAAQ,aAAa,KAAK,SAAS,CAAC,EAAE,OAAO,YAAY,QAAQ,CAAC;AAAA,IACtF;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAa,QAAqB;AAC3B,eAAA,IAAI,KAAK,MAAM;AACjB,aAAA;AAAA,IACT;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,WAAmB,aAA0C;AAC/D,iBAAW,cAAc,OAAO,KAAK,WAAW,GAAG;AAC3C,cAAA,SAAS,YAAY,UAAU;AAC/B,cAAA,MAAM,aAAa,YAAY,SAAS;AAE1C,YAAA,IAAI,KAAK,QAAQ,GAAG;AACtB,gBAAM,IAAI,MAAM,UAAU,GAAG,+BAA+B;AAAA,QAC9D;AAES,iBAAA,IAAI,KAAK,MAAM;AAAA,MAC1B;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,QAAQ,QAAuC,eAA+B;AAC5E,YAAM,EAAE,YAAY,YAAY,iBAAiB,CAAA;AAEjD,aAAO,UAAU,MAAM,EAAE,IAAI,CAAC,iBAAiB;AACtC,eAAA;AAAA,UACL,SAAS,eAAe,cAAc,EAAE,YAAY,SAAS;AAAA,UAC7D,QAAS,OAAO,iBAAiB,YAAY,aAAa,UAAW,CAAC;AAAA,QAAA;AAAA,MACxE,CACD;AAAA,IACH;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"policies.mjs","sources":["../../src/registries/policies.ts"],"sourcesContent":["import { pickBy, has, castArray } from 'lodash/fp';\nimport type { Core } from '@strapi/types';\nimport { addNamespace, hasNamespace } from './namespace';\n\nconst PLUGIN_PREFIX = 'plugin::';\nconst API_PREFIX = 'api::';\n\ninterface PolicyInfo {\n name: string;\n config: unknown;\n}\n\ntype PolicyConfig = string | PolicyInfo;\n\ninterface NamespaceInfo {\n pluginName?: string;\n apiName?: string;\n}\n\nconst parsePolicy = (policy: string | PolicyInfo) => {\n if (typeof policy === 'string') {\n return { policyName: policy, config: {} };\n }\n\n const { name, config } = policy;\n return { policyName: name, config };\n};\n\nconst policiesRegistry = () => {\n const policies = new Map<string, Core.Policy>();\n\n const find = (name: string, namespaceInfo?: NamespaceInfo) => {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n // try to resolve a full name to avoid extra prefixing\n const policy = policies.get(name);\n\n if (policy) {\n return policy;\n }\n\n if (pluginName) {\n return policies.get(`${PLUGIN_PREFIX}${pluginName}.${name}`);\n }\n\n if (apiName) {\n return policies.get(`${API_PREFIX}${apiName}.${name}`);\n }\n };\n\n function resolveHandler(policyConfig: PolicyConfig, namespaceInfo?: NamespaceInfo): Core.Policy;\n function resolveHandler(\n policyConfig: PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy[];\n function resolveHandler(\n policyConfig: PolicyConfig | PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy | Core.Policy[] {\n if (Array.isArray(policyConfig)) {\n return policyConfig.map((config) => {\n return resolveHandler(config, namespaceInfo);\n });\n }\n\n const { policyName, config } = parsePolicy(policyConfig);\n\n const policy = find(policyName, namespaceInfo);\n\n if (!policy) {\n throw new Error(`Policy ${policyName} not found.`);\n }\n\n if (typeof policy === 'function') {\n return policy;\n }\n\n if (policy.validator) {\n policy.validator(config);\n }\n\n return policy.handler;\n }\n\n return {\n /**\n * Returns this list of registered policies uids\n */\n keys() {\n // Return an array so format stays the same as controllers, services, etc\n return Array.from(policies.keys());\n },\n\n /**\n * Returns the instance of a policy. Instantiate the policy if not already done\n */\n get(name: string, namespaceInfo?: NamespaceInfo) {\n return find(name, namespaceInfo);\n },\n /**\n * Checks if a policy is registered\n */\n has(name: string, namespaceInfo?: NamespaceInfo) {\n const res = find(name, namespaceInfo);\n return !!res;\n },\n\n /**\n * Returns a map with all the policies in a namespace\n */\n getAll(namespace: string) {\n return pickBy((_, uid) => hasNamespace(uid, namespace))(Object.fromEntries(policies));\n },\n\n /**\n * Registers a policy\n */\n set(uid: string, policy: Core.Policy) {\n policies.set(uid, policy);\n return this;\n },\n\n /**\n * Registers a map of policies for a specific namespace\n */\n add(namespace: string, newPolicies: Record<string, Core.Policy>) {\n for (const policyName of Object.keys(newPolicies)) {\n const policy = newPolicies[policyName];\n const uid = addNamespace(policyName, namespace);\n\n if (has(uid, policies)) {\n throw new Error(`Policy ${uid} has already been registered.`);\n }\n\n policies.set(uid, policy);\n }\n },\n\n /**\n * Resolves a list of policies\n */\n resolve(config: PolicyConfig | PolicyConfig[], namespaceInfo?: NamespaceInfo) {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n return castArray(config).map((policyConfig) => {\n return {\n handler: resolveHandler(policyConfig, { pluginName, apiName }),\n config: (typeof policyConfig === 'object' && policyConfig.config) || {},\n };\n });\n },\n };\n};\n\nexport default policiesRegistry;\n"],"names":["config"],"mappings":";;AAIA,MAAM,gBAAgB;AACtB,MAAM,aAAa;AAcnB,MAAM,cAAc,CAAC,WAAgC;AAC/C,MAAA,OAAO,WAAW,UAAU;AAC9B,WAAO,EAAE,YAAY,QAAQ,QAAQ,CAAG,EAAA;AAAA,EAC1C;AAEM,QAAA,EAAE,MAAM,OAAW,IAAA;AAClB,SAAA,EAAE,YAAY,MAAM;AAC7B;AAEA,MAAM,mBAAmB,MAAM;AACvB,QAAA,+BAAe;AAEf,QAAA,OAAO,CAAC,MAAc,kBAAkC;AAC5D,UAAM,EAAE,YAAY,YAAY,iBAAiB,CAAA;AAG3C,UAAA,SAAS,SAAS,IAAI,IAAI;AAEhC,QAAI,QAAQ;AACH,aAAA;AAAA,IACT;AAEA,QAAI,YAAY;AACP,aAAA,SAAS,IAAI,GAAG,aAAa,GAAG,UAAU,IAAI,IAAI,EAAE;AAAA,IAC7D;AAEA,QAAI,SAAS;AACJ,aAAA,SAAS,IAAI,GAAG,UAAU,GAAG,OAAO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