@strapi/core 5.0.0-rc.22 → 5.0.0-rc.24

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.
@@ -1 +1 @@
1
- {"version":3,"file":"5.0.0-discard-drafts.d.ts","sourceRoot":"","sources":["../../../src/migrations/database/5.0.0-discard-drafts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG5D,KAAK,eAAe,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAC9D,KAAK,IAAI,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAgF3C;;;;;GAKG;AACH,wBAAuB,iBAAiB,CAAC,EACvC,EAAE,EACF,GAAG,EACH,GAAG,EACH,SAAgB,GACjB,EAAE;IACD,EAAE,EAAE,QAAQ,CAAC;IACb,GAAG,EAAE,IAAI,CAAC;IACV,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,oDAuBA;AAwCD,eAAO,MAAM,qBAAqB,EAAE,SAQnC,CAAC"}
1
+ {"version":3,"file":"5.0.0-discard-drafts.d.ts","sourceRoot":"","sources":["../../../src/migrations/database/5.0.0-discard-drafts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG5D,KAAK,eAAe,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAC9D,KAAK,IAAI,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAqF3C;;;;;GAKG;AACH,wBAAuB,iBAAiB,CAAC,EACvC,EAAE,EACF,GAAG,EACH,GAAG,EACH,SAAgB,GACjB,EAAE;IACD,EAAE,EAAE,QAAQ,CAAC;IACb,GAAG,EAAE,IAAI,CAAC;IACV,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,oDAuBA;AAwCD,eAAO,MAAM,qBAAqB,EAAE,SAQnC,CAAC"}
@@ -29,11 +29,16 @@ async function copyPublishedEntriesToDraft({
29
29
  }
30
30
  return acc;
31
31
  }, []);
32
- await trx.into(trx.raw(`${meta.tableName} (${scalarAttributes.join(", ")})`)).insert((subQb) => {
32
+ await trx.into(
33
+ trx.raw(`?? (${scalarAttributes.map(() => `??`).join(", ")})`, [
34
+ meta.tableName,
35
+ ...scalarAttributes
36
+ ])
37
+ ).insert((subQb) => {
33
38
  subQb.select(
34
39
  ...scalarAttributes.map((att) => {
35
40
  if (att === "published_at") {
36
- return trx.raw("NULL as published_at");
41
+ return trx.raw("NULL as ??", "published_at");
37
42
  }
38
43
  return att;
39
44
  })
@@ -1 +1 @@
1
- {"version":3,"file":"5.0.0-discard-drafts.js","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';\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(trx.raw(`${meta.tableName} (${scalarAttributes.join(', ')})`))\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 for (const model of dpModels) {\n const discardDraft = async (entry: DocumentVersion) =>\n strapi\n .documents(model.uid as UID.ContentType)\n .discardDraft({ documentId: entry.documentId, locale: entry.locale });\n\n for await (const batch of getBatchToDiscard({ db, trx, uid: model.uid })) {\n await async.map(batch, discardDraft, { concurrency: 10 });\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":["contentTypes","async"],"mappings":";;;AAwBA,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,QAAQA,YAAAA,aAAa,mBAAmB,KAAK;AACnD,MAAI,CAAC,OAAO;AACH,WAAA;AAAA,EACT;AAEO,SAAA;AACT;AAMA,eAAe,4BAA4B;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AACF,GAIG;AAED,QAAM,OAAO,GAAG,SAAS,IAAI,GAAG;AAG1B,QAAA,mBAAmB,OAAO,OAAO,KAAK,UAAU,EAAE,OAAO,CAAC,KAAK,cAAmB;AACtF,QAAI,CAAC,IAAI,EAAE,SAAS,UAAU,UAAU,GAAG;AAClC,aAAA;AAAA,IACT;AAEI,QAAAA,YAAA,aAAa,kBAAkB,SAAS,GAAG;AACzC,UAAA,KAAK,UAAU,UAAU;AAAA,IAC/B;AAEO,WAAA;AAAA,EACT,GAAG,CAAc,CAAA;AASjB,QAAM,IAEH,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,KAAK,iBAAiB,KAAK,IAAI,CAAC,GAAG,CAAC,EAClE,OAAO,CAAC,UAAsB;AAG1B,UAAA;AAAA,MACC,GAAG,iBAAiB,IAAI,CAAC,QAAgB;AAEvC,YAAI,QAAQ,gBAAgB;AACnB,iBAAA,IAAI,IAAI,sBAAsB;AAAA,QACvC;AAEO,eAAA;AAAA,MAAA,CACR;AAAA,IAAA,EAEF,KAAK,KAAK,SAAS,EAEnB,aAAa,cAAc;AAAA,EAAA,CAC/B;AACL;AAQA,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;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;AAQA,aAAW,SAAS,UAAU;AAC5B,UAAM,eAAe,OAAO,UAC1B,OACG,UAAU,MAAM,GAAsB,EACtC,aAAa,EAAE,YAAY,MAAM,YAAY,QAAQ,MAAM,QAAQ;AAEvD,qBAAA,SAAS,kBAAkB,EAAE,IAAI,KAAK,KAAK,MAAM,IAAI,CAAC,GAAG;AACxE,YAAMC,YAAAA,MAAM,IAAI,OAAO,cAAc,EAAE,aAAa,IAAI;AAAA,IAC1D;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
+ {"version":3,"file":"5.0.0-discard-drafts.js","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';\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 for (const model of dpModels) {\n const discardDraft = async (entry: DocumentVersion) =>\n strapi\n .documents(model.uid as UID.ContentType)\n .discardDraft({ documentId: entry.documentId, locale: entry.locale });\n\n for await (const batch of getBatchToDiscard({ db, trx, uid: model.uid })) {\n await async.map(batch, discardDraft, { concurrency: 10 });\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":["contentTypes","async"],"mappings":"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"}
@@ -27,11 +27,16 @@ async function copyPublishedEntriesToDraft({
27
27
  }
28
28
  return acc;
29
29
  }, []);
30
- await trx.into(trx.raw(`${meta.tableName} (${scalarAttributes.join(", ")})`)).insert((subQb) => {
30
+ await trx.into(
31
+ trx.raw(`?? (${scalarAttributes.map(() => `??`).join(", ")})`, [
32
+ meta.tableName,
33
+ ...scalarAttributes
34
+ ])
35
+ ).insert((subQb) => {
31
36
  subQb.select(
32
37
  ...scalarAttributes.map((att) => {
33
38
  if (att === "published_at") {
34
- return trx.raw("NULL as published_at");
39
+ return trx.raw("NULL as ??", "published_at");
35
40
  }
36
41
  return att;
37
42
  })
@@ -1 +1 @@
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';\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(trx.raw(`${meta.tableName} (${scalarAttributes.join(', ')})`))\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 for (const model of dpModels) {\n const discardDraft = async (entry: DocumentVersion) =>\n strapi\n .documents(model.uid as UID.ContentType)\n .discardDraft({ documentId: entry.documentId, locale: entry.locale });\n\n for await (const batch of getBatchToDiscard({ db, trx, uid: model.uid })) {\n await async.map(batch, discardDraft, { concurrency: 10 });\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":";AAwBA,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;AAAA,EACA;AAAA,EACA;AACF,GAIG;AAED,QAAM,OAAO,GAAG,SAAS,IAAI,GAAG;AAG1B,QAAA,mBAAmB,OAAO,OAAO,KAAK,UAAU,EAAE,OAAO,CAAC,KAAK,cAAmB;AACtF,QAAI,CAAC,IAAI,EAAE,SAAS,UAAU,UAAU,GAAG;AAClC,aAAA;AAAA,IACT;AAEI,QAAA,aAAa,kBAAkB,SAAS,GAAG;AACzC,UAAA,KAAK,UAAU,UAAU;AAAA,IAC/B;AAEO,WAAA;AAAA,EACT,GAAG,CAAc,CAAA;AASjB,QAAM,IAEH,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,KAAK,iBAAiB,KAAK,IAAI,CAAC,GAAG,CAAC,EAClE,OAAO,CAAC,UAAsB;AAG1B,UAAA;AAAA,MACC,GAAG,iBAAiB,IAAI,CAAC,QAAgB;AAEvC,YAAI,QAAQ,gBAAgB;AACnB,iBAAA,IAAI,IAAI,sBAAsB;AAAA,QACvC;AAEO,eAAA;AAAA,MAAA,CACR;AAAA,IAAA,EAEF,KAAK,KAAK,SAAS,EAEnB,aAAa,cAAc;AAAA,EAAA,CAC/B;AACL;AAQA,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;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;AAQA,aAAW,SAAS,UAAU;AAC5B,UAAM,eAAe,OAAO,UAC1B,OACG,UAAU,MAAM,GAAsB,EACtC,aAAa,EAAE,YAAY,MAAM,YAAY,QAAQ,MAAM,QAAQ;AAEvD,qBAAA,SAAS,kBAAkB,EAAE,IAAI,KAAK,KAAK,MAAM,IAAI,CAAC,GAAG;AACxE,YAAM,MAAM,IAAI,OAAO,cAAc,EAAE,aAAa,IAAI;AAAA,IAC1D;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
+ {"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';\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 for (const model of dpModels) {\n const discardDraft = async (entry: DocumentVersion) =>\n strapi\n .documents(model.uid as UID.ContentType)\n .discardDraft({ documentId: entry.documentId, locale: entry.locale });\n\n for await (const batch of getBatchToDiscard({ db, trx, uid: model.uid })) {\n await async.map(batch, discardDraft, { concurrency: 10 });\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":"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"}
@@ -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: null },\n }),\n ]);\n }\n }\n};\n\nexport { enableI18n as enable, disableI18n as disable };\n"],"names":[],"mappings":";;AAGA,MAAM,aAAa,OAAO,EAAE,iBAAiB,mBAA0B;AAC/D,QAAA,EAAE,2BAA2B,OAAO,OAAO,MAAM,GAAG,QAAQ,eAAe,KAAK;AAChF,QAAA,EAAE,qBAAqB,OAAO,OAAO,MAAM,GAAG,QAAQ,SAAS,KAAK;AAE1E,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;AAEpC,QAAI,CAAC,uBAAuB,cAAc,KAAK,uBAAuB,WAAW,GAAG;AAC5E,YAAA,gBAAgB,MAAM;AAE5B,YAAM,OAAO,GAAG,MAAM,GAAG,EAAE,WAAW;AAAA,QACpC,OAAO,EAAE,QAAQ,KAAK;AAAA,QACtB,MAAM,EAAE,QAAQ,cAAc;AAAA,MAAA,CAC/B;AAAA,IACH;AAAA,EACF;AACF;AAEA,MAAM,cAAc,OAAO,EAAE,iBAAiB,mBAA0B;AAChE,QAAA,EAAE,2BAA2B,OAAO,OAAO,MAAM,GAAG,QAAQ,eAAe,KAAK;AAChF,QAAA,EAAE,qBAAqB,OAAO,OAAO,MAAM,GAAG,QAAQ,SAAS,KAAK;AAE1E,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;AAGpC,QAAI,uBAAuB,cAAc,KAAK,CAAC,uBAAuB,WAAW,GAAG;AAC5E,YAAA,gBAAgB,MAAM;AAE5B,YAAM,QAAQ,IAAI;AAAA;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,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: { locale: { $eq: defaultLocale } },\n data: { locale: null },\n }),\n ]);\n }\n }\n};\n\nexport { enableI18n as enable, disableI18n as disable };\n"],"names":[],"mappings":"AAGA,MAAM,aAAa,OAAO,EAAE,iBAAiB,mBAA0B;AAC/D,QAAA,EAAE,2BAA2B,OAAO,OAAO,MAAM,GAAG,QAAQ,eAAe,KAAK;AAChF,QAAA,EAAE,qBAAqB,OAAO,OAAO,MAAM,GAAG,QAAQ,SAAS,KAAK;AAE1E,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;AAEpC,QAAI,CAAC,uBAAuB,cAAc,KAAK,uBAAuB,WAAW,GAAG;AAC5E,YAAA,gBAAgB,MAAM;AAE5B,YAAM,OAAO,GAAG,MAAM,GAAG,EAAE,WAAW;AAAA,QACpC,OAAO,EAAE,QAAQ,KAAK;AAAA,QACtB,MAAM,EAAE,QAAQ,cAAc;AAAA,MAAA,CAC/B;AAAA,IACH;AAAA,EACF;AACF;AAEA,MAAM,cAAc,OAAO,EAAE,iBAAiB,mBAA0B;AAChE,QAAA,EAAE,2BAA2B,OAAO,OAAO,MAAM,GAAG,QAAQ,eAAe,KAAK;AAChF,QAAA,EAAE,qBAAqB,OAAO,OAAO,MAAM,GAAG,QAAQ,SAAS,KAAK;AAE1E,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;AAGpC,QAAI,uBAAuB,cAAc,KAAK,CAAC,uBAAuB,WAAW,GAAG;AAC5E,YAAA,gBAAgB,MAAM;AAE5B,YAAM,QAAQ,IAAI;AAAA;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;"}
@@ -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;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/core",
3
- "version": "5.0.0-rc.22",
3
+ "version": "5.0.0-rc.24",
4
4
  "description": "Core of Strapi",
