@strapi/strapi 4.3.6 → 4.4.0-alpha.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/lib/Strapi.js CHANGED
@@ -22,6 +22,7 @@ const createCronService = require('./services/cron');
22
22
  const entityValidator = require('./services/entity-validator');
23
23
  const createTelemetry = require('./services/metrics');
24
24
  const createAuth = require('./services/auth');
25
+ const createCustomFields = require('./services/custom-fields');
25
26
  const createUpdateNotifier = require('./utils/update-notifier');
26
27
  const createStartupLogger = require('./utils/startup-logger');
27
28
  const { LIFECYCLES } = require('./utils/lifecycles');
@@ -34,12 +35,14 @@ const hooksRegistry = require('./core/registries/hooks');
34
35
  const controllersRegistry = require('./core/registries/controllers');
35
36
  const modulesRegistry = require('./core/registries/modules');
36
37
  const pluginsRegistry = require('./core/registries/plugins');
38
+ const customFieldsRegistry = require('./core/registries/custom-fields');
37
39
  const createConfigProvider = require('./core/registries/config');
38
40
  const apisRegistry = require('./core/registries/apis');
39
41
  const bootstrap = require('./core/bootstrap');
40
42
  const loaders = require('./core/loaders');
41
43
  const { destroyOnSignal } = require('./utils/signals');
42
44
  const sanitizersRegistry = require('./core/registries/sanitizers');
45
+ const convertCustomFieldType = require('./utils/convert-custom-field-type');
43
46
 
44
47
  // TODO: move somewhere else
45
48
  const draftAndPublishSync = require('./migrations/draft-publish');
