@strapi/strapi 0.0.0-e4d1f4d78c → 0.0.0-ee00599cd73180e84df84536521183b48892a28c
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/README.md +18 -9
- package/lib/commands/configurationDump.js +2 -2
- package/lib/core/loaders/apis.js +1 -1
- package/lib/core/loaders/plugins/get-enabled-plugins.js +3 -1
- package/lib/core/loaders/plugins/index.js +5 -5
- package/lib/core/registries/content-types.js +2 -2
- package/lib/core/registries/controllers.js +2 -2
- package/lib/core/registries/hooks.js +1 -1
- package/lib/core/registries/middlewares.js +2 -2
- package/lib/core/registries/policies.js +1 -1
- package/lib/core/registries/services.js +2 -2
- package/lib/core-api/controller/transform.js +1 -1
- package/lib/core-api/service/index.d.ts +6 -3
- package/lib/middlewares/body.js +9 -2
- package/lib/middlewares/cors.js +1 -1
- package/lib/middlewares/security.js +22 -16
- package/lib/services/cron.js +1 -1
- package/lib/services/entity-service/components.js +28 -8
- package/lib/services/entity-service/index.js +21 -2
- package/lib/services/entity-validator/index.js +22 -17
- package/lib/services/metrics/middleware.js +1 -1
- package/lib/services/metrics/sender.js +2 -2
- package/lib/services/server/register-routes.js +2 -2
- package/lib/services/utils/upload-files.js +1 -1
- package/lib/services/worker-queue.js +2 -2
- package/lib/types/core/strapi/index.d.ts +4 -3
- package/lib/types/factories.d.ts +3 -3
- package/lib/utils/addSlash.js +6 -5
- package/package.json +15 -15
package/README.md
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<a href="https://strapi.io">
|
|
2
|
+
<a href="https://strapi.io/#gh-light-mode-only">
|
|
3
3
|
<img src="https://strapi.io/assets/strapi-logo-dark.svg" width="318px" alt="Strapi logo" />
|
|
4
4
|
</a>
|
|
5
|
+
<a href="https://strapi.io/#gh-dark-mode-only">
|
|
6
|
+
<img src="https://strapi.io/assets/strapi-logo-light.svg" width="318px" alt="Strapi logo" />
|
|
7
|
+
</a>
|
|
5
8
|
</p>
|
|
9
|
+
|
|
6
10
|
<h3 align="center">API creation made simple, secure and fast.</h3>
|
|
7
11
|
<p align="center">The most advanced open-source headless CMS to build powerful APIs with no effort.</p>
|
|
8
12
|
<p align="center"><a href="https://strapi.io/demo">Try live demo</a></p>
|
|
@@ -13,11 +17,14 @@
|
|
|
13
17
|
<img src="https://img.shields.io/npm/v/@strapi/strapi/latest.svg" alt="NPM Version" />
|
|
14
18
|
</a>
|
|
15
19
|
<a href="https://github.com/strapi/strapi/actions/workflows/tests.yml">
|
|
16
|
-
<img src="https://github.com/strapi/strapi/actions/workflows/tests.yml/badge.svg?branch=
|
|
20
|
+
<img src="https://github.com/strapi/strapi/actions/workflows/tests.yml/badge.svg?branch=main" alt="Tests" />
|
|
17
21
|
</a>
|
|
18
22
|
<a href="https://discord.strapi.io">
|
|
19
23
|
<img src="https://img.shields.io/discord/811989166782021633?label=Discord" alt="Strapi on Discord" />
|
|
20
24
|
</a>
|
|
25
|
+
<a href="https://github.com/strapi/strapi/actions/workflows/nightly.yml">
|
|
26
|
+
<img src="https://github.com/strapi/strapi/actions/workflows/nightly.yml/badge.svg" alt="Strapi Nightly Release Build Status" />
|
|
27
|
+
</a>
|
|
21
28
|
</p>
|
|
22
29
|
|
|
23
30
|
<br>
|
|
@@ -79,15 +86,17 @@ Complete installation requirements can be found in the documentation under <a hr
|
|
|
79
86
|
|
|
80
87
|
**Node:**
|
|
81
88
|
|
|
82
|
-
- NodeJS >=
|
|
89
|
+
- NodeJS >= 14 <= 18
|
|
83
90
|
- NPM >= 6.x
|
|
84
91
|
|
|
85
92
|
**Database:**
|
|
86
93
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
94
|
+
| Database | Minimum | Recommended |
|
|
95
|
+
| ---------- | ------- | ----------- |
|
|
96
|
+
| MySQL | 5.7.8 | 8.0 |
|
|
97
|
+
| MariaDB | 10.3 | 10.6 |
|
|
98
|
+
| PostgreSQL | 11.0 | 14.0 |
|
|
99
|
+
| SQLite | 3 | 3 |
|
|
91
100
|
|
|
92
101
|
**We recommend always using the latest version of Strapi to start your new projects**.
|
|
93
102
|
|
|
@@ -114,7 +123,7 @@ For general help using Strapi, please refer to [the official Strapi documentatio
|
|
|
114
123
|
- [Discord](https://discord.strapi.io) (For live discussion with the Community and Strapi team)
|
|
115
124
|
- [GitHub](https://github.com/strapi/strapi) (Bug reports, Contributions)
|
|
116
125
|
- [Community Forum](https://forum.strapi.io) (Questions and Discussions)
|
|
117
|
-
- [
|
|
126
|
+
- [Feedback section](https://feedback.strapi.io) (Roadmap, Feature requests)
|
|
118
127
|
- [Twitter](https://twitter.com/strapijs) (Get the news fast)
|
|
119
128
|
- [Facebook](https://www.facebook.com/Strapi-616063331867161)
|
|
120
129
|
- [YouTube Channel](https://www.youtube.com/strapi) (Learn from Video Tutorials)
|
|
@@ -125,7 +134,7 @@ Follow our [migration guides](https://docs.strapi.io/developer-docs/latest/updat
|
|
|
125
134
|
|
|
126
135
|
## Roadmap
|
|
127
136
|
|
|
128
|
-
Check out our [roadmap](https://feedback.strapi.io
|
|
137
|
+
Check out our [roadmap](https://feedback.strapi.io) to get informed of the latest features released and the upcoming ones. You may also give us insights and vote for a specific feature.
|
|
129
138
|
|
|
130
139
|
## Documentation
|
|
131
140
|
|
|
@@ -9,7 +9,7 @@ const CHUNK_SIZE = 100;
|
|
|
9
9
|
* Will dump configurations to a file or stdout
|
|
10
10
|
* @param {string} file filepath to use as output
|
|
11
11
|
*/
|
|
12
|
-
module.exports = async
|
|
12
|
+
module.exports = async ({ file: filePath, pretty }) => {
|
|
13
13
|
const output = filePath ? fs.createWriteStream(filePath) : process.stdout;
|
|
14
14
|
|
|
15
15
|
const appContext = await strapi.compile();
|
|
@@ -21,7 +21,7 @@ module.exports = async function ({ file: filePath, pretty }) {
|
|
|
21
21
|
|
|
22
22
|
const pageCount = Math.ceil(count / CHUNK_SIZE);
|
|
23
23
|
|
|
24
|
-
for (let page = 0; page < pageCount; page
|
|
24
|
+
for (let page = 0; page < pageCount; page += 1) {
|
|
25
25
|
const results = await app
|
|
26
26
|
.query('strapi::core-store')
|
|
27
27
|
.findMany({ limit: CHUNK_SIZE, offset: page * CHUNK_SIZE, orderBy: 'key' });
|
package/lib/core/loaders/apis.js
CHANGED
|
@@ -59,7 +59,9 @@ const getEnabledPlugins = async (strapi) => {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
const installedPlugins = {};
|
|
62
|
-
|
|
62
|
+
const dependencies = strapi.config.get('info.dependencies', {});
|
|
63
|
+
|
|
64
|
+
for (const dep of Object.keys(dependencies)) {
|
|
63
65
|
const packagePath = join(dep, 'package.json');
|
|
64
66
|
let packageInfo;
|
|
65
67
|
try {
|
|
@@ -34,10 +34,10 @@ const applyUserExtension = async (plugins) => {
|
|
|
34
34
|
const extendedSchemas = await loadFiles(extensionsDir, '**/content-types/**/schema.json');
|
|
35
35
|
const strapiServers = await loadFiles(extensionsDir, '**/strapi-server.js');
|
|
36
36
|
|
|
37
|
-
for (const pluginName
|
|
37
|
+
for (const pluginName of Object.keys(plugins)) {
|
|
38
38
|
const plugin = plugins[pluginName];
|
|
39
39
|
// first: load json schema
|
|
40
|
-
for (const ctName
|
|
40
|
+
for (const ctName of Object.keys(plugin.contentTypes)) {
|
|
41
41
|
const extendedSchema = get([pluginName, 'content-types', ctName, 'schema'], extendedSchemas);
|
|
42
42
|
if (extendedSchema) {
|
|
43
43
|
plugin.contentTypes[ctName].schema = {
|
|
@@ -57,7 +57,7 @@ const applyUserExtension = async (plugins) => {
|
|
|
57
57
|
const applyUserConfig = async (plugins) => {
|
|
58
58
|
const userPluginsConfig = await getUserPluginsConfig();
|
|
59
59
|
|
|
60
|
-
for (const pluginName
|
|
60
|
+
for (const pluginName of Object.keys(plugins)) {
|
|
61
61
|
const plugin = plugins[pluginName];
|
|
62
62
|
const userPluginConfig = getOr({}, `${pluginName}.config`, userPluginsConfig);
|
|
63
63
|
const defaultConfig =
|
|
@@ -82,7 +82,7 @@ const loadPlugins = async (strapi) => {
|
|
|
82
82
|
|
|
83
83
|
strapi.config.set('enabledPlugins', enabledPlugins);
|
|
84
84
|
|
|
85
|
-
for (const pluginName
|
|
85
|
+
for (const pluginName of Object.keys(enabledPlugins)) {
|
|
86
86
|
const enabledPlugin = enabledPlugins[pluginName];
|
|
87
87
|
|
|
88
88
|
const serverEntrypointPath = join(enabledPlugin.pathToPlugin, 'strapi-server.js');
|
|
@@ -100,7 +100,7 @@ const loadPlugins = async (strapi) => {
|
|
|
100
100
|
await applyUserConfig(plugins);
|
|
101
101
|
await applyUserExtension(plugins);
|
|
102
102
|
|
|
103
|
-
for (const pluginName
|
|
103
|
+
for (const pluginName of Object.keys(plugins)) {
|
|
104
104
|
strapi.container.get('plugins').add(pluginName, plugins[pluginName]);
|
|
105
105
|
}
|
|
106
106
|
};
|
|
@@ -5,7 +5,7 @@ const { createContentType } = require('../domain/content-type');
|
|
|
5
5
|
const { addNamespace, hasNamespace } = require('../utils');
|
|
6
6
|
|
|
7
7
|
const validateKeySameToSingularName = (contentTypes) => {
|
|
8
|
-
for (const ctName
|
|
8
|
+
for (const ctName of Object.keys(contentTypes)) {
|
|
9
9
|
const contentType = contentTypes[ctName];
|
|
10
10
|
|
|
11
11
|
if (ctName !== contentType.schema.info.singularName) {
|
|
@@ -63,7 +63,7 @@ const contentTypesRegistry = () => {
|
|
|
63
63
|
add(namespace, newContentTypes) {
|
|
64
64
|
validateKeySameToSingularName(newContentTypes);
|
|
65
65
|
|
|
66
|
-
for (const rawCtName
|
|
66
|
+
for (const rawCtName of Object.keys(newContentTypes)) {
|
|
67
67
|
const uid = addNamespace(rawCtName, namespace);
|
|
68
68
|
|
|
69
69
|
if (has(uid, contentTypes)) {
|
|
@@ -48,7 +48,7 @@ const controllersRegistry = () => {
|
|
|
48
48
|
const filteredControllers = pickBy((_, uid) => hasNamespace(uid, namespace))(controllers);
|
|
49
49
|
|
|
50
50
|
const map = {};
|
|
51
|
-
for (const uid
|
|
51
|
+
for (const uid of Object.keys(filteredControllers)) {
|
|
52
52
|
Object.defineProperty(map, uid, {
|
|
53
53
|
enumerable: true,
|
|
54
54
|
get: () => {
|
|
@@ -78,7 +78,7 @@ const controllersRegistry = () => {
|
|
|
78
78
|
* @returns
|
|
79
79
|
*/
|
|
80
80
|
add(namespace, newControllers) {
|
|
81
|
-
for (const controllerName
|
|
81
|
+
for (const controllerName of Object.keys(newControllers)) {
|
|
82
82
|
const controller = newControllers[controllerName];
|
|
83
83
|
const uid = addNamespace(controllerName, namespace);
|
|
84
84
|
|
|
@@ -54,8 +54,8 @@ const middlewaresRegistry = () => {
|
|
|
54
54
|
* @param {{ [key: string]: Middleware }} newMiddlewares
|
|
55
55
|
* @returns
|
|
56
56
|
*/
|
|
57
|
-
add(namespace, rawMiddlewares) {
|
|
58
|
-
for (const middlewareName
|
|
57
|
+
add(namespace, rawMiddlewares = {}) {
|
|
58
|
+
for (const middlewareName of Object.keys(rawMiddlewares)) {
|
|
59
59
|
const middleware = rawMiddlewares[middlewareName];
|
|
60
60
|
const uid = addNamespace(middlewareName, namespace);
|
|
61
61
|
|
|
@@ -55,7 +55,7 @@ const policiesRegistry = () => {
|
|
|
55
55
|
* @returns
|
|
56
56
|
*/
|
|
57
57
|
add(namespace, newPolicies) {
|
|
58
|
-
for (const policyName
|
|
58
|
+
for (const policyName of Object.keys(newPolicies)) {
|
|
59
59
|
const policy = newPolicies[policyName];
|
|
60
60
|
const uid = addNamespace(policyName, namespace);
|
|
61
61
|
|
|
@@ -48,7 +48,7 @@ const servicesRegistry = (strapi) => {
|
|
|
48
48
|
|
|
49
49
|
// create lazy accessor to avoid instantiating the services;
|
|
50
50
|
const map = {};
|
|
51
|
-
for (const uid
|
|
51
|
+
for (const uid of Object.keys(filteredServices)) {
|
|
52
52
|
Object.defineProperty(map, uid, {
|
|
53
53
|
enumerable: true,
|
|
54
54
|
get: () => {
|
|
@@ -78,7 +78,7 @@ const servicesRegistry = (strapi) => {
|
|
|
78
78
|
* @returns
|
|
79
79
|
*/
|
|
80
80
|
add(namespace, newServices) {
|
|
81
|
-
for (const serviceName
|
|
81
|
+
for (const serviceName of Object.keys(newServices)) {
|
|
82
82
|
const service = newServices[serviceName];
|
|
83
83
|
const uid = addNamespace(serviceName, namespace);
|
|
84
84
|
|
|
@@ -12,11 +12,14 @@ export interface SingleTypeService extends BaseService {
|
|
|
12
12
|
|
|
13
13
|
export interface CollectionTypeService extends BaseService {
|
|
14
14
|
find?(params: object): Promise<Entity[]> | Entity;
|
|
15
|
-
findOne?(entityId: string,params: object): Promise<Entity> | Entity;
|
|
15
|
+
findOne?(entityId: string, params: object): Promise<Entity> | Entity;
|
|
16
16
|
create?(params: object): Promise<Entity> | Entity;
|
|
17
|
-
update?(entityId: string,params: object): Promise<Entity> | Entity;
|
|
18
|
-
delete?(entityId: string,params: object): Promise<Entity> | Entity;
|
|
17
|
+
update?(entityId: string, params: object): Promise<Entity> | Entity;
|
|
18
|
+
delete?(entityId: string, params: object): Promise<Entity> | Entity;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export type Service = SingleTypeService | CollectionTypeService;
|
|
22
22
|
|
|
23
|
+
export type GenericService = Partial<Service> & {
|
|
24
|
+
[method: string | number | symbol]: <T = any>(...args: any) => T;
|
|
25
|
+
};
|
package/lib/middlewares/body.js
CHANGED
|
@@ -23,12 +23,19 @@ function getFiles(ctx) {
|
|
|
23
23
|
/**
|
|
24
24
|
* @type {import('./').MiddlewareFactory}
|
|
25
25
|
*/
|
|
26
|
-
|
|
26
|
+
|
|
27
|
+
module.exports = (config, { strapi }) => {
|
|
27
28
|
const bodyConfig = defaultsDeep(defaults, config);
|
|
28
29
|
|
|
30
|
+
let gqlEndpoint;
|
|
31
|
+
if (strapi.plugin('graphql')) {
|
|
32
|
+
const { config: gqlConfig } = strapi.plugin('graphql');
|
|
33
|
+
gqlEndpoint = gqlConfig('endpoint');
|
|
34
|
+
}
|
|
35
|
+
|
|
29
36
|
return async (ctx, next) => {
|
|
30
37
|
// TODO: find a better way later
|
|
31
|
-
if (ctx.url ===
|
|
38
|
+
if (gqlEndpoint && ctx.url === gqlEndpoint) {
|
|
32
39
|
await next();
|
|
33
40
|
} else {
|
|
34
41
|
try {
|
package/lib/middlewares/cors.js
CHANGED
|
@@ -30,22 +30,28 @@ const defaults = {
|
|
|
30
30
|
/**
|
|
31
31
|
* @type {import('./').MiddlewareFactory}
|
|
32
32
|
*/
|
|
33
|
-
module.exports = (config) => (ctx, next) => {
|
|
34
|
-
let helmetConfig = defaultsDeep(defaults, config);
|
|
35
33
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
module.exports =
|
|
35
|
+
(config, { strapi }) =>
|
|
36
|
+
(ctx, next) => {
|
|
37
|
+
let helmetConfig = defaultsDeep(defaults, config);
|
|
38
|
+
const specialPaths = ['/documentation'];
|
|
39
|
+
|
|
40
|
+
if (strapi.plugin('graphql')) {
|
|
41
|
+
const { config: gqlConfig } = strapi.plugin('graphql');
|
|
42
|
+
specialPaths.push(gqlConfig('endpoint'));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (ctx.method === 'GET' && specialPaths.some((str) => ctx.path.startsWith(str))) {
|
|
46
|
+
helmetConfig = merge(helmetConfig, {
|
|
47
|
+
contentSecurityPolicy: {
|
|
48
|
+
directives: {
|
|
49
|
+
'script-src': ["'self'", "'unsafe-inline'", 'cdn.jsdelivr.net'],
|
|
50
|
+
'img-src': ["'self'", 'data:', 'cdn.jsdelivr.net', 'strapi.io'],
|
|
51
|
+
},
|
|
45
52
|
},
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
49
55
|
|
|
50
|
-
|
|
51
|
-
};
|
|
56
|
+
return helmet(helmetConfig)(ctx, next);
|
|
57
|
+
};
|
package/lib/services/cron.js
CHANGED
|
@@ -5,6 +5,7 @@ const { has, prop, omit, toString } = require('lodash/fp');
|
|
|
5
5
|
|
|
6
6
|
const { contentTypes: contentTypesUtils } = require('@strapi/utils');
|
|
7
7
|
const { ApplicationError } = require('@strapi/utils').errors;
|
|
8
|
+
const { getComponentAttributes } = require('@strapi/utils').contentTypes;
|
|
8
9
|
|
|
9
10
|
const omitComponentData = (contentType, data) => {
|
|
10
11
|
const { attributes } = contentType;
|
|
@@ -17,11 +18,11 @@ const omitComponentData = (contentType, data) => {
|
|
|
17
18
|
|
|
18
19
|
// NOTE: we could generalize the logic to allow CRUD of relation directly in the DB layer
|
|
19
20
|
const createComponents = async (uid, data) => {
|
|
20
|
-
const { attributes } = strapi.getModel(uid);
|
|
21
|
+
const { attributes = {} } = strapi.getModel(uid);
|
|
21
22
|
|
|
22
23
|
const componentBody = {};
|
|
23
24
|
|
|
24
|
-
for (const attributeName
|
|
25
|
+
for (const attributeName of Object.keys(attributes)) {
|
|
25
26
|
const attribute = attributes[attributeName];
|
|
26
27
|
|
|
27
28
|
if (!has(attributeName, data) || !contentTypesUtils.isComponentAttribute(attribute)) {
|
|
@@ -100,16 +101,28 @@ const createComponents = async (uid, data) => {
|
|
|
100
101
|
return componentBody;
|
|
101
102
|
};
|
|
102
103
|
|
|
104
|
+
/**
|
|
105
|
+
* @param {str} uid
|
|
106
|
+
* @param {object} entity
|
|
107
|
+
* @return {Promise<{uid: string, entity: object}>}
|
|
108
|
+
*/
|
|
109
|
+
const getComponents = async (uid, entity) => {
|
|
110
|
+
const componentAttributes = getComponentAttributes(strapi.getModel(uid));
|
|
111
|
+
|
|
112
|
+
if (_.isEmpty(componentAttributes)) return {};
|
|
113
|
+
return strapi.query(uid).load(entity, componentAttributes);
|
|
114
|
+
};
|
|
115
|
+
|
|
103
116
|
/*
|
|
104
117
|
delete old components
|
|
105
118
|
create or update
|
|
106
119
|
*/
|
|
107
120
|
const updateComponents = async (uid, entityToUpdate, data) => {
|
|
108
|
-
const { attributes } = strapi.getModel(uid);
|
|
121
|
+
const { attributes = {} } = strapi.getModel(uid);
|
|
109
122
|
|
|
110
123
|
const componentBody = {};
|
|
111
124
|
|
|
112
|
-
for (const attributeName
|
|
125
|
+
for (const attributeName of Object.keys(attributes)) {
|
|
113
126
|
const attribute = attributes[attributeName];
|
|
114
127
|
|
|
115
128
|
if (!has(attributeName, data)) {
|
|
@@ -262,15 +275,18 @@ const deleteOldDZComponents = async (uid, entityToUpdate, attributeName, dynamic
|
|
|
262
275
|
};
|
|
263
276
|
|
|
264
277
|
const deleteComponents = async (uid, entityToDelete) => {
|
|
265
|
-
const { attributes } = strapi.getModel(uid);
|
|
278
|
+
const { attributes = {} } = strapi.getModel(uid);
|
|
266
279
|
|
|
267
|
-
for (const attributeName
|
|
280
|
+
for (const attributeName of Object.keys(attributes)) {
|
|
268
281
|
const attribute = attributes[attributeName];
|
|
269
282
|
|
|
270
283
|
if (attribute.type === 'component') {
|
|
271
284
|
const { component: componentUID } = attribute;
|
|
272
285
|
|
|
273
|
-
|
|
286
|
+
// Load attribute value if it's not already loaded
|
|
287
|
+
const value =
|
|
288
|
+
entityToDelete[attributeName] ||
|
|
289
|
+
(await strapi.query(uid).load(entityToDelete, attributeName));
|
|
274
290
|
|
|
275
291
|
if (!value) {
|
|
276
292
|
continue;
|
|
@@ -286,7 +302,9 @@ const deleteComponents = async (uid, entityToDelete) => {
|
|
|
286
302
|
}
|
|
287
303
|
|
|
288
304
|
if (attribute.type === 'dynamiczone') {
|
|
289
|
-
const value =
|
|
305
|
+
const value =
|
|
306
|
+
entityToDelete[attributeName] ||
|
|
307
|
+
(await strapi.query(uid).load(entityToDelete, attributeName));
|
|
290
308
|
|
|
291
309
|
if (!value) {
|
|
292
310
|
continue;
|
|
@@ -352,7 +370,9 @@ const deleteComponent = async (uid, componentToDelete) => {
|
|
|
352
370
|
|
|
353
371
|
module.exports = {
|
|
354
372
|
omitComponentData,
|
|
373
|
+
getComponents,
|
|
355
374
|
createComponents,
|
|
356
375
|
updateComponents,
|
|
357
376
|
deleteComponents,
|
|
377
|
+
deleteComponent,
|
|
358
378
|
};
|
|
@@ -14,6 +14,7 @@ const uploadFiles = require('../utils/upload-files');
|
|
|
14
14
|
|
|
15
15
|
const {
|
|
16
16
|
omitComponentData,
|
|
17
|
+
getComponents,
|
|
17
18
|
createComponents,
|
|
18
19
|
updateComponents,
|
|
19
20
|
deleteComponents,
|
|
@@ -213,8 +214,10 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
|
|
|
213
214
|
return null;
|
|
214
215
|
}
|
|
215
216
|
|
|
217
|
+
const componentsToDelete = await getComponents(uid, entityToDelete);
|
|
218
|
+
|
|
216
219
|
await db.query(uid).delete({ where: { id: entityToDelete.id } });
|
|
217
|
-
await deleteComponents(uid, entityToDelete);
|
|
220
|
+
await deleteComponents(uid, { ...entityToDelete, ...componentsToDelete });
|
|
218
221
|
|
|
219
222
|
await this.emitEvent(uid, ENTRY_DELETE, entityToDelete);
|
|
220
223
|
|
|
@@ -228,7 +231,23 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
|
|
|
228
231
|
// select / populate
|
|
229
232
|
const query = transformParamsToQuery(uid, wrappedParams);
|
|
230
233
|
|
|
231
|
-
|
|
234
|
+
const entitiesToDelete = await db.query(uid).findMany(query);
|
|
235
|
+
|
|
236
|
+
if (!entitiesToDelete.length) {
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const componentsToDelete = await Promise.all(
|
|
241
|
+
entitiesToDelete.map((entityToDelete) => getComponents(uid, entityToDelete))
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
const deletedEntities = await db.query(uid).deleteMany(query);
|
|
245
|
+
await Promise.all(componentsToDelete.map((compos) => deleteComponents(uid, compos)));
|
|
246
|
+
|
|
247
|
+
// Trigger webhooks. One for each entity
|
|
248
|
+
await Promise.all(entitiesToDelete.map((entity) => this.emitEvent(uid, ENTRY_DELETE, entity)));
|
|
249
|
+
|
|
250
|
+
return deletedEntities;
|
|
232
251
|
},
|
|
233
252
|
|
|
234
253
|
load(uid, entity, field, params = {}) {
|
|
@@ -14,51 +14,56 @@ const { isMediaAttribute, isScalarAttribute, getWritableAttributes } = strapiUti
|
|
|
14
14
|
const { ValidationError } = strapiUtils.errors;
|
|
15
15
|
|
|
16
16
|
const addMinMax = (validator, { attr, updatedAttribute }) => {
|
|
17
|
+
let nextValidator = validator;
|
|
18
|
+
|
|
17
19
|
if (
|
|
18
20
|
Number.isInteger(attr.min) &&
|
|
19
21
|
(attr.required || (Array.isArray(updatedAttribute.value) && updatedAttribute.value.length > 0))
|
|
20
22
|
) {
|
|
21
|
-
|
|
23
|
+
nextValidator = nextValidator.min(attr.min);
|
|
22
24
|
}
|
|
23
25
|
if (Number.isInteger(attr.max)) {
|
|
24
|
-
|
|
26
|
+
nextValidator = nextValidator.max(attr.max);
|
|
25
27
|
}
|
|
26
|
-
return
|
|
28
|
+
return nextValidator;
|
|
27
29
|
};
|
|
28
30
|
|
|
29
|
-
const addRequiredValidation =
|
|
30
|
-
(
|
|
31
|
-
|
|
31
|
+
const addRequiredValidation = (createOrUpdate) => {
|
|
32
|
+
return (validator, { attr: { required } }) => {
|
|
33
|
+
let nextValidator = validator;
|
|
32
34
|
if (required) {
|
|
33
35
|
if (createOrUpdate === 'creation') {
|
|
34
|
-
|
|
36
|
+
nextValidator = nextValidator.notNil();
|
|
35
37
|
} else if (createOrUpdate === 'update') {
|
|
36
|
-
|
|
38
|
+
nextValidator = nextValidator.notNull();
|
|
37
39
|
}
|
|
38
40
|
} else {
|
|
39
|
-
|
|
41
|
+
nextValidator = nextValidator.nullable();
|
|
40
42
|
}
|
|
41
|
-
return
|
|
43
|
+
return nextValidator;
|
|
42
44
|
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const addDefault = (createOrUpdate) => {
|
|
48
|
+
return (validator, { attr }) => {
|
|
49
|
+
let nextValidator = validator;
|
|
43
50
|
|
|
44
|
-
const addDefault =
|
|
45
|
-
(createOrUpdate) =>
|
|
46
|
-
(validator, { attr }) => {
|
|
47
51
|
if (createOrUpdate === 'creation') {
|
|
48
52
|
if (
|
|
49
53
|
((attr.type === 'component' && attr.repeatable) || attr.type === 'dynamiczone') &&
|
|
50
54
|
!attr.required
|
|
51
55
|
) {
|
|
52
|
-
|
|
56
|
+
nextValidator = nextValidator.default([]);
|
|
53
57
|
} else {
|
|
54
|
-
|
|
58
|
+
nextValidator = nextValidator.default(attr.default);
|
|
55
59
|
}
|
|
56
60
|
} else {
|
|
57
|
-
|
|
61
|
+
nextValidator = nextValidator.default(undefined);
|
|
58
62
|
}
|
|
59
63
|
|
|
60
|
-
return
|
|
64
|
+
return nextValidator;
|
|
61
65
|
};
|
|
66
|
+
};
|
|
62
67
|
|
|
63
68
|
const preventCast = (validator) => validator.transform((val, originalVal) => originalVal);
|
|
64
69
|
|
|
@@ -45,12 +45,12 @@ module.exports = (strapi) => {
|
|
|
45
45
|
environment: strapi.config.environment,
|
|
46
46
|
os: os.type(),
|
|
47
47
|
osPlatform: os.platform(),
|
|
48
|
+
osArch: os.arch(),
|
|
48
49
|
osRelease: os.release(),
|
|
49
|
-
nodeVersion: process.
|
|
50
|
+
nodeVersion: process.versions.node,
|
|
50
51
|
docker: process.env.DOCKER || isDocker(),
|
|
51
52
|
isCI: ciEnv.isCI,
|
|
52
53
|
version: strapi.config.get('info.strapi'),
|
|
53
|
-
strapiVersion: strapi.config.get('info.strapi'),
|
|
54
54
|
projectType: isEE ? 'Enterprise' : 'Community',
|
|
55
55
|
useTypescriptOnServer: isUsingTypeScriptSync(serverRootPath),
|
|
56
56
|
useTypescriptOnAdmin: isUsingTypeScriptSync(adminRootPath),
|
|
@@ -50,7 +50,7 @@ const registerAdminRoutes = (strapi) => {
|
|
|
50
50
|
* @param {import('../../').Strapi} strapi
|
|
51
51
|
*/
|
|
52
52
|
const registerPluginRoutes = (strapi) => {
|
|
53
|
-
for (const pluginName
|
|
53
|
+
for (const pluginName of Object.keys(strapi.plugins)) {
|
|
54
54
|
const plugin = strapi.plugins[pluginName];
|
|
55
55
|
|
|
56
56
|
const generateRouteScope = createRouteScopeGenerator(`plugin::${pluginName}`);
|
|
@@ -86,7 +86,7 @@ const registerPluginRoutes = (strapi) => {
|
|
|
86
86
|
* @param {import('../../').Strapi} strapi
|
|
87
87
|
*/
|
|
88
88
|
const registerAPIRoutes = (strapi) => {
|
|
89
|
-
for (const apiName
|
|
89
|
+
for (const apiName of Object.keys(strapi.api)) {
|
|
90
90
|
const api = strapi.api[apiName];
|
|
91
91
|
|
|
92
92
|
const generateRouteScope = createRouteScopeGenerator(`api::${apiName}`);
|
|
@@ -27,7 +27,7 @@ module.exports = async (uid, entity, files) => {
|
|
|
27
27
|
let tmpModel = modelDef;
|
|
28
28
|
let modelUID = uid;
|
|
29
29
|
|
|
30
|
-
for (let i = 0; i < path.length; i
|
|
30
|
+
for (let i = 0; i < path.length; i += 1) {
|
|
31
31
|
if (!tmpModel) return {};
|
|
32
32
|
const part = path[i];
|
|
33
33
|
const attr = tmpModel.attributes[part];
|
|
@@ -26,7 +26,7 @@ module.exports = class WorkerQueue {
|
|
|
26
26
|
enqueue(payload) {
|
|
27
27
|
debug('Enqueue event in worker queue');
|
|
28
28
|
if (this.running < this.concurrency) {
|
|
29
|
-
this.running
|
|
29
|
+
this.running += 1;
|
|
30
30
|
this.execute(payload);
|
|
31
31
|
} else {
|
|
32
32
|
this.queue.unshift(payload);
|
|
@@ -40,7 +40,7 @@ module.exports = class WorkerQueue {
|
|
|
40
40
|
if (payload) {
|
|
41
41
|
this.execute(payload);
|
|
42
42
|
} else {
|
|
43
|
-
this.running
|
|
43
|
+
this.running -= 1;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -2,7 +2,8 @@ import type Koa from 'koa';
|
|
|
2
2
|
import { Database } from '@strapi/database';
|
|
3
3
|
|
|
4
4
|
import type { StringMap } from './utils';
|
|
5
|
-
import type { GenericController } from '
|
|
5
|
+
import type { GenericController } from '../../../core-api/controller'
|
|
6
|
+
import type { GenericService } from '../../../core-api/service'
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* The Strapi interface implemented by the main Strapi class.
|
|
@@ -33,12 +34,12 @@ export interface Strapi {
|
|
|
33
34
|
*
|
|
34
35
|
* It returns all the registered services
|
|
35
36
|
*/
|
|
36
|
-
readonly services: StringMap<
|
|
37
|
+
readonly services: StringMap<GenericService>;
|
|
37
38
|
|
|
38
39
|
/**
|
|
39
40
|
* Find a service using its unique identifier
|
|
40
41
|
*/
|
|
41
|
-
service<T extends
|
|
42
|
+
service<T extends GenericService = GenericService>(uid: string): T | undefined;
|
|
42
43
|
|
|
43
44
|
/**
|
|
44
45
|
* Getter for the Strapi controllers container
|
package/lib/types/factories.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Service } from '../core-api/service';
|
|
1
|
+
import { Service,GenericService } 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';
|
|
@@ -47,14 +47,14 @@ interface Router {
|
|
|
47
47
|
type ControllerCallback<T extends GenericController = GenericController> = (params: {
|
|
48
48
|
strapi: Strapi;
|
|
49
49
|
}) => T;
|
|
50
|
-
type ServiceCallback<T extends
|
|
50
|
+
type ServiceCallback<T extends GenericService = GenericService> = (params: { strapi: Strapi }) => T;
|
|
51
51
|
|
|
52
52
|
export function createCoreRouter(uid: string, cfg?: RouterConfig = {}): () => Router;
|
|
53
53
|
export function createCoreController<T extends GenericController = GenericController>(
|
|
54
54
|
uid: string,
|
|
55
55
|
cfg?: ControllerCallback<T> | T = {}
|
|
56
56
|
): () => T & Controller;
|
|
57
|
-
export function createCoreService<T extends
|
|
57
|
+
export function createCoreService<T extends GenericService = GenericService>(
|
|
58
58
|
uid: string,
|
|
59
59
|
cfg?: ServiceCallback<T> | T = {}
|
|
60
60
|
): () => T;
|
package/lib/utils/addSlash.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
module.exports = (path) => {
|
|
4
|
-
|
|
5
|
-
if (
|
|
4
|
+
let tmpPath = path;
|
|
5
|
+
if (typeof tmpPath !== 'string') throw new Error('admin.url must be a string');
|
|
6
|
+
if (tmpPath === '' || tmpPath === '/') return '/';
|
|
6
7
|
|
|
7
|
-
if (
|
|
8
|
-
if (
|
|
9
|
-
return
|
|
8
|
+
if (tmpPath[0] !== '/') tmpPath = `/${tmpPath}`;
|
|
9
|
+
if (tmpPath[tmpPath.length - 1] !== '/') tmpPath += '/';
|
|
10
|
+
return tmpPath;
|
|
10
11
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/strapi",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-ee00599cd73180e84df84536521183b48892a28c",
|
|
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",
|
|
@@ -78,19 +78,19 @@
|
|
|
78
78
|
"test:unit": "jest --verbose"
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"@koa/cors": "3.1
|
|
81
|
+
"@koa/cors": "3.4.1",
|
|
82
82
|
"@koa/router": "10.1.1",
|
|
83
|
-
"@strapi/admin": "0.0.0-
|
|
84
|
-
"@strapi/database": "0.0.0-
|
|
85
|
-
"@strapi/generate-new": "0.0.0-
|
|
86
|
-
"@strapi/generators": "0.0.0-
|
|
87
|
-
"@strapi/logger": "0.0.0-
|
|
88
|
-
"@strapi/plugin-content-manager": "0.0.0-
|
|
89
|
-
"@strapi/plugin-content-type-builder": "0.0.0-
|
|
90
|
-
"@strapi/plugin-email": "0.0.0-
|
|
91
|
-
"@strapi/plugin-upload": "0.0.0-
|
|
92
|
-
"@strapi/typescript-utils": "0.0.0-
|
|
93
|
-
"@strapi/utils": "0.0.0-
|
|
83
|
+
"@strapi/admin": "0.0.0-ee00599cd73180e84df84536521183b48892a28c",
|
|
84
|
+
"@strapi/database": "0.0.0-ee00599cd73180e84df84536521183b48892a28c",
|
|
85
|
+
"@strapi/generate-new": "0.0.0-ee00599cd73180e84df84536521183b48892a28c",
|
|
86
|
+
"@strapi/generators": "0.0.0-ee00599cd73180e84df84536521183b48892a28c",
|
|
87
|
+
"@strapi/logger": "0.0.0-ee00599cd73180e84df84536521183b48892a28c",
|
|
88
|
+
"@strapi/plugin-content-manager": "0.0.0-ee00599cd73180e84df84536521183b48892a28c",
|
|
89
|
+
"@strapi/plugin-content-type-builder": "0.0.0-ee00599cd73180e84df84536521183b48892a28c",
|
|
90
|
+
"@strapi/plugin-email": "0.0.0-ee00599cd73180e84df84536521183b48892a28c",
|
|
91
|
+
"@strapi/plugin-upload": "0.0.0-ee00599cd73180e84df84536521183b48892a28c",
|
|
92
|
+
"@strapi/typescript-utils": "0.0.0-ee00599cd73180e84df84536521183b48892a28c",
|
|
93
|
+
"@strapi/utils": "0.0.0-ee00599cd73180e84df84536521183b48892a28c",
|
|
94
94
|
"bcryptjs": "2.4.3",
|
|
95
95
|
"boxen": "5.1.2",
|
|
96
96
|
"chalk": "4.1.2",
|
|
@@ -136,8 +136,8 @@
|
|
|
136
136
|
"typescript": "4.6.2"
|
|
137
137
|
},
|
|
138
138
|
"engines": {
|
|
139
|
-
"node": ">=14.19.1 <=
|
|
139
|
+
"node": ">=14.19.1 <=18.x.x",
|
|
140
140
|
"npm": ">=6.0.0"
|
|
141
141
|
},
|
|
142
|
-
"gitHead": "
|
|
142
|
+
"gitHead": "ee00599cd73180e84df84536521183b48892a28c"
|
|
143
143
|
}
|