5
5
  "homepage": "https://strapi.io",
6
6
  "bugs": {
@@ -55,15 +55,15 @@
55
55
  "@koa/cors": "5.0.0",
56
56
  "@koa/router": "12.0.1",
57
57
  "@paralleldrive/cuid2": "2.2.2",
58
- "@strapi/admin": "5.0.0-rc.22",
59
- "@strapi/database": "5.0.0-rc.22",
60
- "@strapi/generators": "5.0.0-rc.22",
61
- "@strapi/logger": "5.0.0-rc.22",
58
+ "@strapi/admin": "5.0.0-rc.24",
59
+ "@strapi/database": "5.0.0-rc.24",
60
+ "@strapi/generators": "5.0.0-rc.24",
61
+ "@strapi/logger": "5.0.0-rc.24",
62
62
  "@strapi/pack-up": "5.0.0",
63
- "@strapi/permissions": "5.0.0-rc.22",
64
- "@strapi/types": "5.0.0-rc.22",
65
- "@strapi/typescript-utils": "5.0.0-rc.22",
66
- "@strapi/utils": "5.0.0-rc.22",
63
+ "@strapi/permissions": "5.0.0-rc.24",
64
+ "@strapi/types": "5.0.0-rc.24",
65
+ "@strapi/typescript-utils": "5.0.0-rc.24",
66
+ "@strapi/utils": "5.0.0-rc.24",
67
67
  "bcryptjs": "2.4.3",
68
68
  "boxen": "5.1.2",
69
69
  "chalk": "4.1.2",
@@ -126,13 +126,13 @@
126
126
  "@types/node": "18.19.24",
127
127
  "@types/node-schedule": "2.1.7",
128
128
  "@types/statuses": "2.0.1",
129
- "eslint-config-custom": "5.0.0-rc.22",
129
+ "eslint-config-custom": "5.0.0-rc.24",
130
130
  "supertest": "6.3.3",
131
- "tsconfig": "5.0.0-rc.22"
131
+ "tsconfig": "5.0.0-rc.24"
132
132
  },
133
133
  "engines": {
134
134
  "node": ">=18.0.0 <=20.x.x",
135
135
  "npm": ">=6.0.0"
136
136
  },
137
- "gitHead": "0f2bce1bebfdd4c40c8c559d145d78f3b6ed4cfc"
137
+ "gitHead": "860b3bae00b8dc271c7ab2c6a6a2e5ba258e479f"
138
138
  }