@@ -87,6 +90,7 @@ class Strapi {
87
90
  this.container.register('controllers', controllersRegistry(this));
88
91
  this.container.register('modules', modulesRegistry(this));
89
92
  this.container.register('plugins', pluginsRegistry(this));
93
+ this.container.register('custom-fields', customFieldsRegistry(this));
90
94
  this.container.register('apis', apisRegistry(this));
91
95
  this.container.register('auth', createAuth(this));
92
96
  this.container.register('sanitizers', sanitizersRegistry(this));
@@ -109,6 +113,8 @@ class Strapi {
109
113
  this.cron = createCronService();
110
114
  this.telemetry = createTelemetry(this);
111
115
 
116
+ this.customFields = createCustomFields(this);
117
+
112
118
  createUpdateNotifier(this).notify();
113
119
  }
114
120
 
@@ -454,6 +460,8 @@ class Strapi {
454
460
 
455
461
  async load() {
456
462
  await this.register();
463
+ // Swap type customField for underlying data type
464
+ convertCustomFieldType(this);
457
465
  await this.bootstrap();
458
466
 
459
467
  this.isLoaded = true;
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+
3
+ const { has } = require('lodash/fp');
4
+ const validators = require('../../services/entity-validator/validators');
5
+
6
+ const customFieldsRegistry = strapi => {
7
+ const customFields = {};
8
+
9
+ return {
10
+ getAll() {
11
+ return customFields;
12
+ },
13
+ get(customField) {
14
+ const registeredCustomField = customFields[customField];
15
+ if (!registeredCustomField) {
16
+ throw new Error(`Could not find Custom Field: ${customField}`);
17
+ }
18
+
19
+ return registeredCustomField;
20
+ },
21
+ add(customField) {
22
+ const customFieldList = Array.isArray(customField) ? customField : [customField];
23
+
24
+ for (const cf of customFieldList) {
25
+ if (!has('name', cf) || !has('type', cf)) {
26
+ throw new Error(`Custom fields require a 'name' and 'type' key`);
27
+ }
28
+
29
+ const { name, plugin, type } = cf;
30
+ if (!has(type, validators)) {
31
+ throw new Error(
32
+ `Custom field type: '${type}' is not a valid Strapi type or it can't be used with a Custom Field`
33
+ );
34
+ }
35
+
36
+ const isValidObjectKey = /^(?![0-9])[a-zA-Z0-9$_-]+$/g;
37
+ if (!isValidObjectKey.test(name)) {
38
+ throw new Error(`Custom field name: '${name}' is not a valid object key`);
39
+ }
40
+
41
+ // When no plugin is specified, or it isn't found in Strapi, default to global
42
+ const uid = strapi.plugin(plugin) ? `plugin::${plugin}.${name}` : `global::${name}`;
43
+
44
+ if (has(uid, customFields)) {
45
+ throw new Error(`Custom field: '${uid}' has already been registered`);
46
+ }
47
+
48
+ customFields[uid] = cf;
49
+ }
50
+ },
51
+ };
52
+ };
53
+
54
+ module.exports = customFieldsRegistry;
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ const createCustomFields = strapi => {
4
+ return {
5
+ register(customField) {
6
+ strapi.container.get('custom-fields').add(customField);
7
+ },
8
+ };
9
+ };
10
+
11
+ module.exports = createCustomFields;
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ const convertCustomFieldType = strapi => {
4
+ const allContentTypeSchemaAttributes = Object.values(strapi.contentTypes).map(
5
+ schema => schema.attributes
6
+ );
7
+ const allComponentSchemaAttributes = Object.values(strapi.components).map(
8
+ schema => schema.attributes
9
+ );
10
+ const allSchemasAttributes = [...allContentTypeSchemaAttributes, ...allComponentSchemaAttributes];
11
+
12
+ for (const schemaAttrbutes of allSchemasAttributes) {
13
+ for (const attribute of Object.values(schemaAttrbutes)) {
14
+ if (attribute.type === 'customField') {
15
+ const customField = strapi.container.get('custom-fields').get(attribute.customField);
16
+ attribute.type = customField.type;
17
+ }
18
+ }
19
+ }
20
+ };
21
+
22
+ module.exports = convertCustomFieldType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/strapi",
3
- "version": "4.3.6",
3
+ "version": "4.4.0-alpha.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",
@@ -78,19 +78,19 @@
78
78
  "test:unit": "jest --verbose"
79
79
  },
80
80
  "dependencies": {
81
- "@koa/cors": "3.1.0",
81
+ "@koa/cors": "3.4.1",
82
82
  "@koa/router": "10.1.1",
83
- "@strapi/admin": "4.3.6",
84
- "@strapi/database": "4.3.6",
85
- "@strapi/generate-new": "4.3.6",
86
- "@strapi/generators": "4.3.6",
87
- "@strapi/logger": "4.3.6",
88
- "@strapi/plugin-content-manager": "4.3.6",
89
- "@strapi/plugin-content-type-builder": "4.3.6",
90
- "@strapi/plugin-email": "4.3.6",
91
- "@strapi/plugin-upload": "4.3.6",
92
- "@strapi/typescript-utils": "4.3.6",
93
- "@strapi/utils": "4.3.6",
83
+ "@strapi/admin": "4.4.0-alpha.0",
84
+ "@strapi/database": "4.4.0-alpha.0",
85
+ "@strapi/generate-new": "4.4.0-alpha.0",
86
+ "@strapi/generators": "4.4.0-alpha.0",
87
+ "@strapi/logger": "4.4.0-alpha.0",
88
+ "@strapi/plugin-content-manager": "4.4.0-alpha.0",
89
+ "@strapi/plugin-content-type-builder": "4.4.0-alpha.0",
90
+ "@strapi/plugin-email": "4.4.0-alpha.0",
91
+ "@strapi/plugin-upload": "4.4.0-alpha.0",
92
+ "@strapi/typescript-utils": "4.4.0-alpha.0",
93
+ "@strapi/utils": "4.4.0-alpha.0",
94
94
  "bcryptjs": "2.4.3",
95
95
  "boxen": "5.1.2",
96
96
  "chalk": "4.1.2",
@@ -139,5 +139,5 @@
139
139
  "node": ">=14.19.1 <=16.x.x",
140
140
  "npm": ">=6.0.0"
141
141
  },
142
- "gitHead": "4c6e67c4934580ed051a2afb83e6fc8f64f3a5b5"
142
+ "gitHead": "fc78298ae4f9b247d636beda568734d5f8ed7b3e"
143
143
  }