@strapi/strapi 4.3.0-beta.2 → 4.3.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/bin/strapi.js +12 -11
- package/lib/Strapi.js +4 -2
- package/lib/commands/{content-types → ts}/generate-types.js +7 -1
- package/lib/core/domain/content-type/validator.js +29 -8
- package/lib/services/cron.js +7 -3
- package/lib/services/webhook-runner.js +1 -1
- package/lib/types/core/strapi/index.d.ts +21 -0
- package/lib/types/factories.d.ts +15 -7
- package/lib/utils/machine-id.js +2 -2
- package/package.json +18 -18
package/bin/strapi.js
CHANGED
|
@@ -213,17 +213,6 @@ program
|
|
|
213
213
|
.description('List all the application content-types')
|
|
214
214
|
.action(getLocalScript('content-types/list'));
|
|
215
215
|
|
|
216
|
-
program
|
|
217
|
-
.command('content-types:generate-types')
|
|
218
|
-
.description('Generate TypeScript typings for the content-types')
|
|
219
|
-
.option(
|
|
220
|
-
'-o, --out-dir <outDir>',
|
|
221
|
-
'Specify a relative directory in which the schemas definitions will be generated'
|
|
222
|
-
)
|
|
223
|
-
.option('-f, --file <file>', 'Specify a filename to store the schemas definitions')
|
|
224
|
-
.option('--verbose', `Display more information about the types generation`, false)
|
|
225
|
-
.action(getLocalScript('content-types/generate-types'));
|
|
226
|
-
|
|
227
216
|
program
|
|
228
217
|
.command('hooks:list')
|
|
229
218
|
.description('List all the application hooks')
|
|
@@ -251,4 +240,16 @@ program
|
|
|
251
240
|
.description('Enable anonymous telemetry and metadata sending to Strapi analytics')
|
|
252
241
|
.action(getLocalScript('opt-in-telemetry'));
|
|
253
242
|
|
|
243
|
+
program
|
|
244
|
+
.command('ts:generate-types')
|
|
245
|
+
.description(`Generate TypeScript typings for your schemas`)
|
|
246
|
+
.option(
|
|
247
|
+
'-o, --out-dir <outDir>',
|
|
248
|
+
'Specify a relative directory in which the schemas definitions will be generated'
|
|
249
|
+
)
|
|
250
|
+
.option('-f, --file <file>', 'Specify a filename to store the schemas definitions')
|
|
251
|
+
.option('--verbose', `Display more information about the types generation`, false)
|
|
252
|
+
.option('-s, --silent', `Run the generation silently, without any output`, false)
|
|
253
|
+
.action(getLocalScript('ts/generate-types'));
|
|
254
|
+
|
|
254
255
|
program.parseAsync(process.argv);
|
package/lib/Strapi.js
CHANGED
|
@@ -405,8 +405,10 @@ class Strapi {
|
|
|
405
405
|
entityValidator: this.entityValidator,
|
|
406
406
|
});
|
|
407
407
|
|
|
408
|
-
|
|
409
|
-
|
|
408
|
+
if (strapi.config.get('server.cron.enabled', true)) {
|
|
409
|
+
const cronTasks = this.config.get('server.cron.tasks', {});
|
|
410
|
+
this.cron.add(cronTasks);
|
|
411
|
+
}
|
|
410
412
|
|
|
411
413
|
this.telemetry.bootstrap();
|
|
412
414
|
|
|
@@ -4,7 +4,12 @@ const tsUtils = require('@strapi/typescript-utils');
|
|
|
4
4
|
|
|
5
5
|
const strapi = require('../../index');
|
|
6
6
|
|
|
7
|
-
module.exports = async function({ outDir, file, verbose }) {
|
|
7
|
+
module.exports = async function({ outDir, file, verbose, silent }) {
|
|
8
|
+
if (verbose && silent) {
|
|
9
|
+
console.error('You cannot enable verbose and silent flags at the same time, exiting...');
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
|
|
8
13
|
const appContext = await strapi.compile();
|
|
9
14
|
const app = await strapi(appContext).register();
|
|
10
15
|
|
|
@@ -14,6 +19,7 @@ module.exports = async function({ outDir, file, verbose }) {
|
|
|
14
19
|
file,
|
|
15
20
|
dirs: appContext,
|
|
16
21
|
verbose,
|
|
22
|
+
silent,
|
|
17
23
|
});
|
|
18
24
|
|
|
19
25
|
app.destroy();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const _ = require('lodash');
|
|
4
|
-
const { yup, toRegressedEnumValue
|
|
4
|
+
const { yup, toRegressedEnumValue } = require('@strapi/utils');
|
|
5
5
|
|
|
6
6
|
const LIFECYCLES = [
|
|
7
7
|
'beforeCreate',
|
|
@@ -24,6 +24,20 @@ const LIFECYCLES = [
|
|
|
24
24
|
'afterDeleteMany',
|
|
25
25
|
];
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* For enumerations the least common denomiator is GraphQL, where
|
|
29
|
+
* values needs to match the secure name regex:
|
|
30
|
+
* GraphQL Spec https://spec.graphql.org/June2018/#sec-Names
|
|
31
|
+
*
|
|
32
|
+
* Therefore we need to make sure our users only use values, which
|
|
33
|
+
* can be returned by GraphQL, by checking the regressed values
|
|
34
|
+
* agains the GraphQL regex.
|
|
35
|
+
*
|
|
36
|
+
* TODO V5: check if we can avoid this coupling by moving this logic
|
|
37
|
+
* into the GraphQL plugin.
|
|
38
|
+
*/
|
|
39
|
+
const GRAPHQL_ENUM_REGEX = new RegExp('^[_A-Za-z][_0-9A-Za-z]*$');
|
|
40
|
+
|
|
27
41
|
const lifecyclesShape = _.mapValues(_.keyBy(LIFECYCLES), () =>
|
|
28
42
|
yup
|
|
29
43
|
.mixed()
|
|
@@ -54,22 +68,29 @@ const contentTypeSchemaValidator = yup.object().shape({
|
|
|
54
68
|
for (const attrName in attributes) {
|
|
55
69
|
const attr = attributes[attrName];
|
|
56
70
|
if (attr.type === 'enumeration') {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
71
|
+
const regressedValues = attr.enum.map(toRegressedEnumValue);
|
|
72
|
+
|
|
73
|
+
// should match the GraphQL regex
|
|
74
|
+
if (!regressedValues.every(value => GRAPHQL_ENUM_REGEX.test(value))) {
|
|
75
|
+
const message = `Invalid enumeration value. Values should have at least one alphabetical character preceeding the first occurence of a number. Update your enumeration '${attrName}'.`;
|
|
60
76
|
|
|
61
77
|
return this.createError({ message });
|
|
62
78
|
}
|
|
63
79
|
|
|
80
|
+
// should not contain empty values
|
|
81
|
+
if (regressedValues.some(value => value === '')) {
|
|
82
|
+
return this.createError({
|
|
83
|
+
message: `At least one value of the enumeration '${attrName}' appears to be empty. Only alphanumerical characters are taken into account.`,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
64
87
|
// should not collide
|
|
65
88
|
const duplicates = _.uniq(
|
|
66
|
-
|
|
67
|
-
.map(toRegressedEnumValue)
|
|
68
|
-
.filter((value, index, values) => values.indexOf(value) !== index)
|
|
89
|
+
regressedValues.filter((value, index, values) => values.indexOf(value) !== index)
|
|
69
90
|
);
|
|
70
91
|
|
|
71
92
|
if (duplicates.length) {
|
|
72
|
-
const message = `Some
|
|
93
|
+
const message = `Some enumeration values of the field '${attrName}' collide when normalized: ${duplicates.join(
|
|
73
94
|
', '
|
|
74
95
|
)}. Please modify your enumeration.`;
|
|
75
96
|
|
package/lib/services/cron.js
CHANGED
|
@@ -5,6 +5,7 @@ const { isFunction } = require('lodash/fp');
|
|
|
5
5
|
|
|
6
6
|
const createCronService = () => {
|
|
7
7
|
let jobsSpecs = [];
|
|
8
|
+
let running = false;
|
|
8
9
|
|
|
9
10
|
return {
|
|
10
11
|
add(tasks = {}) {
|
|
@@ -29,18 +30,21 @@ const createCronService = () => {
|
|
|
29
30
|
|
|
30
31
|
const job = new Job(null, fnWithStrapi);
|
|
31
32
|
jobsSpecs.push({ job, options });
|
|
33
|
+
|
|
34
|
+
if (running) {
|
|
35
|
+
job.schedule(options);
|
|
36
|
+
}
|
|
32
37
|
}
|
|
33
38
|
return this;
|
|
34
39
|
},
|
|
35
40
|
start() {
|
|
36
|
-
if (!strapi.config.get('server.cron.enabled')) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
41
|
jobsSpecs.forEach(({ job, options }) => job.schedule(options));
|
|
42
|
+
running = true;
|
|
40
43
|
return this;
|
|
41
44
|
},
|
|
42
45
|
stop() {
|
|
43
46
|
jobsSpecs.forEach(({ job }) => job.cancel());
|
|
47
|
+
running = false;
|
|
44
48
|
return this;
|
|
45
49
|
},
|
|
46
50
|
destroy() {
|
|
@@ -29,7 +29,7 @@ class WebhookRunner {
|
|
|
29
29
|
|
|
30
30
|
this.config = _.merge(defaultConfiguration, configuration);
|
|
31
31
|
|
|
32
|
-
this.queue = new WorkerQueue({ logger,
|
|
32
|
+
this.queue = new WorkerQueue({ logger, concurrency: 5 });
|
|
33
33
|
this.queue.subscribe(this.executeListener.bind(this));
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type Koa from 'koa';
|
|
2
|
+
import { Database } from '@strapi/database';
|
|
2
3
|
|
|
3
4
|
import type { StringMap } from './utils';
|
|
4
5
|
import type { GenericController } from '../core-api/controller'
|
|
@@ -335,6 +336,26 @@ export interface Strapi {
|
|
|
335
336
|
* Telemetry util used to collect anonymous data on the application usage
|
|
336
337
|
*/
|
|
337
338
|
telemetry: any;
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Strapi DB layer instance
|
|
342
|
+
*/
|
|
343
|
+
db: Database;
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Core Store accessor
|
|
347
|
+
*/
|
|
348
|
+
store: any;
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Entity Validator instance
|
|
352
|
+
*/
|
|
353
|
+
entityValidator: any;
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Entity Service instance
|
|
357
|
+
*/
|
|
358
|
+
entityService: any;
|
|
338
359
|
}
|
|
339
360
|
|
|
340
361
|
export interface Lifecycles {
|
package/lib/types/factories.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Service } from '../core-api/service';
|
|
|
2
2
|
import { Controller, GenericController } from '../core-api/controller';
|
|
3
3
|
import { Middleware } from '../middlewares';
|
|
4
4
|
import { Policy } from '../core/registries/policies';
|
|
5
|
-
import { Strapi } from '@strapi/strapi'
|
|
5
|
+
import { Strapi } from '@strapi/strapi';
|
|
6
6
|
|
|
7
7
|
type ControllerConfig<T extends Controller = Controller> = T;
|
|
8
8
|
|
|
@@ -10,8 +10,8 @@ type ServiceConfig = Service;
|
|
|
10
10
|
|
|
11
11
|
type HandlerConfig = {
|
|
12
12
|
auth?: false | { scope: string[] };
|
|
13
|
-
policies?: Array<string | Policy>;
|
|
14
|
-
middlewares?: Array<string | Middleware>;
|
|
13
|
+
policies?: Array<string | Policy | { name: string; config: object }>;
|
|
14
|
+
middlewares?: Array<string | Middleware | { name: string; config: object }>;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
type SingleTypeRouterConfig = {
|
|
@@ -44,9 +44,17 @@ interface Router {
|
|
|
44
44
|
routes: Route[];
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
type ControllerCallback
|
|
48
|
-
|
|
47
|
+
type ControllerCallback<T extends GenericController = GenericController> = (params: {
|
|
48
|
+
strapi: Strapi;
|
|
49
|
+
}) => T;
|
|
50
|
+
type ServiceCallback<T extends Service = Service> = (params: { strapi: Strapi }) => T;
|
|
49
51
|
|
|
50
52
|
export function createCoreRouter(uid: string, cfg?: RouterConfig = {}): () => Router;
|
|
51
|
-
export function createCoreController<T extends GenericController = GenericController>(
|
|
52
|
-
|
|
53
|
+
export function createCoreController<T extends GenericController = GenericController>(
|
|
54
|
+
uid: string,
|
|
55
|
+
cfg?: ControllerCallback<T> | T = {}
|
|
56
|
+
): () => T & Controller;
|
|
57
|
+
export function createCoreService<T extends Service = Service>(
|
|
58
|
+
uid: string,
|
|
59
|
+
cfg?: ServiceCallback<T> | T = {}
|
|
60
|
+
): () => T;
|
package/lib/utils/machine-id.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const { machineIdSync } = require('node-machine-id');
|
|
4
|
-
const
|
|
4
|
+
const { v4: uuidv4 } = require('uuid');
|
|
5
5
|
|
|
6
6
|
module.exports = () => {
|
|
7
7
|
try {
|
|
8
8
|
const deviceId = machineIdSync();
|
|
9
9
|
return deviceId;
|
|
10
10
|
} catch (error) {
|
|
11
|
-
const deviceId =
|
|
11
|
+
const deviceId = uuidv4();
|
|
12
12
|
return deviceId;
|
|
13
13
|
}
|
|
14
14
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/strapi",
|
|
3
|
-
"version": "4.3.0
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MySQL, MariaDB, PostgreSQL, SQLite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -80,23 +80,23 @@
|
|
|
80
80
|
"dependencies": {
|
|
81
81
|
"@koa/cors": "3.1.0",
|
|
82
82
|
"@koa/router": "10.1.1",
|
|
83
|
-
"@strapi/admin": "4.3.0
|
|
84
|
-
"@strapi/database": "4.3.0
|
|
85
|
-
"@strapi/generate-new": "4.3.0
|
|
86
|
-
"@strapi/generators": "4.3.0
|
|
87
|
-
"@strapi/logger": "4.3.0
|
|
88
|
-
"@strapi/plugin-content-manager": "4.3.0
|
|
89
|
-
"@strapi/plugin-content-type-builder": "4.3.0
|
|
90
|
-
"@strapi/plugin-email": "4.3.0
|
|
91
|
-
"@strapi/plugin-upload": "4.3.0
|
|
92
|
-
"@strapi/typescript-utils": "4.3.0
|
|
93
|
-
"@strapi/utils": "4.3.0
|
|
83
|
+
"@strapi/admin": "4.3.0",
|
|
84
|
+
"@strapi/database": "4.3.0",
|
|
85
|
+
"@strapi/generate-new": "4.3.0",
|
|
86
|
+
"@strapi/generators": "4.3.0",
|
|
87
|
+
"@strapi/logger": "4.3.0",
|
|
88
|
+
"@strapi/plugin-content-manager": "4.3.0",
|
|
89
|
+
"@strapi/plugin-content-type-builder": "4.3.0",
|
|
90
|
+
"@strapi/plugin-email": "4.3.0",
|
|
91
|
+
"@strapi/plugin-upload": "4.3.0",
|
|
92
|
+
"@strapi/typescript-utils": "4.3.0",
|
|
93
|
+
"@strapi/utils": "4.3.0",
|
|
94
94
|
"bcryptjs": "2.4.3",
|
|
95
95
|
"boxen": "5.1.2",
|
|
96
96
|
"chalk": "4.1.2",
|
|
97
97
|
"chokidar": "3.5.2",
|
|
98
98
|
"ci-info": "3.2.0",
|
|
99
|
-
"cli-table3": "0.6.
|
|
99
|
+
"cli-table3": "0.6.2",
|
|
100
100
|
"commander": "8.2.0",
|
|
101
101
|
"configstore": "5.0.1",
|
|
102
102
|
"debug": "4.3.2",
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
"http-errors": "1.8.1",
|
|
109
109
|
"inquirer": "8.2.4",
|
|
110
110
|
"is-docker": "2.2.1",
|
|
111
|
-
"koa": "2.13.
|
|
111
|
+
"koa": "2.13.4",
|
|
112
112
|
"koa-body": "4.2.0",
|
|
113
113
|
"koa-compose": "4.1.0",
|
|
114
114
|
"koa-compress": "5.1.0",
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
"mime-types": "2.1.35",
|
|
122
122
|
"node-fetch": "2.6.7",
|
|
123
123
|
"node-machine-id": "1.1.12",
|
|
124
|
-
"node-schedule": "2.
|
|
124
|
+
"node-schedule": "2.1.0",
|
|
125
125
|
"open": "8.4.0",
|
|
126
126
|
"ora": "5.4.1",
|
|
127
127
|
"package-json": "7.0.0",
|
|
@@ -129,15 +129,15 @@
|
|
|
129
129
|
"resolve-cwd": "3.0.0",
|
|
130
130
|
"semver": "7.3.7",
|
|
131
131
|
"statuses": "2.0.1",
|
|
132
|
-
"uuid": "^
|
|
132
|
+
"uuid": "^8.3.2"
|
|
133
133
|
},
|
|
134
134
|
"devDependencies": {
|
|
135
|
-
"supertest": "
|
|
135
|
+
"supertest": "6.2.4",
|
|
136
136
|
"typescript": "4.6.2"
|
|
137
137
|
},
|
|
138
138
|
"engines": {
|
|
139
139
|
"node": ">=14.19.1 <=16.x.x",
|
|
140
140
|
"npm": ">=6.0.0"
|
|
141
141
|
},
|
|
142
|
-
"gitHead": "
|
|
142
|
+
"gitHead": "74a2b908df75bc8001d72f9dc8571c4b7a2da337"
|
|
143
143
|
}
|