@strapi/core 5.48.1 → 5.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Strapi.js +9 -5
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +0 -1
- package/dist/Strapi.mjs.map +1 -1
- package/dist/ai.d.ts +2 -0
- package/dist/ai.d.ts.map +1 -0
- package/dist/ai.js +8 -0
- package/dist/ai.js.map +1 -0
- package/dist/ai.mjs +3 -0
- package/dist/ai.mjs.map +1 -0
- package/dist/configuration/config-loader.js +11 -6
- package/dist/configuration/config-loader.js.map +1 -1
- package/dist/configuration/index.js +22 -15
- package/dist/configuration/index.js.map +1 -1
- package/dist/configuration/urls.js +11 -7
- package/dist/configuration/urls.js.map +1 -1
- package/dist/core-api/routes/index.js +3 -2
- package/dist/core-api/routes/index.js.map +1 -1
- package/dist/core-api/routes/validation/common.js +3 -2
- package/dist/core-api/routes/validation/common.js.map +1 -1
- package/dist/core-api/routes/validation/content-type.js +3 -2
- package/dist/core-api/routes/validation/content-type.js.map +1 -1
- package/dist/core-api/routes/validation/mappers.js +3 -2
- package/dist/core-api/routes/validation/mappers.js.map +1 -1
- package/dist/core-api/routes/validation/utils.js +3 -2
- package/dist/core-api/routes/validation/utils.js.map +1 -1
- package/dist/domain/content-type/index.js +9 -5
- package/dist/domain/content-type/index.js.map +1 -1
- package/dist/domain/content-type/validator.js +6 -2
- package/dist/domain/content-type/validator.js.map +1 -1
- package/dist/domain/module/index.js +6 -2
- package/dist/domain/module/index.js.map +1 -1
- package/dist/ee/license.js +8 -3
- package/dist/ee/license.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -1
- package/dist/loaders/admin.js +5 -1
- package/dist/loaders/admin.js.map +1 -1
- package/dist/loaders/apis.js +16 -11
- package/dist/loaders/apis.js.map +1 -1
- package/dist/loaders/components.js +6 -2
- package/dist/loaders/components.js.map +1 -1
- package/dist/loaders/middlewares.js +6 -2
- package/dist/loaders/middlewares.js.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.js +5 -1
- package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
- package/dist/loaders/plugins/get-user-plugins-config.js +6 -2
- package/dist/loaders/plugins/get-user-plugins-config.js.map +1 -1
- package/dist/loaders/plugins/index.js +8 -4
- package/dist/loaders/plugins/index.js.map +1 -1
- package/dist/loaders/policies.js +6 -2
- package/dist/loaders/policies.js.map +1 -1
- package/dist/mcp.d.ts +4 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +12 -0
- package/dist/mcp.js.map +1 -0
- package/dist/mcp.mjs +4 -0
- package/dist/mcp.mjs.map +1 -0
- package/dist/middlewares/body.js +8 -3
- package/dist/middlewares/body.js.map +1 -1
- package/dist/middlewares/compression.js +5 -1
- package/dist/middlewares/compression.js.map +1 -1
- package/dist/middlewares/cors.js +5 -1
- package/dist/middlewares/cors.js.map +1 -1
- package/dist/middlewares/favicon.js +5 -1
- package/dist/middlewares/favicon.js.map +1 -1
- package/dist/middlewares/ip.js +5 -1
- package/dist/middlewares/ip.js.map +1 -1
- package/dist/middlewares/public.js +5 -1
- package/dist/middlewares/public.js.map +1 -1
- package/dist/middlewares/query.js +6 -2
- package/dist/middlewares/query.js.map +1 -1
- package/dist/middlewares/security.js +5 -1
- package/dist/middlewares/security.js.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.js +5 -1
- package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
- package/dist/migrations/first-published-at.js +5 -1
- package/dist/migrations/first-published-at.js.map +1 -1
- package/dist/package.json.js +15 -15
- package/dist/package.json.mjs +15 -15
- package/dist/registries/sanitizers.js +7 -3
- package/dist/registries/sanitizers.js.map +1 -1
- package/dist/registries/validators.js +7 -3
- package/dist/registries/validators.js.map +1 -1
- package/dist/services/auth/index.js +7 -3
- package/dist/services/auth/index.js.map +1 -1
- package/dist/services/content-api/index.js +10 -6
- package/dist/services/content-api/index.js.map +1 -1
- package/dist/services/content-api/permissions/engine.js +5 -1
- package/dist/services/content-api/permissions/engine.js.map +1 -1
- package/dist/services/content-api/permissions/index.js +10 -6
- package/dist/services/content-api/permissions/index.js.map +1 -1
- package/dist/services/document-service/attributes/transforms.js +5 -1
- package/dist/services/document-service/attributes/transforms.js.map +1 -1
- package/dist/services/document-service/components.d.ts.map +1 -1
- package/dist/services/document-service/components.js +14 -10
- package/dist/services/document-service/components.js.map +1 -1
- package/dist/services/document-service/components.mjs.map +1 -1
- package/dist/services/document-service/draft-and-publish.js +1 -1
- package/dist/services/document-service/draft-and-publish.js.map +1 -1
- package/dist/services/document-service/draft-and-publish.mjs +1 -1
- package/dist/services/document-service/draft-and-publish.mjs.map +1 -1
- package/dist/services/document-service/entries.d.ts.map +1 -1
- package/dist/services/document-service/entries.js +6 -2
- package/dist/services/document-service/entries.js.map +1 -1
- package/dist/services/document-service/entries.mjs +7 -3
- package/dist/services/document-service/entries.mjs.map +1 -1
- package/dist/services/document-service/internationalization.js.map +1 -1
- package/dist/services/document-service/internationalization.mjs.map +1 -1
- package/dist/services/document-service/transform/data.d.ts +2 -0
- package/dist/services/document-service/transform/data.d.ts.map +1 -1
- package/dist/services/document-service/transform/data.js +7 -1
- package/dist/services/document-service/transform/data.js.map +1 -1
- package/dist/services/document-service/transform/data.mjs +7 -2
- package/dist/services/document-service/transform/data.mjs.map +1 -1
- package/dist/services/document-service/utils/populate.d.ts +1 -1
- package/dist/services/document-service/utils/populate.d.ts.map +1 -1
- package/dist/services/document-service/utils/populate.js.map +1 -1
- package/dist/services/document-service/utils/populate.mjs.map +1 -1
- package/dist/services/entity-service/index.js +9 -4
- package/dist/services/entity-service/index.js.map +1 -1
- package/dist/services/entity-validator/index.d.ts.map +1 -1
- package/dist/services/entity-validator/index.js +9 -4
- package/dist/services/entity-validator/index.js.map +1 -1
- package/dist/services/entity-validator/index.mjs.map +1 -1
- package/dist/services/entity-validator/validators.js +10 -6
- package/dist/services/entity-validator/validators.js.map +1 -1
- package/dist/services/errors.js +7 -3
- package/dist/services/errors.js.map +1 -1
- package/dist/services/fs.js +10 -5
- package/dist/services/fs.js.map +1 -1
- package/dist/services/mcp/prompt-registry.d.ts +31 -3
- package/dist/services/mcp/prompt-registry.d.ts.map +1 -1
- package/dist/services/mcp/prompt-registry.js +31 -0
- package/dist/services/mcp/prompt-registry.js.map +1 -1
- package/dist/services/mcp/prompt-registry.mjs +31 -1
- package/dist/services/mcp/prompt-registry.mjs.map +1 -1
- package/dist/services/mcp/resource-registry.d.ts +31 -1
- package/dist/services/mcp/resource-registry.d.ts.map +1 -1
- package/dist/services/mcp/resource-registry.js +31 -0
- package/dist/services/mcp/resource-registry.js.map +1 -1
- package/dist/services/mcp/resource-registry.mjs +31 -1
- package/dist/services/mcp/resource-registry.mjs.map +1 -1
- package/dist/services/mcp/tool-registry.d.ts +36 -9
- package/dist/services/mcp/tool-registry.d.ts.map +1 -1
- package/dist/services/mcp/tool-registry.js +35 -3
- package/dist/services/mcp/tool-registry.js.map +1 -1
- package/dist/services/mcp/tool-registry.mjs +35 -3
- package/dist/services/mcp/tool-registry.mjs.map +1 -1
- package/dist/services/mcp/tools/log.d.ts +15 -85
- package/dist/services/mcp/tools/log.d.ts.map +1 -1
- package/dist/services/metrics/admin-user-hash.js +5 -1
- package/dist/services/metrics/admin-user-hash.js.map +1 -1
- package/dist/services/metrics/is-truthy.js +5 -1
- package/dist/services/metrics/is-truthy.js.map +1 -1
- package/dist/services/metrics/sender.js +17 -9
- package/dist/services/metrics/sender.js.map +1 -1
- package/dist/services/server/api.js +5 -1
- package/dist/services/server/api.js.map +1 -1
- package/dist/services/server/compose-endpoint.js +5 -1
- package/dist/services/server/compose-endpoint.js.map +1 -1
- package/dist/services/server/http-server.js +5 -1
- package/dist/services/server/http-server.js.map +1 -1
- package/dist/services/server/index.js +5 -1
- package/dist/services/server/index.js.map +1 -1
- package/dist/services/server/koa.js +12 -5
- package/dist/services/server/koa.js.map +1 -1
- package/dist/services/server/middleware.js +5 -1
- package/dist/services/server/middleware.js.map +1 -1
- package/dist/services/server/openapi.js +11 -6
- package/dist/services/server/openapi.js.map +1 -1
- package/dist/services/server/register-routes.js +8 -4
- package/dist/services/server/register-routes.js.map +1 -1
- package/dist/services/server/routing.js +5 -1
- package/dist/services/server/routing.js.map +1 -1
- package/dist/services/session-manager.js +14 -9
- package/dist/services/session-manager.js.map +1 -1
- package/dist/services/webhook-runner.js +7 -2
- package/dist/services/webhook-runner.js.map +1 -1
- package/dist/services/worker-queue.js +5 -1
- package/dist/services/worker-queue.js.map +1 -1
- package/dist/utils/filepath-to-prop-path.js +13 -8
- package/dist/utils/filepath-to-prop-path.js.map +1 -1
- package/dist/utils/load-config-file.js +7 -2
- package/dist/utils/load-config-file.js.map +1 -1
- package/dist/utils/load-files.js +12 -6
- package/dist/utils/load-files.js.map +1 -1
- package/dist/utils/open-browser.js +5 -1
- package/dist/utils/open-browser.js.map +1 -1
- package/dist/utils/resolve-working-dirs.js +6 -2
- package/dist/utils/resolve-working-dirs.js.map +1 -1
- package/dist/utils/startup-logger.js +27 -21
- package/dist/utils/startup-logger.js.map +1 -1
- package/dist/utils/transform-content-types-to-models.js +10 -5
- package/dist/utils/transform-content-types-to-models.js.map +1 -1
- package/dist/utils/update-notifier/index.d.ts.map +1 -1
- package/dist/utils/update-notifier/index.js +21 -8
- package/dist/utils/update-notifier/index.js.map +1 -1
- package/dist/utils/update-notifier/index.mjs +6 -1
- package/dist/utils/update-notifier/index.mjs.map +1 -1
- package/package.json +15 -15
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
var path = require('node:path');
|
|
4
4
|
|
|
5
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
|
+
|
|
7
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
8
|
+
|
|
5
9
|
/**
|
|
6
10
|
* Resolve the working directories based on the instance options.
|
|
7
11
|
*
|
|
@@ -14,8 +18,8 @@ var path = require('node:path');
|
|
|
14
18
|
* - If `distDir` is `undefined`, it'll be set to `appDir`
|
|
15
19
|
*/ const resolveWorkingDirectories = (opts)=>{
|
|
16
20
|
const cwd = process.cwd();
|
|
17
|
-
const appDir = opts.appDir ?
|
|
18
|
-
const distDir = opts.distDir ?
|
|
21
|
+
const appDir = opts.appDir ? path__default.default.resolve(cwd, opts.appDir) : cwd;
|
|
22
|
+
const distDir = opts.distDir ? path__default.default.resolve(cwd, opts.distDir) : appDir;
|
|
19
23
|
return {
|
|
20
24
|
appDir,
|
|
21
25
|
distDir
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-working-dirs.js","sources":["../../src/utils/resolve-working-dirs.ts"],"sourcesContent":["import path from 'node:path';\n\n/**\n * Resolve the working directories based on the instance options.\n *\n * Behavior:\n * - `appDir` is the directory where Strapi will write every file (schemas, generated APIs, controllers or services)\n * - `distDir` is the directory where Strapi will read configurations, schemas and any compiled code\n *\n * Default values:\n * - If `appDir` is `undefined`, it'll be set to `process.cwd()`\n * - If `distDir` is `undefined`, it'll be set to `appDir`\n */\nexport const resolveWorkingDirectories = (opts: { appDir?: string; distDir?: string }) => {\n const cwd = process.cwd();\n\n const appDir = opts.appDir ? path.resolve(cwd, opts.appDir) : cwd;\n const distDir = opts.distDir ? path.resolve(cwd, opts.distDir) : appDir;\n\n return { appDir, distDir };\n};\n"],"names":["resolveWorkingDirectories","opts","cwd","process","appDir","path","resolve","distDir"],"mappings":"
|
|
1
|
+
{"version":3,"file":"resolve-working-dirs.js","sources":["../../src/utils/resolve-working-dirs.ts"],"sourcesContent":["import path from 'node:path';\n\n/**\n * Resolve the working directories based on the instance options.\n *\n * Behavior:\n * - `appDir` is the directory where Strapi will write every file (schemas, generated APIs, controllers or services)\n * - `distDir` is the directory where Strapi will read configurations, schemas and any compiled code\n *\n * Default values:\n * - If `appDir` is `undefined`, it'll be set to `process.cwd()`\n * - If `distDir` is `undefined`, it'll be set to `appDir`\n */\nexport const resolveWorkingDirectories = (opts: { appDir?: string; distDir?: string }) => {\n const cwd = process.cwd();\n\n const appDir = opts.appDir ? path.resolve(cwd, opts.appDir) : cwd;\n const distDir = opts.distDir ? path.resolve(cwd, opts.distDir) : appDir;\n\n return { appDir, distDir };\n};\n"],"names":["resolveWorkingDirectories","opts","cwd","process","appDir","path","resolve","distDir"],"mappings":";;;;;;;;AAEA;;;;;;;;;;IAWO,MAAMA,yBAAAA,GAA4B,CAACC,IAAAA,GAAAA;IACxC,MAAMC,GAAAA,GAAMC,QAAQD,GAAG,EAAA;IAEvB,MAAME,MAAAA,GAASH,IAAAA,CAAKG,MAAM,GAAGC,qBAAAA,CAAKC,OAAO,CAACJ,GAAAA,EAAKD,IAAAA,CAAKG,MAAM,CAAA,GAAIF,GAAAA;IAC9D,MAAMK,OAAAA,GAAUN,IAAAA,CAAKM,OAAO,GAAGF,qBAAAA,CAAKC,OAAO,CAACJ,GAAAA,EAAKD,IAAAA,CAAKM,OAAO,CAAA,GAAIH,MAAAA;IAEjE,OAAO;AAAEA,QAAAA,MAAAA;AAAQG,QAAAA;AAAQ,KAAA;AAC3B;;;;"}
|
|
@@ -4,6 +4,12 @@ var chalk = require('chalk');
|
|
|
4
4
|
var CLITable = require('cli-table3');
|
|
5
5
|
var fp = require('lodash/fp');
|
|
6
6
|
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var chalk__default = /*#__PURE__*/_interopDefault(chalk);
|
|
10
|
+
var CLITable__default = /*#__PURE__*/_interopDefault(CLITable);
|
|
11
|
+
var fp__default = /*#__PURE__*/_interopDefault(fp);
|
|
12
|
+
|
|
7
13
|
const ROUNDED_CHARS = {
|
|
8
14
|
top: '─',
|
|
9
15
|
'top-mid': '┬',
|
|
@@ -26,9 +32,9 @@ const createStartupLogger = (app)=>{
|
|
|
26
32
|
logStats () {
|
|
27
33
|
const columns = Math.min(process.stderr.columns, 80) - 2;
|
|
28
34
|
console.log();
|
|
29
|
-
console.log(
|
|
35
|
+
console.log(chalk__default.default.black.bgWhite(fp__default.default.padEnd(columns, ' Project information')));
|
|
30
36
|
console.log();
|
|
31
|
-
const infoTable = new
|
|
37
|
+
const infoTable = new CLITable__default.default({
|
|
32
38
|
colWidths: [
|
|
33
39
|
20,
|
|
34
40
|
50
|
|
@@ -37,39 +43,39 @@ const createStartupLogger = (app)=>{
|
|
|
37
43
|
});
|
|
38
44
|
const dbInfo = app.db?.getInfo();
|
|
39
45
|
infoTable.push([
|
|
40
|
-
|
|
46
|
+
chalk__default.default.blue('Time'),
|
|
41
47
|
`${new Date()}`
|
|
42
48
|
], [
|
|
43
|
-
|
|
49
|
+
chalk__default.default.blue('Launched in'),
|
|
44
50
|
`${Date.now() - app.config.launchedAt} ms`
|
|
45
51
|
], [
|
|
46
|
-
|
|
52
|
+
chalk__default.default.blue('Environment'),
|
|
47
53
|
app.config.environment
|
|
48
54
|
], [
|
|
49
|
-
|
|
55
|
+
chalk__default.default.blue('Process PID'),
|
|
50
56
|
process.pid
|
|
51
57
|
], [
|
|
52
|
-
|
|
58
|
+
chalk__default.default.blue('Version'),
|
|
53
59
|
`${app.config.info.strapi} (node ${process.version})`
|
|
54
60
|
], [
|
|
55
|
-
|
|
61
|
+
chalk__default.default.blue('Edition'),
|
|
56
62
|
app.EE ? 'Enterprise' : 'Community'
|
|
57
63
|
], [
|
|
58
|
-
|
|
64
|
+
chalk__default.default.blue('Database'),
|
|
59
65
|
dbInfo?.client
|
|
60
66
|
], [
|
|
61
|
-
|
|
67
|
+
chalk__default.default.blue('Database name'),
|
|
62
68
|
dbInfo?.displayName
|
|
63
69
|
]);
|
|
64
70
|
if (dbInfo?.schema) {
|
|
65
71
|
infoTable.push([
|
|
66
|
-
|
|
72
|
+
chalk__default.default.blue('Database schema'),
|
|
67
73
|
dbInfo.schema
|
|
68
74
|
]);
|
|
69
75
|
}
|
|
70
76
|
console.log(infoTable.toString());
|
|
71
77
|
console.log();
|
|
72
|
-
console.log(
|
|
78
|
+
console.log(chalk__default.default.black.bgWhite(fp__default.default.padEnd(columns, ' Actions available')));
|
|
73
79
|
console.log();
|
|
74
80
|
},
|
|
75
81
|
logFirstStartupMessage () {
|
|
@@ -77,13 +83,13 @@ const createStartupLogger = (app)=>{
|
|
|
77
83
|
return;
|
|
78
84
|
}
|
|
79
85
|
this.logStats();
|
|
80
|
-
console.log(
|
|
81
|
-
console.log(
|
|
86
|
+
console.log(chalk__default.default.bold('One more thing...'));
|
|
87
|
+
console.log(chalk__default.default.grey('Create your first administrator 💻 by going to the administration panel at:'));
|
|
82
88
|
console.log();
|
|
83
|
-
const addressTable = new
|
|
89
|
+
const addressTable = new CLITable__default.default();
|
|
84
90
|
const adminUrl = strapi.config.get('admin.absoluteUrl');
|
|
85
91
|
addressTable.push([
|
|
86
|
-
|
|
92
|
+
chalk__default.default.bold(adminUrl)
|
|
87
93
|
]);
|
|
88
94
|
console.log(`${addressTable.toString()}`);
|
|
89
95
|
console.log();
|
|
@@ -93,16 +99,16 @@ const createStartupLogger = (app)=>{
|
|
|
93
99
|
return;
|
|
94
100
|
}
|
|
95
101
|
this.logStats();
|
|
96
|
-
console.log(
|
|
102
|
+
console.log(chalk__default.default.bold('Welcome back!'));
|
|
97
103
|
if (app.config.get('admin.serveAdminPanel') === true) {
|
|
98
|
-
console.log(
|
|
104
|
+
console.log(chalk__default.default.grey('To manage your project 🚀, go to the administration panel at:'));
|
|
99
105
|
const adminUrl = strapi.config.get('admin.absoluteUrl');
|
|
100
|
-
console.log(
|
|
106
|
+
console.log(chalk__default.default.bold(adminUrl));
|
|
101
107
|
console.log();
|
|
102
108
|
}
|
|
103
|
-
console.log(
|
|
109
|
+
console.log(chalk__default.default.grey('To access the server ⚡️, go to:'));
|
|
104
110
|
const serverUrl = strapi.config.get('server.absoluteUrl');
|
|
105
|
-
console.log(
|
|
111
|
+
console.log(chalk__default.default.bold(serverUrl));
|
|
106
112
|
console.log();
|
|
107
113
|
},
|
|
108
114
|
logStartupMessage ({ isInitialized }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"startup-logger.js","sources":["../../src/utils/startup-logger.ts"],"sourcesContent":["import chalk from 'chalk';\nimport CLITable from 'cli-table3';\nimport _ from 'lodash/fp';\n\nimport type { Core } from '@strapi/types';\n\nconst ROUNDED_CHARS = {\n top: '─',\n 'top-mid': '┬',\n 'top-left': '╭',\n 'top-right': '╮',\n bottom: '─',\n 'bottom-mid': '┴',\n 'bottom-left': '╰',\n 'bottom-right': '╯',\n left: '│',\n right: '│',\n middle: '│',\n mid: '',\n 'left-mid': '',\n 'mid-mid': '',\n 'right-mid': '',\n};\n\nexport const createStartupLogger = (app: Core.Strapi) => {\n return {\n logStats() {\n const columns = Math.min(process.stderr.columns, 80) - 2;\n console.log();\n console.log(chalk.black.bgWhite(_.padEnd(columns, ' Project information')));\n console.log();\n\n const infoTable = new CLITable({\n colWidths: [20, 50],\n chars: ROUNDED_CHARS,\n });\n\n const dbInfo = app.db?.getInfo();\n\n infoTable.push(\n [chalk.blue('Time'), `${new Date()}`],\n [chalk.blue('Launched in'), `${Date.now() - app.config.launchedAt} ms`],\n [chalk.blue('Environment'), app.config.environment],\n [chalk.blue('Process PID'), process.pid],\n [chalk.blue('Version'), `${app.config.info.strapi} (node ${process.version})`],\n [chalk.blue('Edition'), app.EE ? 'Enterprise' : 'Community'],\n [chalk.blue('Database'), dbInfo?.client],\n [chalk.blue('Database name'), dbInfo?.displayName]\n );\n\n if (dbInfo?.schema) {\n infoTable.push([chalk.blue('Database schema'), dbInfo.schema]);\n }\n\n console.log(infoTable.toString());\n console.log();\n console.log(chalk.black.bgWhite(_.padEnd(columns, ' Actions available')));\n console.log();\n },\n\n logFirstStartupMessage() {\n if (!strapi.config.get('server.logger.startup.enabled')) {\n return;\n }\n\n this.logStats();\n\n console.log(chalk.bold('One more thing...'));\n console.log(\n chalk.grey('Create your first administrator 💻 by going to the administration panel at:')\n );\n console.log();\n\n const addressTable = new CLITable();\n\n const adminUrl = strapi.config.get('admin.absoluteUrl');\n addressTable.push([chalk.bold(adminUrl)]);\n\n console.log(`${addressTable.toString()}`);\n console.log();\n },\n\n logDefaultStartupMessage() {\n if (!strapi.config.get('server.logger.startup.enabled')) {\n return;\n }\n this.logStats();\n\n console.log(chalk.bold('Welcome back!'));\n\n if (app.config.get('admin.serveAdminPanel') === true) {\n console.log(chalk.grey('To manage your project 🚀, go to the administration panel at:'));\n const adminUrl = strapi.config.get('admin.absoluteUrl');\n console.log(chalk.bold(adminUrl));\n console.log();\n }\n\n console.log(chalk.grey('To access the server ⚡️, go to:'));\n const serverUrl = strapi.config.get('server.absoluteUrl');\n console.log(chalk.bold(serverUrl));\n console.log();\n },\n\n logStartupMessage({ isInitialized }: { isInitialized: boolean }) {\n if (!strapi.config.get('server.logger.startup.enabled')) {\n return;\n }\n if (!isInitialized) {\n this.logFirstStartupMessage();\n } else {\n this.logDefaultStartupMessage();\n }\n },\n };\n};\n"],"names":["ROUNDED_CHARS","top","bottom","left","right","middle","mid","createStartupLogger","app","logStats","columns","Math","min","process","stderr","console","log","chalk","black","bgWhite","_","padEnd","infoTable","CLITable","colWidths","chars","dbInfo","db","getInfo","push","blue","Date","now","config","launchedAt","environment","pid","info","strapi","version","EE","client","displayName","schema","toString","logFirstStartupMessage","get","bold","grey","addressTable","adminUrl","logDefaultStartupMessage","serverUrl","logStartupMessage","isInitialized"],"mappings":"
|
|
1
|
+
{"version":3,"file":"startup-logger.js","sources":["../../src/utils/startup-logger.ts"],"sourcesContent":["import chalk from 'chalk';\nimport CLITable from 'cli-table3';\nimport _ from 'lodash/fp';\n\nimport type { Core } from '@strapi/types';\n\nconst ROUNDED_CHARS = {\n top: '─',\n 'top-mid': '┬',\n 'top-left': '╭',\n 'top-right': '╮',\n bottom: '─',\n 'bottom-mid': '┴',\n 'bottom-left': '╰',\n 'bottom-right': '╯',\n left: '│',\n right: '│',\n middle: '│',\n mid: '',\n 'left-mid': '',\n 'mid-mid': '',\n 'right-mid': '',\n};\n\nexport const createStartupLogger = (app: Core.Strapi) => {\n return {\n logStats() {\n const columns = Math.min(process.stderr.columns, 80) - 2;\n console.log();\n console.log(chalk.black.bgWhite(_.padEnd(columns, ' Project information')));\n console.log();\n\n const infoTable = new CLITable({\n colWidths: [20, 50],\n chars: ROUNDED_CHARS,\n });\n\n const dbInfo = app.db?.getInfo();\n\n infoTable.push(\n [chalk.blue('Time'), `${new Date()}`],\n [chalk.blue('Launched in'), `${Date.now() - app.config.launchedAt} ms`],\n [chalk.blue('Environment'), app.config.environment],\n [chalk.blue('Process PID'), process.pid],\n [chalk.blue('Version'), `${app.config.info.strapi} (node ${process.version})`],\n [chalk.blue('Edition'), app.EE ? 'Enterprise' : 'Community'],\n [chalk.blue('Database'), dbInfo?.client],\n [chalk.blue('Database name'), dbInfo?.displayName]\n );\n\n if (dbInfo?.schema) {\n infoTable.push([chalk.blue('Database schema'), dbInfo.schema]);\n }\n\n console.log(infoTable.toString());\n console.log();\n console.log(chalk.black.bgWhite(_.padEnd(columns, ' Actions available')));\n console.log();\n },\n\n logFirstStartupMessage() {\n if (!strapi.config.get('server.logger.startup.enabled')) {\n return;\n }\n\n this.logStats();\n\n console.log(chalk.bold('One more thing...'));\n console.log(\n chalk.grey('Create your first administrator 💻 by going to the administration panel at:')\n );\n console.log();\n\n const addressTable = new CLITable();\n\n const adminUrl = strapi.config.get('admin.absoluteUrl');\n addressTable.push([chalk.bold(adminUrl)]);\n\n console.log(`${addressTable.toString()}`);\n console.log();\n },\n\n logDefaultStartupMessage() {\n if (!strapi.config.get('server.logger.startup.enabled')) {\n return;\n }\n this.logStats();\n\n console.log(chalk.bold('Welcome back!'));\n\n if (app.config.get('admin.serveAdminPanel') === true) {\n console.log(chalk.grey('To manage your project 🚀, go to the administration panel at:'));\n const adminUrl = strapi.config.get('admin.absoluteUrl');\n console.log(chalk.bold(adminUrl));\n console.log();\n }\n\n console.log(chalk.grey('To access the server ⚡️, go to:'));\n const serverUrl = strapi.config.get('server.absoluteUrl');\n console.log(chalk.bold(serverUrl));\n console.log();\n },\n\n logStartupMessage({ isInitialized }: { isInitialized: boolean }) {\n if (!strapi.config.get('server.logger.startup.enabled')) {\n return;\n }\n if (!isInitialized) {\n this.logFirstStartupMessage();\n } else {\n this.logDefaultStartupMessage();\n }\n },\n };\n};\n"],"names":["ROUNDED_CHARS","top","bottom","left","right","middle","mid","createStartupLogger","app","logStats","columns","Math","min","process","stderr","console","log","chalk","black","bgWhite","_","padEnd","infoTable","CLITable","colWidths","chars","dbInfo","db","getInfo","push","blue","Date","now","config","launchedAt","environment","pid","info","strapi","version","EE","client","displayName","schema","toString","logFirstStartupMessage","get","bold","grey","addressTable","adminUrl","logDefaultStartupMessage","serverUrl","logStartupMessage","isInitialized"],"mappings":";;;;;;;;;;;;AAMA,MAAMA,aAAAA,GAAgB;IACpBC,GAAAA,EAAK,GAAA;IACL,SAAA,EAAW,GAAA;IACX,UAAA,EAAY,GAAA;IACZ,WAAA,EAAa,GAAA;IACbC,MAAAA,EAAQ,GAAA;IACR,YAAA,EAAc,GAAA;IACd,aAAA,EAAe,GAAA;IACf,cAAA,EAAgB,GAAA;IAChBC,IAAAA,EAAM,GAAA;IACNC,KAAAA,EAAO,GAAA;IACPC,MAAAA,EAAQ,GAAA;IACRC,GAAAA,EAAK,EAAA;IACL,UAAA,EAAY,EAAA;IACZ,SAAA,EAAW,EAAA;IACX,WAAA,EAAa;AACf,CAAA;AAEO,MAAMC,sBAAsB,CAACC,GAAAA,GAAAA;IAClC,OAAO;AACLC,QAAAA,QAAAA,CAAAA,GAAAA;YACE,MAAMC,OAAAA,GAAUC,KAAKC,GAAG,CAACC,QAAQC,MAAM,CAACJ,OAAO,EAAE,EAAA,CAAA,GAAM,CAAA;AACvDK,YAAAA,OAAAA,CAAQC,GAAG,EAAA;YACXD,OAAAA,CAAQC,GAAG,CA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;AACvBrC,YAAAA,OAAAA,CAAQC,GAAG,EAAA;AACb,QAAA,CAAA;QAEAqC,iBAAAA,CAAAA,CAAkB,EAAEC,aAAa,EAA8B,EAAA;AAC7D,YAAA,IAAI,CAAChB,MAAAA,CAAOL,MAAM,CAACa,GAAG,CAAC,+BAAA,CAAA,EAAkC;AACvD,gBAAA;AACF,YAAA;AACA,YAAA,IAAI,CAACQ,aAAAA,EAAe;AAClB,gBAAA,IAAI,CAACT,sBAAsB,EAAA;YAC7B,CAAA,MAAO;AACL,gBAAA,IAAI,CAACM,wBAAwB,EAAA;AAC/B,YAAA;AACF,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -4,6 +4,11 @@ var cuid2 = require('@paralleldrive/cuid2');
|
|
|
4
4
|
var assert = require('node:assert');
|
|
5
5
|
var fp = require('lodash/fp');
|
|
6
6
|
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var assert__default = /*#__PURE__*/_interopDefault(assert);
|
|
10
|
+
var fp__default = /*#__PURE__*/_interopDefault(fp);
|
|
11
|
+
|
|
7
12
|
/**
|
|
8
13
|
* Because strapi/database models don't know about things like components or dynamic zones, we use this file to convert them
|
|
9
14
|
* to a relations format that it recognizes
|
|
@@ -298,9 +303,9 @@ const createCompoLinkModel = (contentType, identifiers)=>{
|
|
|
298
303
|
const transformContentTypesToModels = (contentTypes, identifiers)=>{
|
|
299
304
|
const models = [];
|
|
300
305
|
contentTypes.forEach((contentType)=>{
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
306
|
+
assert__default.default(contentType.collectionName, 'Content type "collectionName" is required');
|
|
307
|
+
assert__default.default(contentType.modelName, 'Content type "modelName" is required');
|
|
308
|
+
assert__default.default(contentType.uid, 'Content type "uid" is required');
|
|
304
309
|
// Add document id to content types
|
|
305
310
|
// as it is not documented
|
|
306
311
|
const documentIdAttribute = contentType.modelType === 'contentType' ? {
|
|
@@ -316,7 +321,7 @@ const transformContentTypesToModels = (contentTypes, identifiers)=>{
|
|
|
316
321
|
identifiers.ID_COLUMN
|
|
317
322
|
];
|
|
318
323
|
Object.keys(contentType.attributes || {}).forEach((attributeName)=>{
|
|
319
|
-
const snakeCasedAttributeName =
|
|
324
|
+
const snakeCasedAttributeName = fp__default.default.snakeCase(attributeName);
|
|
320
325
|
if (reservedAttributeNames.includes(snakeCasedAttributeName)) {
|
|
321
326
|
throw new Error(`The attribute "${attributeName}" is reserved and cannot be used in a model. Please rename "${contentType.modelName}" attribute "${attributeName}" to something else.`);
|
|
322
327
|
}
|
|
@@ -358,7 +363,7 @@ const transformContentTypesToModels = (contentTypes, identifiers)=>{
|
|
|
358
363
|
'documentId',
|
|
359
364
|
'locale',
|
|
360
365
|
'publishedAt'
|
|
361
|
-
].filter((n)=>model.attributes[n]).map((name)=>identifiers.getColumnName(
|
|
366
|
+
].filter((n)=>model.attributes[n]).map((name)=>identifiers.getColumnName(fp__default.default.snakeCase(name)))
|
|
362
367
|
}
|
|
363
368
|
];
|
|
364
369
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-content-types-to-models.js","sources":["../../src/utils/transform-content-types-to-models.ts"],"sourcesContent":["import { type Model, type Identifiers } from '@strapi/database';\nimport type { Struct, Schema } from '@strapi/types';\nimport { createId } from '@paralleldrive/cuid2';\nimport assert from 'node:assert';\nimport _ from 'lodash/fp';\n\n/**\n * Because strapi/database models don't know about things like components or dynamic zones, we use this file to convert them\n * to a relations format that it recognizes\n *\n * Therefore we have to keep an additional set of helpers/extensions to the database naming methods\n *\n * IMPORTANT!\n * If we use short versions of anything, we MUST call getNameFromTokens directly; attempting to shorten them ourselves\n * prevents the unshortened name map from being filled properly, so for example it will think that the short name\n * 'collection4f3a_cmps' maps to the unshortened 'collectionname_cmps' rather than 'collectionname_components'\n * Therefore, we only use the identifiers helpers in cases where we do not do any of our own shortening\n */\n\nexport const getComponentJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getDzJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnEntityName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'entity', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnInverseName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'component', shortName: 'cmp', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentTypeColumn = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([{ name: 'component_type', compressible: false }]);\n};\n\nexport const getComponentFkIndexName = (contentType: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: contentType, compressible: true },\n { name: 'entity', compressible: false },\n { name: 'fk', compressible: false },\n ]);\n};\n\n// const { ID_COLUMN: id, FIELD_COLUMN: field, ORDER_COLUMN: order } = identifiers;\n\nexport type LoadedContentTypeModel = Struct.ContentTypeSchema &\n Required<Pick<Struct.ContentTypeSchema, 'collectionName' | 'uid' | 'modelName'>> &\n Pick<Model, 'lifecycles'>;\n\n// Transforms an attribute (particularly for relation types) into the format that strapi/database accepts\nexport const transformAttribute = (\n name: string,\n attribute: Schema.Attribute.AnyAttribute,\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n switch (attribute.type) {\n case 'media': {\n return {\n type: 'relation',\n relation: attribute.multiple === true ? 'morphMany' : 'morphOne',\n target: 'plugin::upload.file',\n morphBy: 'related',\n };\n }\n case 'component': {\n const joinTableName = getComponentJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n return {\n type: 'relation',\n relation: attribute.repeatable === true ? 'oneToMany' : 'oneToOne',\n target: attribute.component,\n\n // We need the join table name to be deterministic,\n // We need to allow passing the join table name as an option\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n inverseJoinColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n on: {\n field: name,\n },\n orderColumnName: identifiers.ORDER_COLUMN,\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n case 'dynamiczone': {\n const joinTableName = getDzJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n\n return {\n type: 'relation',\n relation: 'morphToMany',\n // TODO: handle restrictions at some point\n // target: attribute.components,\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n morphColumn: {\n idColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n typeColumn: {\n name: compTypeColumn,\n },\n typeField: '__component',\n },\n on: {\n field: name,\n },\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n default: {\n return attribute;\n }\n }\n};\n\nexport const transformAttributes = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n return Object.keys(contentType.attributes! || {}).reduce((attrs, attrName) => {\n return {\n ...attrs,\n [attrName]: transformAttribute(\n attrName,\n contentType.attributes[attrName]!,\n contentType,\n identifiers\n ),\n };\n }, {});\n};\n\nexport const hasComponentsOrDz = (\n contentType: LoadedContentTypeModel\n): contentType is LoadedContentTypeModel & { type: 'dynamiczone' | 'component' } => {\n return Object.values(contentType.attributes || {}).some(\n (({ type }: { type: string }) => type === 'dynamiczone' || type === 'component') as any\n );\n};\n\nexport const createDocumentId = createId;\n\nconst createCompoLinkModel = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n): Model => {\n const name = getComponentJoinTableName(contentType.collectionName, identifiers);\n\n const entityId = getComponentJoinColumnEntityName(identifiers);\n const componentId = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n const fkIndex = getComponentFkIndexName(contentType.collectionName, identifiers);\n\n return {\n // TODO: make sure there can't be any conflicts with a prefix\n singularName: name,\n uid: name,\n tableName: name,\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n [entityId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [componentId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [compTypeColumn]: {\n type: 'string',\n },\n [identifiers.FIELD_COLUMN]: {\n type: 'string',\n },\n [identifiers.ORDER_COLUMN]: {\n type: 'float',\n column: {\n unsigned: true,\n defaultTo: null,\n },\n },\n },\n indexes: [\n {\n name: identifiers.getIndexName([contentType.collectionName, identifiers.FIELD_COLUMN]),\n columns: [identifiers.FIELD_COLUMN],\n },\n {\n name: identifiers.getIndexName([contentType.collectionName, compTypeColumn]),\n columns: [compTypeColumn],\n },\n {\n name: fkIndex,\n columns: [entityId],\n },\n {\n // NOTE: since we don't include attribute names, we need to be careful not to create another unique index\n name: identifiers.getUniqueIndexName([contentType.collectionName]),\n columns: [entityId, componentId, identifiers.FIELD_COLUMN, compTypeColumn],\n type: 'unique',\n },\n ],\n foreignKeys: [\n {\n name: fkIndex,\n columns: [entityId],\n referencedColumns: [identifiers.ID_COLUMN],\n referencedTable: identifiers.getTableName(contentType.collectionName),\n onDelete: 'CASCADE',\n },\n ],\n };\n};\n\nexport const transformContentTypesToModels = (\n contentTypes: LoadedContentTypeModel[],\n identifiers: Identifiers\n): Model[] => {\n const models: Model[] = [];\n\n contentTypes.forEach((contentType) => {\n assert(contentType.collectionName, 'Content type \"collectionName\" is required');\n assert(contentType.modelName, 'Content type \"modelName\" is required');\n assert(contentType.uid, 'Content type \"uid\" is required');\n\n // Add document id to content types\n // as it is not documented\n const documentIdAttribute: Record<string, Schema.Attribute.AnyAttribute> =\n contentType.modelType === 'contentType'\n ? { documentId: { type: 'string', default: createDocumentId } }\n : {};\n\n // TODO: this needs to be combined with getReservedNames, we should not be maintaining two lists\n // Prevent user from creating a documentId attribute\n const reservedAttributeNames = ['document_id', identifiers.ID_COLUMN];\n Object.keys(contentType.attributes || {}).forEach((attributeName) => {\n const snakeCasedAttributeName = _.snakeCase(attributeName);\n if (reservedAttributeNames.includes(snakeCasedAttributeName)) {\n throw new Error(\n `The attribute \"${attributeName}\" is reserved and cannot be used in a model. Please rename \"${contentType.modelName}\" attribute \"${attributeName}\" to something else.`\n );\n }\n });\n\n if (hasComponentsOrDz(contentType)) {\n const compoLinkModel = createCompoLinkModel(contentType, identifiers);\n models.push(compoLinkModel);\n }\n\n const model: Model = {\n uid: contentType.uid,\n singularName: contentType.modelName,\n tableName: contentType.collectionName, // This gets shortened in metadata.loadModels(), so we don't shorten here or it will happen twice\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n ...documentIdAttribute,\n ...transformAttributes(contentType, identifiers),\n },\n indexes: contentType.indexes as Model['indexes'],\n foreignKeys: contentType.foreignKeys as Model['foreignKeys'],\n lifecycles: contentType?.lifecycles ?? {},\n };\n\n // Document lookups: secondary btree index declared here so syncSchema owns it\n // (instead of DDL in internal migration `5.0.0-06-add-document-id-indexes`, now a no-op).\n // Keep the exact same name/columns schema sync already produced so existing databases\n // see no index diff on upgrade (a rename would orphan the old index, since the schema\n // builder's dropIndex is a silent no-op unless forceMigration is enabled).\n if (contentType.modelType === 'contentType') {\n model.indexes = [\n ...(model.indexes || []),\n {\n name: identifiers.getIndexName([contentType.collectionName, 'documents']),\n // Filter attributes that are not in the schema\n columns: ['documentId', 'locale', 'publishedAt']\n .filter((n) => model.attributes[n])\n .map((name) => identifiers.getColumnName(_.snakeCase(name))),\n },\n ];\n }\n\n models.push(model);\n });\n\n return models;\n};\n"],"names":["getComponentJoinTableName","collectionName","identifiers","getNameFromTokens","name","compressible","shortName","getDzJoinTableName","getComponentJoinColumnEntityName","getComponentJoinColumnInverseName","getComponentTypeColumn","getComponentFkIndexName","contentType","transformAttribute","attribute","type","relation","multiple","target","morphBy","joinTableName","joinColumnEntityName","joinColumnInverseName","compTypeColumn","repeatable","component","joinTable","joinColumn","referencedColumn","ID_COLUMN","inverseJoinColumn","on","field","orderColumnName","ORDER_COLUMN","orderBy","order","pivotColumns","FIELD_COLUMN","morphColumn","idColumn","typeColumn","typeField","transformAttributes","Object","keys","attributes","reduce","attrs","attrName","hasComponentsOrDz","values","some","createDocumentId","createId","createCompoLinkModel","entityId","componentId","fkIndex","singularName","uid","tableName","column","unsigned","defaultTo","indexes","getIndexName","columns","getUniqueIndexName","foreignKeys","referencedColumns","referencedTable","getTableName","onDelete","transformContentTypesToModels","contentTypes","models","forEach","assert","modelName","documentIdAttribute","modelType","documentId","default","reservedAttributeNames","attributeName","snakeCasedAttributeName","_","snakeCase","includes","Error","compoLinkModel","push","model","lifecycles","filter","n","map","getColumnName"],"mappings":";;;;;;AAMA;;;;;;;;;;;AAWC,IAEM,MAAMA,yBAAAA,GAA4B,CAACC,cAAAA,EAAwBC,WAAAA,GAAAA;IAChE,OAAOA,WAAAA,CAAYC,iBAAiB,CAAC;AACnC,QAAA;YAAEC,IAAAA,EAAMH,cAAAA;YAAgBI,YAAAA,EAAc;AAAK,SAAA;AAC3C,QAAA;YAAED,IAAAA,EAAM,YAAA;YAAcE,SAAAA,EAAW,MAAA;YAAQD,YAAAA,EAAc;AAAM;AAC9D,KAAA,CAAA;AACH;AAEO,MAAME,kBAAAA,GAAqB,CAACN,cAAAA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;mBACV4B,KAAAA,CAAM5B,OAAO,IAAI,EAAE;AACvB,gBAAA;oBACE7D,IAAAA,EAAMF,WAAAA,CAAYgE,YAAY,CAAC;AAACtD,wBAAAA,WAAAA,CAAYX,cAAc;AAAE,wBAAA;AAAY,qBAAA,CAAA;;oBAExEkE,OAAAA,EAAS;AAAC,wBAAA,YAAA;AAAc,wBAAA,QAAA;AAAU,wBAAA;AAAc,qBAAA,CAC7C4B,MAAM,CAAC,CAACC,IAAMH,KAAAA,CAAM/C,UAAU,CAACkD,CAAAA,CAAE,CAAA,CACjCC,GAAG,CAAC,CAAC7F,IAAAA,GAASF,WAAAA,CAAYgG,aAAa,CAACX,EAAAA,CAAEC,SAAS,CAACpF,IAAAA,CAAAA,CAAAA;AACzD;AACD,aAAA;AACH,QAAA;AAEAwE,QAAAA,MAAAA,CAAOgB,IAAI,CAACC,KAAAA,CAAAA;AACd,IAAA,CAAA,CAAA;IAEA,OAAOjB,MAAAA;AACT;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"transform-content-types-to-models.js","sources":["../../src/utils/transform-content-types-to-models.ts"],"sourcesContent":["import { type Model, type Identifiers } from '@strapi/database';\nimport type { Struct, Schema } from '@strapi/types';\nimport { createId } from '@paralleldrive/cuid2';\nimport assert from 'node:assert';\nimport _ from 'lodash/fp';\n\n/**\n * Because strapi/database models don't know about things like components or dynamic zones, we use this file to convert them\n * to a relations format that it recognizes\n *\n * Therefore we have to keep an additional set of helpers/extensions to the database naming methods\n *\n * IMPORTANT!\n * If we use short versions of anything, we MUST call getNameFromTokens directly; attempting to shorten them ourselves\n * prevents the unshortened name map from being filled properly, so for example it will think that the short name\n * 'collection4f3a_cmps' maps to the unshortened 'collectionname_cmps' rather than 'collectionname_components'\n * Therefore, we only use the identifiers helpers in cases where we do not do any of our own shortening\n */\n\nexport const getComponentJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getDzJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnEntityName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'entity', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnInverseName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'component', shortName: 'cmp', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentTypeColumn = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([{ name: 'component_type', compressible: false }]);\n};\n\nexport const getComponentFkIndexName = (contentType: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: contentType, compressible: true },\n { name: 'entity', compressible: false },\n { name: 'fk', compressible: false },\n ]);\n};\n\n// const { ID_COLUMN: id, FIELD_COLUMN: field, ORDER_COLUMN: order } = identifiers;\n\nexport type LoadedContentTypeModel = Struct.ContentTypeSchema &\n Required<Pick<Struct.ContentTypeSchema, 'collectionName' | 'uid' | 'modelName'>> &\n Pick<Model, 'lifecycles'>;\n\n// Transforms an attribute (particularly for relation types) into the format that strapi/database accepts\nexport const transformAttribute = (\n name: string,\n attribute: Schema.Attribute.AnyAttribute,\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n switch (attribute.type) {\n case 'media': {\n return {\n type: 'relation',\n relation: attribute.multiple === true ? 'morphMany' : 'morphOne',\n target: 'plugin::upload.file',\n morphBy: 'related',\n };\n }\n case 'component': {\n const joinTableName = getComponentJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n return {\n type: 'relation',\n relation: attribute.repeatable === true ? 'oneToMany' : 'oneToOne',\n target: attribute.component,\n\n // We need the join table name to be deterministic,\n // We need to allow passing the join table name as an option\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n inverseJoinColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n on: {\n field: name,\n },\n orderColumnName: identifiers.ORDER_COLUMN,\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n case 'dynamiczone': {\n const joinTableName = getDzJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n\n return {\n type: 'relation',\n relation: 'morphToMany',\n // TODO: handle restrictions at some point\n // target: attribute.components,\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n morphColumn: {\n idColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n typeColumn: {\n name: compTypeColumn,\n },\n typeField: '__component',\n },\n on: {\n field: name,\n },\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n default: {\n return attribute;\n }\n }\n};\n\nexport const transformAttributes = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n return Object.keys(contentType.attributes! || {}).reduce((attrs, attrName) => {\n return {\n ...attrs,\n [attrName]: transformAttribute(\n attrName,\n contentType.attributes[attrName]!,\n contentType,\n identifiers\n ),\n };\n }, {});\n};\n\nexport const hasComponentsOrDz = (\n contentType: LoadedContentTypeModel\n): contentType is LoadedContentTypeModel & { type: 'dynamiczone' | 'component' } => {\n return Object.values(contentType.attributes || {}).some(\n (({ type }: { type: string }) => type === 'dynamiczone' || type === 'component') as any\n );\n};\n\nexport const createDocumentId = createId;\n\nconst createCompoLinkModel = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n): Model => {\n const name = getComponentJoinTableName(contentType.collectionName, identifiers);\n\n const entityId = getComponentJoinColumnEntityName(identifiers);\n const componentId = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n const fkIndex = getComponentFkIndexName(contentType.collectionName, identifiers);\n\n return {\n // TODO: make sure there can't be any conflicts with a prefix\n singularName: name,\n uid: name,\n tableName: name,\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n [entityId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [componentId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [compTypeColumn]: {\n type: 'string',\n },\n [identifiers.FIELD_COLUMN]: {\n type: 'string',\n },\n [identifiers.ORDER_COLUMN]: {\n type: 'float',\n column: {\n unsigned: true,\n defaultTo: null,\n },\n },\n },\n indexes: [\n {\n name: identifiers.getIndexName([contentType.collectionName, identifiers.FIELD_COLUMN]),\n columns: [identifiers.FIELD_COLUMN],\n },\n {\n name: identifiers.getIndexName([contentType.collectionName, compTypeColumn]),\n columns: [compTypeColumn],\n },\n {\n name: fkIndex,\n columns: [entityId],\n },\n {\n // NOTE: since we don't include attribute names, we need to be careful not to create another unique index\n name: identifiers.getUniqueIndexName([contentType.collectionName]),\n columns: [entityId, componentId, identifiers.FIELD_COLUMN, compTypeColumn],\n type: 'unique',\n },\n ],\n foreignKeys: [\n {\n name: fkIndex,\n columns: [entityId],\n referencedColumns: [identifiers.ID_COLUMN],\n referencedTable: identifiers.getTableName(contentType.collectionName),\n onDelete: 'CASCADE',\n },\n ],\n };\n};\n\nexport const transformContentTypesToModels = (\n contentTypes: LoadedContentTypeModel[],\n identifiers: Identifiers\n): Model[] => {\n const models: Model[] = [];\n\n contentTypes.forEach((contentType) => {\n assert(contentType.collectionName, 'Content type \"collectionName\" is required');\n assert(contentType.modelName, 'Content type \"modelName\" is required');\n assert(contentType.uid, 'Content type \"uid\" is required');\n\n // Add document id to content types\n // as it is not documented\n const documentIdAttribute: Record<string, Schema.Attribute.AnyAttribute> =\n contentType.modelType === 'contentType'\n ? { documentId: { type: 'string', default: createDocumentId } }\n : {};\n\n // TODO: this needs to be combined with getReservedNames, we should not be maintaining two lists\n // Prevent user from creating a documentId attribute\n const reservedAttributeNames = ['document_id', identifiers.ID_COLUMN];\n Object.keys(contentType.attributes || {}).forEach((attributeName) => {\n const snakeCasedAttributeName = _.snakeCase(attributeName);\n if (reservedAttributeNames.includes(snakeCasedAttributeName)) {\n throw new Error(\n `The attribute \"${attributeName}\" is reserved and cannot be used in a model. Please rename \"${contentType.modelName}\" attribute \"${attributeName}\" to something else.`\n );\n }\n });\n\n if (hasComponentsOrDz(contentType)) {\n const compoLinkModel = createCompoLinkModel(contentType, identifiers);\n models.push(compoLinkModel);\n }\n\n const model: Model = {\n uid: contentType.uid,\n singularName: contentType.modelName,\n tableName: contentType.collectionName, // This gets shortened in metadata.loadModels(), so we don't shorten here or it will happen twice\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n ...documentIdAttribute,\n ...transformAttributes(contentType, identifiers),\n },\n indexes: contentType.indexes as Model['indexes'],\n foreignKeys: contentType.foreignKeys as Model['foreignKeys'],\n lifecycles: contentType?.lifecycles ?? {},\n };\n\n // Document lookups: secondary btree index declared here so syncSchema owns it\n // (instead of DDL in internal migration `5.0.0-06-add-document-id-indexes`, now a no-op).\n // Keep the exact same name/columns schema sync already produced so existing databases\n // see no index diff on upgrade (a rename would orphan the old index, since the schema\n // builder's dropIndex is a silent no-op unless forceMigration is enabled).\n if (contentType.modelType === 'contentType') {\n model.indexes = [\n ...(model.indexes || []),\n {\n name: identifiers.getIndexName([contentType.collectionName, 'documents']),\n // Filter attributes that are not in the schema\n columns: ['documentId', 'locale', 'publishedAt']\n .filter((n) => model.attributes[n])\n .map((name) => identifiers.getColumnName(_.snakeCase(name))),\n },\n ];\n }\n\n models.push(model);\n });\n\n return models;\n};\n"],"names":["getComponentJoinTableName","collectionName","identifiers","getNameFromTokens","name","compressible","shortName","getDzJoinTableName","getComponentJoinColumnEntityName","getComponentJoinColumnInverseName","getComponentTypeColumn","getComponentFkIndexName","contentType","transformAttribute","attribute","type","relation","multiple","target","morphBy","joinTableName","joinColumnEntityName","joinColumnInverseName","compTypeColumn","repeatable","component","joinTable","joinColumn","referencedColumn","ID_COLUMN","inverseJoinColumn","on","field","orderColumnName","ORDER_COLUMN","orderBy","order","pivotColumns","FIELD_COLUMN","morphColumn","idColumn","typeColumn","typeField","transformAttributes","Object","keys","attributes","reduce","attrs","attrName","hasComponentsOrDz","values","some","createDocumentId","createId","createCompoLinkModel","entityId","componentId","fkIndex","singularName","uid","tableName","column","unsigned","defaultTo","indexes","getIndexName","columns","getUniqueIndexName","foreignKeys","referencedColumns","referencedTable","getTableName","onDelete","transformContentTypesToModels","contentTypes","models","forEach","assert","modelName","documentIdAttribute","modelType","documentId","default","reservedAttributeNames","attributeName","snakeCasedAttributeName","_","snakeCase","includes","Error","compoLinkModel","push","model","lifecycles","filter","n","map","getColumnName"],"mappings":";;;;;;;;;;;AAMA;;;;;;;;;;;AAWC,IAEM,MAAMA,yBAAAA,GAA4B,CAACC,cAAAA,EAAwBC,WAAAA,GAAAA;IAChE,OAAOA,WAAAA,CAAYC,iBAAiB,CAAC;AACnC,QAAA;YAAEC,IAAAA,EAAMH,cAAAA;YAAgBI,YAAAA,EAAc;AAAK,SAAA;AAC3C,QAAA;YAAED,IAAAA,EAAM,YAAA;YAAcE,SAAAA,EAAW,MAAA;YAAQD,YAAAA,EAAc;AAAM;AAC9D,KAAA,CAAA;AACH;AAEO,MAAME,kBAAAA,GAAqB,CAACN,cAAAA,EAAwBC,WAAAA,GAAAA;IACzD,OAAOA,WAAAA,CAAYC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vB,gBAAA;oBACE7D,IAAAA,EAAMF,WAAAA,CAAYgE,YAAY,CAAC;AAACtD,wBAAAA,WAAAA,CAAYX,cAAc;AAAE,wBAAA;AAAY,qBAAA,CAAA;;oBAExEkE,OAAAA,EAAS;AAAC,wBAAA,YAAA;AAAc,wBAAA,QAAA;AAAU,wBAAA;AAAc,qBAAA,CAC7C4B,MAAM,CAAC,CAACC,IAAMH,KAAAA,CAAM/C,UAAU,CAACkD,CAAAA,CAAE,CAAA,CACjCC,GAAG,CAAC,CAAC7F,IAAAA,GAASF,WAAAA,CAAYgG,aAAa,CAACX,mBAAAA,CAAEC,SAAS,CAACpF,IAAAA,CAAAA,CAAAA;AACzD;AACD,aAAA;AACH,QAAA;AAEAwE,QAAAA,MAAAA,CAAOgB,IAAI,CAACC,KAAAA,CAAAA;AACd,IAAA,CAAA,CAAA;IAEA,OAAOjB,MAAAA;AACT;;;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/update-notifier/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/update-notifier/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAyB1C,eAAO,MAAM,oBAAoB,WAAY,KAAK,MAAM,SAwEvD,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var path = require('path');
|
|
4
|
-
var packageJson = require('package-json');
|
|
5
4
|
var Configstore = require('configstore');
|
|
6
5
|
var semver = require('semver');
|
|
7
6
|
var boxen = require('boxen');
|
|
@@ -9,6 +8,14 @@ var chalk = require('chalk');
|
|
|
9
8
|
var strapiUtils = require('@strapi/utils');
|
|
10
9
|
var _package = require('../../package.json.js');
|
|
11
10
|
|
|
11
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
|
|
13
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
14
|
+
var Configstore__default = /*#__PURE__*/_interopDefault(Configstore);
|
|
15
|
+
var semver__default = /*#__PURE__*/_interopDefault(semver);
|
|
16
|
+
var boxen__default = /*#__PURE__*/_interopDefault(boxen);
|
|
17
|
+
var chalk__default = /*#__PURE__*/_interopDefault(chalk);
|
|
18
|
+
|
|
12
19
|
const CHECK_INTERVAL = 1000 * 60 * 60 * 24 * 1; // 1 day
|
|
13
20
|
const NOTIF_INTERVAL = 1000 * 60 * 60 * 24 * 7; // 1 week
|
|
14
21
|
const boxenOptions = {
|
|
@@ -19,9 +26,9 @@ const boxenOptions = {
|
|
|
19
26
|
borderStyle: 'round'
|
|
20
27
|
};
|
|
21
28
|
const getUpdateMessage = (newVersion, currentVersion)=>{
|
|
22
|
-
const currentVersionLog =
|
|
23
|
-
const newVersionLog =
|
|
24
|
-
const releaseLink =
|
|
29
|
+
const currentVersionLog = chalk__default.default.dim(currentVersion);
|
|
30
|
+
const newVersionLog = chalk__default.default.green(newVersion);
|
|
31
|
+
const releaseLink = chalk__default.default.bold('https://github.com/strapi/strapi/releases');
|
|
25
32
|
return `
|
|
26
33
|
A new version of Strapi is available ${currentVersionLog} → ${newVersionLog}
|
|
27
34
|
Check out the new releases at: ${releaseLink}
|
|
@@ -30,8 +37,8 @@ Check out the new releases at: ${releaseLink}
|
|
|
30
37
|
const createUpdateNotifier = (strapi)=>{
|
|
31
38
|
let config;
|
|
32
39
|
try {
|
|
33
|
-
config = new
|
|
34
|
-
configPath:
|
|
40
|
+
config = new Configstore__default.default(_package.default.name, {}, {
|
|
41
|
+
configPath: path__default.default.join(strapi.dirs.app.root, '.strapi-updater.json')
|
|
35
42
|
});
|
|
36
43
|
} catch {
|
|
37
44
|
// we don't have write access to the file system
|
|
@@ -45,6 +52,12 @@ const createUpdateNotifier = (strapi)=>{
|
|
|
45
52
|
return;
|
|
46
53
|
}
|
|
47
54
|
try {
|
|
55
|
+
// `package-json` is ESM-only. The CJS build can't statically import it while engines
|
|
56
|
+
// allow Node <20.19 (`require()` of ESM throws ERR_REQUIRE_ESM there), so load it via
|
|
57
|
+
// dynamic import. Once the Node floor is >=22, this can revert to a static
|
|
58
|
+
// `import packageJson from 'package-json'` — rollup's `interop: 'auto'` resolves the
|
|
59
|
+
// default export shape correctly.
|
|
60
|
+
const { default: packageJson } = await import('package-json');
|
|
48
61
|
const res = await packageJson(_package.default.name);
|
|
49
62
|
if (res.version) {
|
|
50
63
|
config.set('latest', res.version);
|
|
@@ -58,10 +71,10 @@ const createUpdateNotifier = (strapi)=>{
|
|
|
58
71
|
const now = Date.now();
|
|
59
72
|
const latestVersion = config.get('latest');
|
|
60
73
|
const lastNotification = config.get('lastNotification') || 0;
|
|
61
|
-
if (!process.stdout.isTTY || lastNotification + notifInterval > now || !
|
|
74
|
+
if (!process.stdout.isTTY || lastNotification + notifInterval > now || !semver__default.default.valid(latestVersion) || !semver__default.default.valid(_package.default.version) || semver__default.default.lte(latestVersion, _package.default.version)) {
|
|
62
75
|
return;
|
|
63
76
|
}
|
|
64
|
-
const message =
|
|
77
|
+
const message = boxen__default.default(getUpdateMessage(latestVersion, _package.default.version), boxenOptions);
|
|
65
78
|
config.set('lastNotification', now);
|
|
66
79
|
console.log(message);
|
|
67
80
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/utils/update-notifier/index.ts"],"sourcesContent":["import path from 'path';\nimport
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/utils/update-notifier/index.ts"],"sourcesContent":["import path from 'path';\nimport Configstore from 'configstore';\nimport semver from 'semver';\nimport boxen from 'boxen';\nimport chalk from 'chalk';\nimport { env } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\n\nimport pkg from '../../../package.json';\n\nconst CHECK_INTERVAL = 1000 * 60 * 60 * 24 * 1; // 1 day\nconst NOTIF_INTERVAL = 1000 * 60 * 60 * 24 * 7; // 1 week\nconst boxenOptions: boxen.Options = {\n padding: 1,\n margin: 1,\n align: 'center',\n borderColor: 'yellow',\n borderStyle: 'round',\n};\n\nconst getUpdateMessage = (newVersion: string, currentVersion: string) => {\n const currentVersionLog = chalk.dim(currentVersion);\n const newVersionLog = chalk.green(newVersion);\n const releaseLink = chalk.bold('https://github.com/strapi/strapi/releases');\n\n return `\nA new version of Strapi is available ${currentVersionLog} → ${newVersionLog}\nCheck out the new releases at: ${releaseLink}\n`.trim();\n};\n\nexport const createUpdateNotifier = (strapi: Core.Strapi) => {\n let config: InstanceType<typeof Configstore>;\n\n try {\n config = new Configstore(\n pkg.name,\n {},\n { configPath: path.join(strapi.dirs.app.root, '.strapi-updater.json') }\n );\n } catch {\n // we don't have write access to the file system\n // we silence the error\n return;\n }\n\n const checkUpdate = async (checkInterval: number) => {\n const now = Date.now();\n const lastUpdateCheck = config.get('lastUpdateCheck') || 0;\n if (lastUpdateCheck + checkInterval > now) {\n return;\n }\n\n try {\n // `package-json` is ESM-only. The CJS build can't statically import it while engines\n // allow Node <20.19 (`require()` of ESM throws ERR_REQUIRE_ESM there), so load it via\n // dynamic import. Once the Node floor is >=22, this can revert to a static\n // `import packageJson from 'package-json'` — rollup's `interop: 'auto'` resolves the\n // default export shape correctly.\n const { default: packageJson } = await import('package-json');\n const res = await packageJson(pkg.name);\n if (res.version) {\n config.set('latest', res.version);\n config.set('lastUpdateCheck', now);\n }\n } catch {\n // silence error if offline\n }\n };\n\n const display = (notifInterval: number) => {\n const now = Date.now();\n const latestVersion = config.get('latest');\n const lastNotification = config.get('lastNotification') || 0;\n\n if (\n !process.stdout.isTTY ||\n lastNotification + notifInterval > now ||\n !semver.valid(latestVersion) ||\n !semver.valid(pkg.version) ||\n semver.lte(latestVersion, pkg.version)\n ) {\n return;\n }\n\n const message = boxen(getUpdateMessage(latestVersion, pkg.version), boxenOptions);\n config.set('lastNotification', now);\n console.log(message);\n };\n\n // TODO v6: Remove this warning\n if (env.bool('STRAPI_DISABLE_UPDATE_NOTIFICATION', false)) {\n strapi.log.warn(\n 'STRAPI_DISABLE_UPDATE_NOTIFICATION is no longer supported. Instead, set logger.updates.enabled to false in your server configuration.'\n );\n }\n\n if (!strapi.config.get('server.logger.updates.enabled') || !config) {\n return;\n }\n\n display(NOTIF_INTERVAL);\n checkUpdate(CHECK_INTERVAL); // doesn't need to await\n};\n"],"names":["CHECK_INTERVAL","NOTIF_INTERVAL","boxenOptions","padding","margin","align","borderColor","borderStyle","getUpdateMessage","newVersion","currentVersion","currentVersionLog","chalk","dim","newVersionLog","green","releaseLink","bold","trim","createUpdateNotifier","strapi","config","Configstore","pkg","name","configPath","path","join","dirs","app","root","checkUpdate","checkInterval","now","Date","lastUpdateCheck","get","default","packageJson","res","version","set","display","notifInterval","latestVersion","lastNotification","process","stdout","isTTY","semver","valid","lte","message","boxen","console","log","env","bool","warn"],"mappings":";;;;;;;;;;;;;;;;;;AAUA,MAAMA,iBAAiB,IAAA,GAAO,EAAA,GAAK,EAAA,GAAK,EAAA,GAAK;AAC7C,MAAMC,iBAAiB,IAAA,GAAO,EAAA,GAAK,EAAA,GAAK,EAAA,GAAK;AAC7C,MAAMC,YAAAA,GAA8B;IAClCC,OAAAA,EAAS,CAAA;IACTC,MAAAA,EAAQ,CAAA;IACRC,KAAAA,EAAO,QAAA;IACPC,WAAAA,EAAa,QAAA;IACbC,WAAAA,EAAa;AACf,CAAA;AAEA,MAAMC,gBAAAA,GAAmB,CAACC,UAAAA,EAAoBC,cAAAA,GAAAA;IAC5C,MAAMC,iBAAAA,GAAoBC,sBAAAA,CAAMC,GAAG,CAACH,cAAAA,CAAAA;IACpC,MAAMI,aAAAA,GAAgBF,sBAAAA,CAAMG,KAAK,CAACN,UAAAA,CAAAA;IAClC,MAAMO,WAAAA,GAAcJ,sBAAAA,CAAMK,IAAI,CAAC,2CAAA,CAAA;AAE/B,IAAA,OAAO;qCAC4B,EAAEN,iBAAAA,CAAkB,GAAG,EAAEG,aAAAA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,MAAAA,CAAOe,GAAG,CAAC,QAAA,CAAA;AACjC,QAAA,MAAMS,gBAAAA,GAAmBxB,MAAAA,CAAOe,GAAG,CAAC,kBAAA,CAAA,IAAuB,CAAA;QAE3D,IACE,CAACU,OAAAA,CAAQC,MAAM,CAACC,KAAK,IACrBH,gBAAAA,GAAmBF,aAAAA,GAAgBV,GAAAA,IACnC,CAACgB,uBAAAA,CAAOC,KAAK,CAACN,aAAAA,CAAAA,IACd,CAACK,uBAAAA,CAAOC,KAAK,CAAC3B,gBAAAA,CAAIiB,OAAO,CAAA,IACzBS,uBAAAA,CAAOE,GAAG,CAACP,aAAAA,EAAerB,gBAAAA,CAAIiB,OAAO,CAAA,EACrC;AACA,YAAA;AACF,QAAA;AAEA,QAAA,MAAMY,UAAUC,sBAAAA,CAAM7C,gBAAAA,CAAiBoC,aAAAA,EAAerB,gBAAAA,CAAIiB,OAAO,CAAA,EAAGtC,YAAAA,CAAAA;QACpEmB,MAAAA,CAAOoB,GAAG,CAAC,kBAAA,EAAoBR,GAAAA,CAAAA;AAC/BqB,QAAAA,OAAAA,CAAQC,GAAG,CAACH,OAAAA,CAAAA;AACd,IAAA,CAAA;;AAGA,IAAA,IAAII,eAAAA,CAAIC,IAAI,CAAC,oCAAA,EAAsC,KAAA,CAAA,EAAQ;QACzDrC,MAAAA,CAAOmC,GAAG,CAACG,IAAI,CACb,uIAAA,CAAA;AAEJ,IAAA;IAEA,IAAI,CAACtC,OAAOC,MAAM,CAACe,GAAG,CAAC,+BAAA,CAAA,IAAoC,CAACf,MAAAA,EAAQ;AAClE,QAAA;AACF,IAAA;IAEAqB,OAAAA,CAAQzC,cAAAA,CAAAA;AACR8B,IAAAA,WAAAA,CAAY/B;AACd;;;;"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import packageJson from 'package-json';
|
|
3
2
|
import Configstore from 'configstore';
|
|
4
3
|
import semver from 'semver';
|
|
5
4
|
import boxen from 'boxen';
|
|
@@ -43,6 +42,12 @@ const createUpdateNotifier = (strapi)=>{
|
|
|
43
42
|
return;
|
|
44
43
|
}
|
|
45
44
|
try {
|
|
45
|
+
// `package-json` is ESM-only. The CJS build can't statically import it while engines
|
|
46
|
+
// allow Node <20.19 (`require()` of ESM throws ERR_REQUIRE_ESM there), so load it via
|
|
47
|
+
// dynamic import. Once the Node floor is >=22, this can revert to a static
|
|
48
|
+
// `import packageJson from 'package-json'` — rollup's `interop: 'auto'` resolves the
|
|
49
|
+
// default export shape correctly.
|
|
50
|
+
const { default: packageJson } = await import('package-json');
|
|
46
51
|
const res = await packageJson(pkg.name);
|
|
47
52
|
if (res.version) {
|
|
48
53
|
config.set('latest', res.version);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/utils/update-notifier/index.ts"],"sourcesContent":["import path from 'path';\nimport
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/utils/update-notifier/index.ts"],"sourcesContent":["import path from 'path';\nimport Configstore from 'configstore';\nimport semver from 'semver';\nimport boxen from 'boxen';\nimport chalk from 'chalk';\nimport { env } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\n\nimport pkg from '../../../package.json';\n\nconst CHECK_INTERVAL = 1000 * 60 * 60 * 24 * 1; // 1 day\nconst NOTIF_INTERVAL = 1000 * 60 * 60 * 24 * 7; // 1 week\nconst boxenOptions: boxen.Options = {\n padding: 1,\n margin: 1,\n align: 'center',\n borderColor: 'yellow',\n borderStyle: 'round',\n};\n\nconst getUpdateMessage = (newVersion: string, currentVersion: string) => {\n const currentVersionLog = chalk.dim(currentVersion);\n const newVersionLog = chalk.green(newVersion);\n const releaseLink = chalk.bold('https://github.com/strapi/strapi/releases');\n\n return `\nA new version of Strapi is available ${currentVersionLog} → ${newVersionLog}\nCheck out the new releases at: ${releaseLink}\n`.trim();\n};\n\nexport const createUpdateNotifier = (strapi: Core.Strapi) => {\n let config: InstanceType<typeof Configstore>;\n\n try {\n config = new Configstore(\n pkg.name,\n {},\n { configPath: path.join(strapi.dirs.app.root, '.strapi-updater.json') }\n );\n } catch {\n // we don't have write access to the file system\n // we silence the error\n return;\n }\n\n const checkUpdate = async (checkInterval: number) => {\n const now = Date.now();\n const lastUpdateCheck = config.get('lastUpdateCheck') || 0;\n if (lastUpdateCheck + checkInterval > now) {\n return;\n }\n\n try {\n // `package-json` is ESM-only. The CJS build can't statically import it while engines\n // allow Node <20.19 (`require()` of ESM throws ERR_REQUIRE_ESM there), so load it via\n // dynamic import. Once the Node floor is >=22, this can revert to a static\n // `import packageJson from 'package-json'` — rollup's `interop: 'auto'` resolves the\n // default export shape correctly.\n const { default: packageJson } = await import('package-json');\n const res = await packageJson(pkg.name);\n if (res.version) {\n config.set('latest', res.version);\n config.set('lastUpdateCheck', now);\n }\n } catch {\n // silence error if offline\n }\n };\n\n const display = (notifInterval: number) => {\n const now = Date.now();\n const latestVersion = config.get('latest');\n const lastNotification = config.get('lastNotification') || 0;\n\n if (\n !process.stdout.isTTY ||\n lastNotification + notifInterval > now ||\n !semver.valid(latestVersion) ||\n !semver.valid(pkg.version) ||\n semver.lte(latestVersion, pkg.version)\n ) {\n return;\n }\n\n const message = boxen(getUpdateMessage(latestVersion, pkg.version), boxenOptions);\n config.set('lastNotification', now);\n console.log(message);\n };\n\n // TODO v6: Remove this warning\n if (env.bool('STRAPI_DISABLE_UPDATE_NOTIFICATION', false)) {\n strapi.log.warn(\n 'STRAPI_DISABLE_UPDATE_NOTIFICATION is no longer supported. Instead, set logger.updates.enabled to false in your server configuration.'\n );\n }\n\n if (!strapi.config.get('server.logger.updates.enabled') || !config) {\n return;\n }\n\n display(NOTIF_INTERVAL);\n checkUpdate(CHECK_INTERVAL); // doesn't need to await\n};\n"],"names":["CHECK_INTERVAL","NOTIF_INTERVAL","boxenOptions","padding","margin","align","borderColor","borderStyle","getUpdateMessage","newVersion","currentVersion","currentVersionLog","chalk","dim","newVersionLog","green","releaseLink","bold","trim","createUpdateNotifier","strapi","config","Configstore","pkg","name","configPath","path","join","dirs","app","root","checkUpdate","checkInterval","now","Date","lastUpdateCheck","get","default","packageJson","res","version","set","display","notifInterval","latestVersion","lastNotification","process","stdout","isTTY","semver","valid","lte","message","boxen","console","log","env","bool","warn"],"mappings":";;;;;;;;AAUA,MAAMA,iBAAiB,IAAA,GAAO,EAAA,GAAK,EAAA,GAAK,EAAA,GAAK;AAC7C,MAAMC,iBAAiB,IAAA,GAAO,EAAA,GAAK,EAAA,GAAK,EAAA,GAAK;AAC7C,MAAMC,YAAAA,GAA8B;IAClCC,OAAAA,EAAS,CAAA;IACTC,MAAAA,EAAQ,CAAA;IACRC,KAAAA,EAAO,QAAA;IACPC,WAAAA,EAAa,QAAA;IACbC,WAAAA,EAAa;AACf,CAAA;AAEA,MAAMC,gBAAAA,GAAmB,CAACC,UAAAA,EAAoBC,cAAAA,GAAAA;IAC5C,MAAMC,iBAAAA,GAAoBC,KAAAA,CAAMC,GAAG,CAACH,cAAAA,CAAAA;IACpC,MAAMI,aAAAA,GAAgBF,KAAAA,CAAMG,KAAK,CAACN,UAAAA,CAAAA;IAClC,MAAMO,WAAAA,GAAcJ,KAAAA,CAAMK,IAAI,CAAC,2CAAA,CAAA;AAE/B,IAAA,OAAO;qCAC4B,EAAEN,iBAAAA,CAAkB,GAAG,EAAEG,aAAAA;AAC/B,+BAAA,EAAEE,WAAAA;AACjC,CAAC,CAACE,IAAI,EAAA;AACN,CAAA;AAEO,MAAMC,uBAAuB,CAACC,MAAAA,GAAAA;IACnC,IAAIC,MAAAA;IAEJ,IAAI;AACFA,QAAAA,MAAAA,GAAS,IAAIC,WAAAA,CACXC,GAAAA,CAAIC,IAAI,EACR,EAAC,EACD;YAAEC,UAAAA,EAAYC,IAAAA,CAAKC,IAAI,CAACP,MAAAA,CAAOQ,IAAI,CAACC,GAAG,CAACC,IAAI,EAAE,sBAAA;AAAwB,SAAA,CAAA;AAE1E,IAAA,CAAA,CAAE,OAAM;;;AAGN,QAAA;AACF,I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OAAO,CAAA,EACrC;AACA,YAAA;AACF,QAAA;AAEA,QAAA,MAAMY,UAAUC,KAAAA,CAAM7C,gBAAAA,CAAiBoC,aAAAA,EAAerB,GAAAA,CAAIiB,OAAO,CAAA,EAAGtC,YAAAA,CAAAA;QACpEmB,MAAAA,CAAOoB,GAAG,CAAC,kBAAA,EAAoBR,GAAAA,CAAAA;AAC/BqB,QAAAA,OAAAA,CAAQC,GAAG,CAACH,OAAAA,CAAAA;AACd,IAAA,CAAA;;AAGA,IAAA,IAAII,GAAAA,CAAIC,IAAI,CAAC,oCAAA,EAAsC,KAAA,CAAA,EAAQ;QACzDrC,MAAAA,CAAOmC,GAAG,CAACG,IAAI,CACb,uIAAA,CAAA;AAEJ,IAAA;IAEA,IAAI,CAACtC,OAAOC,MAAM,CAACe,GAAG,CAAC,+BAAA,CAAA,IAAoC,CAACf,MAAAA,EAAQ;AAClE,QAAA;AACF,IAAA;IAEAqB,OAAAA,CAAQzC,cAAAA,CAAAA;AACR8B,IAAAA,WAAAA,CAAY/B;AACd;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/core",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.49.0",
|
|
4
4
|
"description": "Core of Strapi",
|
|
5
5
|
"homepage": "https://strapi.io",
|
|
6
6
|
"bugs": {
|
|
@@ -61,15 +61,15 @@
|
|
|
61
61
|
"@koa/router": "12.0.2",
|
|
62
62
|
"@modelcontextprotocol/sdk": "1.29.0",
|
|
63
63
|
"@paralleldrive/cuid2": "2.2.2",
|
|
64
|
-
"@strapi/admin": "5.
|
|
65
|
-
"@strapi/database": "5.
|
|
66
|
-
"@strapi/generators": "5.
|
|
67
|
-
"@strapi/logger": "5.
|
|
68
|
-
"@strapi/openapi": "5.
|
|
69
|
-
"@strapi/permissions": "5.
|
|
70
|
-
"@strapi/types": "5.
|
|
71
|
-
"@strapi/typescript-utils": "5.
|
|
72
|
-
"@strapi/utils": "5.
|
|
64
|
+
"@strapi/admin": "5.49.0",
|
|
65
|
+
"@strapi/database": "5.49.0",
|
|
66
|
+
"@strapi/generators": "5.49.0",
|
|
67
|
+
"@strapi/logger": "5.49.0",
|
|
68
|
+
"@strapi/openapi": "5.49.0",
|
|
69
|
+
"@strapi/permissions": "5.49.0",
|
|
70
|
+
"@strapi/types": "5.49.0",
|
|
71
|
+
"@strapi/typescript-utils": "5.49.0",
|
|
72
|
+
"@strapi/utils": "5.49.0",
|
|
73
73
|
"@vercel/stega": "0.1.2",
|
|
74
74
|
"bcryptjs": "2.4.3",
|
|
75
75
|
"boxen": "5.1.2",
|
|
@@ -105,14 +105,14 @@
|
|
|
105
105
|
"node-schedule": "2.1.1",
|
|
106
106
|
"open": "8.4.2",
|
|
107
107
|
"ora": "5.4.1",
|
|
108
|
-
"package-json": "
|
|
108
|
+
"package-json": "10.0.1",
|
|
109
109
|
"pkg-up": "3.1.0",
|
|
110
110
|
"qs": "6.15.2",
|
|
111
111
|
"resolve.exports": "2.0.2",
|
|
112
112
|
"semver": "7.7.4",
|
|
113
113
|
"statuses": "2.0.1",
|
|
114
114
|
"typescript": "5.4.5",
|
|
115
|
-
"undici": "6.
|
|
115
|
+
"undici": "6.27.0",
|
|
116
116
|
"yup": "0.32.9",
|
|
117
117
|
"zod": "3.25.67"
|
|
118
118
|
},
|
|
@@ -136,11 +136,11 @@
|
|
|
136
136
|
"@types/node": "24.10.0",
|
|
137
137
|
"@types/node-schedule": "2.1.7",
|
|
138
138
|
"@types/statuses": "2.0.1",
|
|
139
|
-
"eslint-config-custom": "5.
|
|
139
|
+
"eslint-config-custom": "5.49.0",
|
|
140
140
|
"supertest": "7.2.2",
|
|
141
|
-
"tsconfig": "5.
|
|
141
|
+
"tsconfig": "5.49.0",
|
|
142
142
|
"vitest": "catalog:",
|
|
143
|
-
"vitest-config": "5.
|
|
143
|
+
"vitest-config": "5.49.0"
|
|
144
144
|
},
|
|
145
145
|
"engines": {
|
|
146
146
|
"node": ">=20.0.0 <=26.x.x",
|