@strapi/core 5.0.0-rc.9 → 5.0.1
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.
- package/dist/core-api/service/collection-type.d.ts +2 -2
- package/dist/ee/index.d.ts.map +1 -1
- package/dist/ee/index.js +6 -1
- package/dist/ee/index.js.map +1 -1
- package/dist/ee/index.mjs +6 -1
- package/dist/ee/index.mjs.map +1 -1
- package/dist/factories.js.map +1 -1
- package/dist/factories.mjs.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.d.ts.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.js +5 -2
- package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.mjs +5 -2
- package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
- package/dist/loaders/plugins/index.d.ts.map +1 -1
- package/dist/loaders/plugins/index.js +28 -1
- package/dist/loaders/plugins/index.js.map +1 -1
- package/dist/loaders/plugins/index.mjs +9 -1
- package/dist/loaders/plugins/index.mjs.map +1 -1
- package/dist/middlewares/security.d.ts.map +1 -1
- package/dist/middlewares/security.js +1 -1
- package/dist/middlewares/security.js.map +1 -1
- package/dist/middlewares/security.mjs +1 -1
- package/dist/middlewares/security.mjs.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.d.ts +12 -9
- package/dist/migrations/database/5.0.0-discard-drafts.d.ts.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.js +55 -11
- package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.mjs +56 -12
- package/dist/migrations/database/5.0.0-discard-drafts.mjs.map +1 -1
- package/dist/migrations/draft-publish.d.ts +1 -1
- package/dist/migrations/draft-publish.d.ts.map +1 -1
- package/dist/migrations/draft-publish.js.map +1 -1
- package/dist/migrations/draft-publish.mjs.map +1 -1
- package/dist/migrations/i18n.d.ts +5 -0
- package/dist/migrations/i18n.d.ts.map +1 -0
- package/dist/migrations/i18n.js +54 -0
- package/dist/migrations/i18n.js.map +1 -0
- package/dist/migrations/i18n.mjs +54 -0
- package/dist/migrations/i18n.mjs.map +1 -0
- package/dist/migrations/index.d.ts +5 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +15 -0
- package/dist/migrations/index.js.map +1 -0
- package/dist/migrations/index.mjs +15 -0
- package/dist/migrations/index.mjs.map +1 -0
- package/dist/providers/admin.d.ts.map +1 -1
- package/dist/providers/admin.js.map +1 -1
- package/dist/providers/admin.mjs.map +1 -1
- package/dist/providers/registries.js +3 -3
- package/dist/providers/registries.js.map +1 -1
- package/dist/providers/registries.mjs +3 -3
- package/dist/providers/registries.mjs.map +1 -1
- package/dist/services/content-api/index.d.ts +6 -2
- package/dist/services/content-api/index.d.ts.map +1 -1
- package/dist/services/content-api/permissions/index.d.ts +6 -2
- package/dist/services/content-api/permissions/index.d.ts.map +1 -1
- package/dist/services/content-api/permissions/providers/action.d.ts +3 -1
- package/dist/services/content-api/permissions/providers/action.d.ts.map +1 -1
- package/dist/services/content-api/permissions/providers/condition.d.ts +3 -1
- package/dist/services/content-api/permissions/providers/condition.d.ts.map +1 -1
- package/dist/services/cron.d.ts +3 -3
- package/dist/services/cron.d.ts.map +1 -1
- package/dist/services/cron.js.map +1 -1
- package/dist/services/cron.mjs.map +1 -1
- package/dist/services/document-service/repository.d.ts.map +1 -1
- package/dist/services/document-service/repository.js +42 -6
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +43 -7
- package/dist/services/document-service/repository.mjs.map +1 -1
- package/dist/services/document-service/utils/populate.d.ts.map +1 -1
- package/dist/services/document-service/utils/populate.js +3 -1
- package/dist/services/document-service/utils/populate.js.map +1 -1
- package/dist/services/document-service/utils/populate.mjs +3 -1
- package/dist/services/document-service/utils/populate.mjs.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.d.ts +33 -0
- package/dist/services/document-service/utils/unidirectional-relations.d.ts.map +1 -0
- package/dist/services/document-service/utils/unidirectional-relations.js +57 -0
- package/dist/services/document-service/utils/unidirectional-relations.js.map +1 -0
- package/dist/services/document-service/utils/unidirectional-relations.mjs +57 -0
- package/dist/services/document-service/utils/unidirectional-relations.mjs.map +1 -0
- package/dist/services/entity-validator/index.d.ts.map +1 -1
- package/dist/services/entity-validator/index.js +6 -2
- package/dist/services/entity-validator/index.js.map +1 -1
- package/dist/services/entity-validator/index.mjs +6 -2
- package/dist/services/entity-validator/index.mjs.map +1 -1
- package/dist/services/entity-validator/validators.d.ts.map +1 -1
- package/dist/services/entity-validator/validators.js +18 -14
- package/dist/services/entity-validator/validators.js.map +1 -1
- package/dist/services/entity-validator/validators.mjs +18 -14
- package/dist/services/entity-validator/validators.mjs.map +1 -1
- package/dist/utils/transform-content-types-to-models.d.ts +2 -2
- package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
- package/dist/utils/transform-content-types-to-models.js +2 -1
- package/dist/utils/transform-content-types-to-models.js.map +1 -1
- package/dist/utils/transform-content-types-to-models.mjs +2 -1
- package/dist/utils/transform-content-types-to-models.mjs.map +1 -1
- package/package.json +16 -16
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"security.mjs","sources":["../../src/middlewares/security.ts"],"sourcesContent":["import { defaultsDeep, mergeWith } from 'lodash/fp';\nimport helmet, { KoaHelmet } from 'koa-helmet';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = NonNullable<Parameters<KoaHelmet>[0]>;\n\nconst defaults: Config = {\n crossOriginEmbedderPolicy: false,\n crossOriginOpenerPolicy: false,\n crossOriginResourcePolicy: false,\n originAgentCluster: false,\n contentSecurityPolicy: {\n useDefaults: true,\n directives: {\n 'connect-src': [\"'self'\", 'https:'],\n 'img-src': [\"'self'\", 'data:', 'blob:', 'https://market-assets.strapi.io'],\n 'media-src': [\"'self'\", 'data:', 'blob:'],\n upgradeInsecureRequests: null,\n },\n },\n xssFilter: false,\n hsts: {\n maxAge: 31536000,\n includeSubDomains: true,\n },\n frameguard: {\n action: 'sameorigin',\n },\n};\n\nconst mergeConfig = (existingConfig: Config, newConfig: Config) => {\n return mergeWith(\n (obj, src) => (Array.isArray(obj) && Array.isArray(src) ? obj.concat(src) : undefined),\n existingConfig,\n newConfig\n );\n};\n\nexport const security: Core.MiddlewareFactory<Config> =\n (config, { strapi }) =>\n (ctx, next) => {\n let helmetConfig: Config = defaultsDeep(defaults, config);\n\n const specialPaths = ['/documentation'];\n\n const directives: {\n 'script-src': string[];\n 'img-src': string[];\n 'manifest-src': string[];\n 'frame-src': string[];\n } = {\n 'script-src': [\"'self'\", \"'unsafe-inline'\", 'cdn.jsdelivr.net'],\n 'img-src': [\"'self'\", 'data:', 'cdn.jsdelivr.net', 'strapi.io'],\n 'manifest-src': [],\n 'frame-src': [],\n };\n\n // if apollo graphql playground is enabled, add exceptions for it\n if (strapi.plugin('graphql')?.service('utils').playground.isEnabled()) {\n const { config: gqlConfig } = strapi.plugin('graphql');\n specialPaths.push(gqlConfig('endpoint'));\n\n directives['script-src'].push(`https: 'unsafe-inline'`);\n directives['img-src'].push(`'apollo-server-landing-page.cdn.apollographql.com'`);\n directives['manifest-src'].push(`'self'`);\n directives['manifest-src'].push('apollo-server-landing-page.cdn.apollographql.com');\n directives['frame-src'].push(`'self'`);\n directives['frame-src'].push('sandbox.embed.apollographql.com');\n }\n\n // TODO: we shouldn't combine playground exceptions with documentation for all routes, we should first check the path and then return exceptions specific to that\n if (ctx.method === 'GET' && specialPaths.some((str) => ctx.path.startsWith(str))) {\n helmetConfig = mergeConfig(helmetConfig, {\n crossOriginEmbedderPolicy: false, // TODO: only use this for graphql playground\n contentSecurityPolicy: {\n directives,\n },\n });\n }\n\n /**\n * These are for vite's watch mode so it can accurately\n * connect to the HMR websocket & reconnect on failure\n * or when the server restarts.\n *\n * It only applies in development, and only on GET requests\n * that are part of the admin route.\n */\n if (\n ['development', 'test'].includes(process.env.NODE_ENV ?? '') &&\n ctx.method === 'GET' &&\n
|
1
|
+
{"version":3,"file":"security.mjs","sources":["../../src/middlewares/security.ts"],"sourcesContent":["import { defaultsDeep, mergeWith } from 'lodash/fp';\nimport helmet, { KoaHelmet } from 'koa-helmet';\n\nimport type { Core } from '@strapi/types';\n\nexport type Config = NonNullable<Parameters<KoaHelmet>[0]>;\n\nconst defaults: Config = {\n crossOriginEmbedderPolicy: false,\n crossOriginOpenerPolicy: false,\n crossOriginResourcePolicy: false,\n originAgentCluster: false,\n contentSecurityPolicy: {\n useDefaults: true,\n directives: {\n 'connect-src': [\"'self'\", 'https:'],\n 'img-src': [\"'self'\", 'data:', 'blob:', 'https://market-assets.strapi.io'],\n 'media-src': [\"'self'\", 'data:', 'blob:'],\n upgradeInsecureRequests: null,\n },\n },\n xssFilter: false,\n hsts: {\n maxAge: 31536000,\n includeSubDomains: true,\n },\n frameguard: {\n action: 'sameorigin',\n },\n};\n\nconst mergeConfig = (existingConfig: Config, newConfig: Config) => {\n return mergeWith(\n (obj, src) => (Array.isArray(obj) && Array.isArray(src) ? obj.concat(src) : undefined),\n existingConfig,\n newConfig\n );\n};\n\nexport const security: Core.MiddlewareFactory<Config> =\n (config, { strapi }) =>\n (ctx, next) => {\n let helmetConfig: Config = defaultsDeep(defaults, config);\n\n const specialPaths = ['/documentation'];\n\n const directives: {\n 'script-src': string[];\n 'img-src': string[];\n 'manifest-src': string[];\n 'frame-src': string[];\n } = {\n 'script-src': [\"'self'\", \"'unsafe-inline'\", 'cdn.jsdelivr.net'],\n 'img-src': [\"'self'\", 'data:', 'cdn.jsdelivr.net', 'strapi.io'],\n 'manifest-src': [],\n 'frame-src': [],\n };\n\n // if apollo graphql playground is enabled, add exceptions for it\n if (strapi.plugin('graphql')?.service('utils').playground.isEnabled()) {\n const { config: gqlConfig } = strapi.plugin('graphql');\n specialPaths.push(gqlConfig('endpoint'));\n\n directives['script-src'].push(`https: 'unsafe-inline'`);\n directives['img-src'].push(`'apollo-server-landing-page.cdn.apollographql.com'`);\n directives['manifest-src'].push(`'self'`);\n directives['manifest-src'].push('apollo-server-landing-page.cdn.apollographql.com');\n directives['frame-src'].push(`'self'`);\n directives['frame-src'].push('sandbox.embed.apollographql.com');\n }\n\n // TODO: we shouldn't combine playground exceptions with documentation for all routes, we should first check the path and then return exceptions specific to that\n if (ctx.method === 'GET' && specialPaths.some((str) => ctx.path.startsWith(str))) {\n helmetConfig = mergeConfig(helmetConfig, {\n crossOriginEmbedderPolicy: false, // TODO: only use this for graphql playground\n contentSecurityPolicy: {\n directives,\n },\n });\n }\n\n /**\n * These are for vite's watch mode so it can accurately\n * connect to the HMR websocket & reconnect on failure\n * or when the server restarts.\n *\n * It only applies in development, and only on GET requests\n * that are part of the admin route.\n */\n\n if (\n ['development', 'test'].includes(process.env.NODE_ENV ?? '') &&\n ctx.method === 'GET' &&\n ctx.path.startsWith(strapi.config.get('admin.path'))\n ) {\n helmetConfig = mergeConfig(helmetConfig, {\n contentSecurityPolicy: {\n directives: {\n 'script-src': [\"'self'\", \"'unsafe-inline'\"],\n 'connect-src': [\"'self'\", 'http:', 'https:', 'ws:'],\n },\n },\n });\n }\n\n return helmet(helmetConfig)(ctx, next);\n };\n"],"names":[],"mappings":";;AAOA,MAAM,WAAmB;AAAA,EACvB,2BAA2B;AAAA,EAC3B,yBAAyB;AAAA,EACzB,2BAA2B;AAAA,EAC3B,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,IACrB,aAAa;AAAA,IACb,YAAY;AAAA,MACV,eAAe,CAAC,UAAU,QAAQ;AAAA,MAClC,WAAW,CAAC,UAAU,SAAS,SAAS,iCAAiC;AAAA,MACzE,aAAa,CAAC,UAAU,SAAS,OAAO;AAAA,MACxC,yBAAyB;AAAA,IAC3B;AAAA,EACF;AAAA,EACA,WAAW;AAAA,EACX,MAAM;AAAA,IACJ,QAAQ;AAAA,IACR,mBAAmB;AAAA,EACrB;AAAA,EACA,YAAY;AAAA,IACV,QAAQ;AAAA,EACV;AACF;AAEA,MAAM,cAAc,CAAC,gBA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AY,CAAC,GACnD;AACA,mBAAe,YAAY,cAAc;AAAA,MACvC,uBAAuB;AAAA,QACrB,YAAY;AAAA,UACV,cAAc,CAAC,UAAU,iBAAiB;AAAA,UAC1C,eAAe,CAAC,UAAU,SAAS,UAAU,KAAK;AAAA,QACpD;AAAA,MACF;AAAA,IAAA,CACD;AAAA,EACH;AAEA,SAAO,OAAO,YAAY,EAAE,KAAK,IAAI;AACvC;"}
|
@@ -1,3 +1,15 @@
|
|
1
|
+
/**
|
2
|
+
* This migration is responsible for creating the draft counterpart for all the entries that were in a published state.
|
3
|
+
*
|
4
|
+
* In v4, entries could either be in a draft or published state, but not both at the same time.
|
5
|
+
* In v5, we introduced the concept of document, and an entry can be in a draft or published state.
|
6
|
+
*
|
7
|
+
* This means the migration needs to create the draft counterpart if an entry was published.
|
8
|
+
*
|
9
|
+
* This migration performs the following steps:
|
10
|
+
* 1. Creates draft entries for all published entries, without it's components, dynamic zones or relations.
|
11
|
+
* 2. Using the document service, discard those same drafts to copy its relations.
|
12
|
+
*/
|
1
13
|
import type { Database, Migration } from '@strapi/database';
|
2
14
|
type DocumentVersion = {
|
3
15
|
documentId: string;
|
@@ -16,15 +28,6 @@ export declare function getBatchToDiscard({ db, trx, uid, batchSize, }: {
|
|
16
28
|
uid: string;
|
17
29
|
batchSize?: number;
|
18
30
|
}): AsyncGenerator<DocumentVersion[], void, unknown>;
|
19
|
-
/**
|
20
|
-
* On V4 there was no concept of document, and an entry could be in a draft or published state.
|
21
|
-
* But not both at the same time.
|
22
|
-
*
|
23
|
-
* On V5 we introduced the concept of document, and an entry can be in a draft or published state,
|
24
|
-
* with the requirement that a document must always have a draft.
|
25
|
-
*
|
26
|
-
* This migration creates the document draft counterpart for all the entries that were in a published state.
|
27
|
-
*/
|
28
31
|
export declare const discardDocumentDrafts: Migration;
|
29
32
|
export {};
|
30
33
|
//# sourceMappingURL=5.0.0-discard-drafts.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"5.0.0-discard-drafts.d.ts","sourceRoot":"","sources":["../../../src/migrations/database/5.0.0-discard-drafts.ts"],"names":[],"mappings":"
|
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"}
|
@@ -1,6 +1,50 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
3
|
const strapiUtils = require("@strapi/utils");
|
4
|
+
const hasDraftAndPublish = async (trx, meta) => {
|
5
|
+
const hasTable = await trx.schema.hasTable(meta.tableName);
|
6
|
+
if (!hasTable) {
|
7
|
+
return false;
|
8
|
+
}
|
9
|
+
const uid = meta.uid;
|
10
|
+
const model = strapi.getModel(uid);
|
11
|
+
const hasDP = strapiUtils.contentTypes.hasDraftAndPublish(model);
|
12
|
+
if (!hasDP) {
|
13
|
+
return false;
|
14
|
+
}
|
15
|
+
return true;
|
16
|
+
};
|
17
|
+
async function copyPublishedEntriesToDraft({
|
18
|
+
db,
|
19
|
+
trx,
|
20
|
+
uid
|
21
|
+
}) {
|
22
|
+
const meta = db.metadata.get(uid);
|
23
|
+
const scalarAttributes = Object.values(meta.attributes).reduce((acc, attribute) => {
|
24
|
+
if (["id"].includes(attribute.columnName)) {
|
25
|
+
return acc;
|
26
|
+
}
|
27
|
+
if (strapiUtils.contentTypes.isScalarAttribute(attribute)) {
|
28
|
+
acc.push(attribute.columnName);
|
29
|
+
}
|
30
|
+
return acc;
|
31
|
+
}, []);
|
32
|
+
await trx.into(
|
33
|
+
trx.raw(`?? (${scalarAttributes.map(() => `??`).join(", ")})`, [
|
34
|
+
meta.tableName,
|
35
|
+
...scalarAttributes
|
36
|
+
])
|
37
|
+
).insert((subQb) => {
|
38
|
+
subQb.select(
|
39
|
+
...scalarAttributes.map((att) => {
|
40
|
+
if (att === "published_at") {
|
41
|
+
return trx.raw("NULL as ??", "published_at");
|
42
|
+
}
|
43
|
+
return att;
|
44
|
+
})
|
45
|
+
).from(meta.tableName).whereNotNull("published_at");
|
46
|
+
});
|
47
|
+
}
|
4
48
|
async function* getBatchToDiscard({
|
5
49
|
db,
|
6
50
|
trx,
|
@@ -19,19 +63,19 @@ async function* getBatchToDiscard({
|
|
19
63
|
}
|
20
64
|
}
|
21
65
|
const migrateUp = async (trx, db) => {
|
66
|
+
const dpModels = [];
|
22
67
|
for (const meta of db.metadata.values()) {
|
23
|
-
const
|
24
|
-
if (
|
25
|
-
|
68
|
+
const hasDP = await hasDraftAndPublish(trx, meta);
|
69
|
+
if (hasDP) {
|
70
|
+
dpModels.push(meta);
|
26
71
|
}
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
}
|
33
|
-
|
34
|
-
for await (const batch of getBatchToDiscard({ db, trx, uid: meta.uid })) {
|
72
|
+
}
|
73
|
+
for (const model of dpModels) {
|
74
|
+
await copyPublishedEntriesToDraft({ db, trx, uid: model.uid });
|
75
|
+
}
|
76
|
+
for (const model of dpModels) {
|
77
|
+
const discardDraft = async (entry) => strapi.documents(model.uid).discardDraft({ documentId: entry.documentId, locale: entry.locale });
|
78
|
+
for await (const batch of getBatchToDiscard({ db, trx, uid: model.uid })) {
|
35
79
|
await strapiUtils.async.map(batch, discardDraft, { concurrency: 10 });
|
36
80
|
}
|
37
81
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"5.0.0-discard-drafts.js","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
|
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":["content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|
+
import { async, contentTypes } from "@strapi/utils";
|
2
|
+
const hasDraftAndPublish = async (trx, meta) => {
|
3
|
+
const hasTable = await trx.schema.hasTable(meta.tableName);
|
4
|
+
if (!hasTable) {
|
5
|
+
return false;
|
6
|
+
}
|
7
|
+
const uid = meta.uid;
|
8
|
+
const model = strapi.getModel(uid);
|
9
|
+
const hasDP = contentTypes.hasDraftAndPublish(model);
|
10
|
+
if (!hasDP) {
|
11
|
+
return false;
|
12
|
+
}
|
13
|
+
return true;
|
14
|
+
};
|
15
|
+
async function copyPublishedEntriesToDraft({
|
16
|
+
db,
|
17
|
+
trx,
|
18
|
+
uid
|
19
|
+
}) {
|
20
|
+
const meta = db.metadata.get(uid);
|
21
|
+
const scalarAttributes = Object.values(meta.attributes).reduce((acc, attribute) => {
|
22
|
+
if (["id"].includes(attribute.columnName)) {
|
23
|
+
return acc;
|
24
|
+
}
|
25
|
+
if (contentTypes.isScalarAttribute(attribute)) {
|
26
|
+
acc.push(attribute.columnName);
|
27
|
+
}
|
28
|
+
return acc;
|
29
|
+
}, []);
|
30
|
+
await trx.into(
|
31
|
+
trx.raw(`?? (${scalarAttributes.map(() => `??`).join(", ")})`, [
|
32
|
+
meta.tableName,
|
33
|
+
...scalarAttributes
|
34
|
+
])
|
35
|
+
).insert((subQb) => {
|
36
|
+
subQb.select(
|
37
|
+
...scalarAttributes.map((att) => {
|
38
|
+
if (att === "published_at") {
|
39
|
+
return trx.raw("NULL as ??", "published_at");
|
40
|
+
}
|
41
|
+
return att;
|
42
|
+
})
|
43
|
+
).from(meta.tableName).whereNotNull("published_at");
|
44
|
+
});
|
45
|
+
}
|
2
46
|
async function* getBatchToDiscard({
|
3
47
|
db,
|
4
48
|
trx,
|
@@ -17,19 +61,19 @@ async function* getBatchToDiscard({
|
|
17
61
|
}
|
18
62
|
}
|
19
63
|
const migrateUp = async (trx, db) => {
|
64
|
+
const dpModels = [];
|
20
65
|
for (const meta of db.metadata.values()) {
|
21
|
-
const
|
22
|
-
if (
|
23
|
-
|
66
|
+
const hasDP = await hasDraftAndPublish(trx, meta);
|
67
|
+
if (hasDP) {
|
68
|
+
dpModels.push(meta);
|
24
69
|
}
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
}
|
31
|
-
|
32
|
-
for await (const batch of getBatchToDiscard({ db, trx, uid: meta.uid })) {
|
70
|
+
}
|
71
|
+
for (const model of dpModels) {
|
72
|
+
await copyPublishedEntriesToDraft({ db, trx, uid: model.uid });
|
73
|
+
}
|
74
|
+
for (const model of dpModels) {
|
75
|
+
const discardDraft = async (entry) => strapi.documents(model.uid).discardDraft({ documentId: entry.documentId, locale: entry.locale });
|
76
|
+
for await (const batch of getBatchToDiscard({ db, trx, uid: model.uid })) {
|
33
77
|
await async.map(batch, discardDraft, { concurrency: 10 });
|
34
78
|
}
|
35
79
|
}
|
@@ -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
|
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":";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;AAAA,IACC,IAAI,IAAI,OAAO,iBAAiB,IAAI,MAAM,IAAI,EAAE,KAAK,IAAI,CAAC,KAAK;AAAA,MAC7D,KAAK;AAAA,MACL,GAAG;AAAA,IAAA,CACJ;AAAA,EAAA,EAEF,OAAO,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AAG;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 +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,
|
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\
|
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\
|
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,OAA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E,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,
|
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;
|
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;
|
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
|
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(
|
30
|
-
strapi.hook("strapi::content-types.afterSync").register(
|
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
|
});
|