@webiny/api-headless-cms 5.35.0 → 5.35.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/crud/contentEntry.crud.js +110 -4
  2. package/crud/contentEntry.crud.js.map +1 -1
  3. package/crud/contentModel/validation.d.ts +87 -87
  4. package/crud/contentModelGroup/validation.d.ts +4 -4
  5. package/graphql/index.d.ts +1 -1
  6. package/graphql/schema/baseSchema.js +15 -0
  7. package/graphql/schema/baseSchema.js.map +1 -1
  8. package/graphql/schema/createManageResolvers.js +4 -0
  9. package/graphql/schema/createManageResolvers.js.map +1 -1
  10. package/graphql/schema/createManageSDL.js +4 -2
  11. package/graphql/schema/createManageSDL.js.map +1 -1
  12. package/graphql/schema/resolvers/manage/resolveDelete.d.ts +2 -1
  13. package/graphql/schema/resolvers/manage/resolveDelete.js +13 -3
  14. package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
  15. package/graphql/schema/resolvers/manage/resolveDeleteMultiple.d.ts +7 -0
  16. package/graphql/schema/resolvers/manage/resolveDeleteMultiple.js +20 -0
  17. package/graphql/schema/resolvers/manage/resolveDeleteMultiple.js.map +1 -0
  18. package/graphql/schema/schemaPlugins.js +0 -7
  19. package/graphql/schema/schemaPlugins.js.map +1 -1
  20. package/index.d.ts +1 -1
  21. package/package.json +36 -35
  22. package/types.d.ts +52 -8
  23. package/types.js +7 -0
  24. package/types.js.map +1 -1
  25. package/crud/contentModel/createFieldModels.d.ts +0 -2
  26. package/crud/contentModel/createFieldModels.js +0 -26
  27. package/crud/contentModel/createFieldModels.js.map +0 -1
  28. package/crud/contentModel/fieldIdValidation.d.ts +0 -1
  29. package/crud/contentModel/fieldIdValidation.js +0 -25
  30. package/crud/contentModel/fieldIdValidation.js.map +0 -1
  31. package/crud/contentModel/idValidation.d.ts +0 -1
  32. package/crud/contentModel/idValidation.js +0 -22
  33. package/crud/contentModel/idValidation.js.map +0 -1
  34. package/crud/contentModel/models.d.ts +0 -4
  35. package/crud/contentModel/models.js +0 -192
  36. package/crud/contentModel/models.js.map +0 -1
  37. package/crud/contentModel/systemFields.d.ts +0 -1
  38. package/crud/contentModel/systemFields.js +0 -8
  39. package/crud/contentModel/systemFields.js.map +0 -1
  40. package/upgrades/5.33.0/index.d.ts +0 -3
  41. package/upgrades/5.33.0/index.js +0 -182
  42. package/upgrades/5.33.0/index.js.map +0 -1
  43. package/upgrades/index.d.ts +0 -1
  44. package/upgrades/index.js +0 -12
  45. package/upgrades/index.js.map +0 -1
  46. package/utils/pluralizedTypeName.d.ts +0 -1
  47. package/utils/pluralizedTypeName.js +0 -26
  48. package/utils/pluralizedTypeName.js.map +0 -1
@@ -1,192 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.UpdateContentModelModel = exports.CreateContentModelModelFrom = exports.CreateContentModelModel = exports.ContentModelFieldModel = void 0;
7
-
8
- var _validation = require("@webiny/validation");
9
-
10
- var _commodoFieldsObject = require("commodo-fields-object");
11
-
12
- var _fields = require("@commodo/fields");
13
-
14
- var _fieldIdValidation = require("./fieldIdValidation");
15
-
16
- /**
17
- * Package commodo-fields-object does not have types
18
- */
19
- // @ts-ignore
20
-
21
- /**
22
- * Package commodo-fields does not have object.
23
- */
24
- // @ts-ignore
25
- const requiredShortString = _validation.validation.create("required,maxLength:255");
26
-
27
- const shortString = _validation.validation.create("maxLength:255");
28
-
29
- const RendererModel = (0, _fields.withFields)({
30
- name: (0, _fields.string)({
31
- validation: requiredShortString
32
- })
33
- })();
34
- const ContentModelFieldModel = (0, _fields.withFields)({
35
- id: (0, _fields.string)({
36
- validation: requiredShortString
37
- }),
38
- fieldId: (0, _fields.string)({
39
- validation: _fieldIdValidation.validateFieldId
40
- }),
41
- label: (0, _fields.string)({
42
- validation: requiredShortString
43
- }),
44
- helpText: (0, _fields.string)({
45
- validation: shortString
46
- }),
47
- placeholderText: (0, _fields.string)({
48
- validation: shortString
49
- }),
50
- type: (0, _fields.setOnce)()((0, _fields.string)({
51
- validation: requiredShortString
52
- })),
53
- tags: (0, _commodoFieldsObject.object)({
54
- value: [],
55
- required: false
56
- }),
57
- multipleValues: (0, _fields.boolean)({
58
- value: false
59
- }),
60
- predefinedValues: (0, _fields.fields)({
61
- value: {},
62
- instanceOf: (0, _fields.withFields)({
63
- enabled: (0, _fields.boolean)(),
64
- values: (0, _fields.fields)({
65
- value: [],
66
- list: true,
67
- instanceOf: (0, _fields.withFields)({
68
- label: (0, _fields.string)(),
69
- value: (0, _fields.string)(),
70
- selected: (0, _fields.boolean)()
71
- })()
72
- })
73
- })()
74
- }),
75
- renderer: (0, _fields.fields)({
76
- instanceOf: RendererModel,
77
- validation: shortString
78
- }),
79
- validation: (0, _fields.fields)({
80
- list: true,
81
- value: [],
82
- instanceOf: (0, _fields.withFields)({
83
- name: (0, _fields.string)({
84
- validation: requiredShortString
85
- }),
86
- message: (0, _fields.string)({
87
- validation: shortString
88
- }),
89
- settings: (0, _commodoFieldsObject.object)({
90
- value: {}
91
- })
92
- })()
93
- }),
94
- listValidation: (0, _fields.fields)({
95
- list: true,
96
- value: [],
97
- instanceOf: (0, _fields.withFields)({
98
- name: (0, _fields.string)({
99
- validation: requiredShortString
100
- }),
101
- message: (0, _fields.string)({
102
- validation: shortString
103
- }),
104
- settings: (0, _commodoFieldsObject.object)({
105
- value: {}
106
- })
107
- })()
108
- }),
109
- settings: (0, _commodoFieldsObject.object)({
110
- value: {}
111
- })
112
- /**
113
- * By the default, field is not deleted.
114
- */
115
- // isDeleted: boolean({ value: false })
116
-
117
- })();
118
- exports.ContentModelFieldModel = ContentModelFieldModel;
119
- const CreateContentModelModel = (0, _fields.withFields)({
120
- name: (0, _fields.string)({
121
- validation: requiredShortString
122
- }),
123
- modelId: (0, _fields.string)({
124
- validation: shortString
125
- }),
126
- description: (0, _fields.string)({
127
- validation: shortString
128
- }),
129
- group: (0, _fields.string)({
130
- validation: requiredShortString
131
- }),
132
- fields: (0, _fields.fields)({
133
- instanceOf: ContentModelFieldModel,
134
- value: [],
135
- list: true,
136
- required: true
137
- }),
138
- layout: (0, _commodoFieldsObject.object)({
139
- value: [],
140
- required: true
141
- }),
142
- tags: (0, _commodoFieldsObject.object)({
143
- value: [],
144
- required: false
145
- })
146
- })();
147
- exports.CreateContentModelModel = CreateContentModelModel;
148
- const CreateContentModelModelFrom = (0, _fields.withFields)({
149
- name: (0, _fields.string)({
150
- validation: requiredShortString
151
- }),
152
- modelId: (0, _fields.string)({
153
- validation: shortString
154
- }),
155
- description: (0, _fields.string)({
156
- validation: shortString
157
- }),
158
- group: (0, _fields.string)({
159
- validation: requiredShortString
160
- }),
161
- locale: (0, _fields.string)({
162
- validation: shortString
163
- })
164
- })();
165
- exports.CreateContentModelModelFrom = CreateContentModelModelFrom;
166
- const UpdateContentModelModel = (0, _fields.withFields)({
167
- name: (0, _fields.string)({
168
- validation: shortString
169
- }),
170
- description: (0, _fields.string)({
171
- validation: shortString
172
- }),
173
- group: (0, _fields.string)({
174
- validation: shortString
175
- }),
176
- titleFieldId: (0, _fields.string)(),
177
- fields: (0, _fields.fields)({
178
- instanceOf: ContentModelFieldModel,
179
- value: [],
180
- list: true,
181
- required: true
182
- }),
183
- layout: (0, _commodoFieldsObject.object)({
184
- value: [],
185
- required: true
186
- }),
187
- tags: (0, _commodoFieldsObject.object)({
188
- value: [],
189
- required: false
190
- })
191
- })();
192
- exports.UpdateContentModelModel = UpdateContentModelModel;
@@ -1 +0,0 @@
1
- {"version":3,"names":["requiredShortString","validation","create","shortString","RendererModel","withFields","name","string","ContentModelFieldModel","id","fieldId","validateFieldId","label","helpText","placeholderText","type","setOnce","tags","object","value","required","multipleValues","boolean","predefinedValues","fields","instanceOf","enabled","values","list","selected","renderer","message","settings","listValidation","CreateContentModelModel","modelId","description","group","layout","CreateContentModelModelFrom","locale","UpdateContentModelModel","titleFieldId"],"sources":["models.ts"],"sourcesContent":["import { validation } from \"@webiny/validation\";\n/**\n * Package commodo-fields-object does not have types\n */\n// @ts-ignore\nimport { object } from \"commodo-fields-object\";\n/**\n * Package commodo-fields does not have object.\n */\n// @ts-ignore\nimport { withFields, string, setOnce, boolean, fields } from \"@commodo/fields\";\nimport { validateFieldId } from \"./fieldIdValidation\";\n\nconst requiredShortString = validation.create(\"required,maxLength:255\");\nconst shortString = validation.create(\"maxLength:255\");\n\nconst RendererModel = withFields({\n name: string({ validation: requiredShortString })\n})();\n\nexport const ContentModelFieldModel = withFields({\n id: string({ validation: requiredShortString }),\n fieldId: string({\n validation: validateFieldId\n }),\n label: string({ validation: requiredShortString }),\n helpText: string({ validation: shortString }),\n placeholderText: string({ validation: shortString }),\n type: setOnce()(string({ validation: requiredShortString })),\n tags: object({ value: [], required: false }),\n multipleValues: boolean({ value: false }),\n predefinedValues: fields({\n value: {},\n instanceOf: withFields({\n enabled: boolean(),\n values: fields({\n value: [],\n list: true,\n instanceOf: withFields({\n label: string(),\n value: string(),\n selected: boolean()\n })()\n })\n })()\n }),\n renderer: fields({ instanceOf: RendererModel, validation: shortString }),\n validation: fields({\n list: true,\n value: [],\n instanceOf: withFields({\n name: string({ validation: requiredShortString }),\n message: string({ validation: shortString }),\n settings: object({ value: {} })\n })()\n }),\n listValidation: fields({\n list: true,\n value: [],\n instanceOf: withFields({\n name: string({ validation: requiredShortString }),\n message: string({ validation: shortString }),\n settings: object({ value: {} })\n })()\n }),\n settings: object({ value: {} })\n /**\n * By the default, field is not deleted.\n */\n // isDeleted: boolean({ value: false })\n})();\n\nexport const CreateContentModelModel = withFields({\n name: string({ validation: requiredShortString }),\n modelId: string({ validation: shortString }),\n description: string({ validation: shortString }),\n group: string({ validation: requiredShortString }),\n fields: fields({ instanceOf: ContentModelFieldModel, value: [], list: true, required: true }),\n layout: object({ value: [], required: true }),\n tags: object({ value: [], required: false })\n})();\n\nexport const CreateContentModelModelFrom = withFields({\n name: string({ validation: requiredShortString }),\n modelId: string({ validation: shortString }),\n description: string({ validation: shortString }),\n group: string({ validation: requiredShortString }),\n locale: string({ validation: shortString })\n})();\n\nexport const UpdateContentModelModel = withFields({\n name: string({ validation: shortString }),\n description: string({ validation: shortString }),\n group: string({ validation: shortString }),\n titleFieldId: string(),\n fields: fields({ instanceOf: ContentModelFieldModel, value: [], list: true, required: true }),\n layout: object({ value: [], required: true }),\n tags: object({ value: [], required: false })\n})();\n"],"mappings":";;;;;;;AAAA;;AAKA;;AAKA;;AACA;;AAVA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AAIA,MAAMA,mBAAmB,GAAGC,sBAAA,CAAWC,MAAX,CAAkB,wBAAlB,CAA5B;;AACA,MAAMC,WAAW,GAAGF,sBAAA,CAAWC,MAAX,CAAkB,eAAlB,CAApB;;AAEA,MAAME,aAAa,GAAG,IAAAC,kBAAA,EAAW;EAC7BC,IAAI,EAAE,IAAAC,cAAA,EAAO;IAAEN,UAAU,EAAED;EAAd,CAAP;AADuB,CAAX,GAAtB;AAIO,MAAMQ,sBAAsB,GAAG,IAAAH,kBAAA,EAAW;EAC7CI,EAAE,EAAE,IAAAF,cAAA,EAAO;IAAEN,UAAU,EAAED;EAAd,CAAP,CADyC;EAE7CU,OAAO,EAAE,IAAAH,cAAA,EAAO;IACZN,UAAU,EAAEU;EADA,CAAP,CAFoC;EAK7CC,KAAK,EAAE,IAAAL,cAAA,EAAO;IAAEN,UAAU,EAAED;EAAd,CAAP,CALsC;EAM7Ca,QAAQ,EAAE,IAAAN,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CANmC;EAO7CW,eAAe,EAAE,IAAAP,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CAP4B;EAQ7CY,IAAI,EAAE,IAAAC,eAAA,IAAU,IAAAT,cAAA,EAAO;IAAEN,UAAU,EAAED;EAAd,CAAP,CAAV,CARuC;EAS7CiB,IAAI,EAAE,IAAAC,2BAAA,EAAO;IAAEC,KAAK,EAAE,EAAT;IAAaC,QAAQ,EAAE;EAAvB,C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AAE,IAAA5B,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CAFyC;EAGlDiC,WAAW,EAAE,IAAA7B,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CAHqC;EAIlDkC,KAAK,EAAE,IAAA9B,cAAA,EAAO;IAAEN,UAAU,EAAED;EAAd,CAAP,CAJ2C;EAKlDwC,MAAM,EAAE,IAAAjC,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP;AAL0C,CAAX,GAApC;;AAQA,MAAMsC,uBAAuB,GAAG,IAAApC,kBAAA,EAAW;EAC9CC,IAAI,EAAE,IAAAC,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CADwC;EAE9CiC,WAAW,EAAE,IAAA7B,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CAFiC;EAG9CkC,KAAK,EAAE,IAAA9B,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CAHuC;EAI9CuC,YAAY,EAAE,IAAAnC,cAAA,GAJgC;EAK9CiB,MAAM,EAAE,IAAAA,cAAA,EAAO;IAAEC,UAAU,EAAEjB,sBAAd;IAAsCW,KAAK,EAAE,EAA7C;IAAiDS,IAAI,EAAE,IAAvD;IAA6DR,QAAQ,EAAE;EAAvE,CAAP,CALsC;EAM9CkB,MAAM,EAAE,IAAApB,2BAAA,EAAO;IAAEC,KAAK,EAAE,EAAT;IAAaC,QAAQ,EAAE;EAAvB,CAAP,CANsC;EAO9CH,IAAI,EAAE,IAAAC,2BAAA,EAAO;IAAEC,KAAK,EAAE,EAAT;IAAaC,QAAQ,EAAE;EAAvB,CAAP;AAPwC,CAAX,GAAhC"}
@@ -1 +0,0 @@
1
- export declare const fieldSystemFields: string[];
@@ -1,8 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.fieldSystemFields = void 0;
7
- const fieldSystemFields = ["id", "fieldId", "storageId", "label", "helpText", "placeholderText", "type", "multipleValues", "predefinedValues", "renderer", "validation", "listValidation", "settings"];
8
- exports.fieldSystemFields = fieldSystemFields;
@@ -1 +0,0 @@
1
- {"version":3,"names":["fieldSystemFields"],"sources":["systemFields.ts"],"sourcesContent":["export const fieldSystemFields: string[] = [\n \"id\",\n \"fieldId\",\n \"storageId\",\n \"label\",\n \"helpText\",\n \"placeholderText\",\n \"type\",\n \"multipleValues\",\n \"predefinedValues\",\n \"renderer\",\n \"validation\",\n \"listValidation\",\n \"settings\"\n];\n"],"mappings":";;;;;;AAAO,MAAMA,iBAA2B,GAAG,CACvC,IADuC,EAEvC,SAFuC,EAGvC,WAHuC,EAIvC,OAJuC,EAKvC,UALuC,EAMvC,iBANuC,EAOvC,MAPuC,EAQvC,gBARuC,EASvC,kBATuC,EAUvC,UAVuC,EAWvC,YAXuC,EAYvC,gBAZuC,EAavC,UAbuC,CAApC"}
@@ -1,3 +0,0 @@
1
- import { UpgradePlugin } from "@webiny/api-upgrade";
2
- import { CmsContext } from "../../types";
3
- export declare const createUpgrade: () => UpgradePlugin<CmsContext>;
@@ -1,182 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.createUpgrade = void 0;
9
-
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
- var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
- const assignStorageId = fields => {
15
- return fields.map(field => {
16
- const settings = (0, _objectSpread2.default)({}, field.settings || {});
17
-
18
- if (settings.fields && Array.isArray(settings.fields) === true) {
19
- settings.fields = assignStorageId(settings.fields);
20
- }
21
-
22
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, field), {}, {
23
- storageId: field.fieldId,
24
- settings
25
- });
26
- });
27
- };
28
- /**
29
- * If at least one field does not have storageId define, we should definitely update the model.
30
- */
31
-
32
-
33
- const shouldUpdate = fields => {
34
- return fields.some(field => {
35
- var _field$settings;
36
-
37
- if ((_field$settings = field.settings) !== null && _field$settings !== void 0 && _field$settings.fields) {
38
- return shouldUpdate(field.settings.fields);
39
- }
40
-
41
- return !field.storageId;
42
- });
43
- };
44
-
45
- const upgradeTenantModels = async params => {
46
- const {
47
- tenant,
48
- cms,
49
- i18n
50
- } = params;
51
- /**
52
- * We need all locales for this tenant, so we can go and find all models for all the locales.
53
- */
54
-
55
- const [locales] = await i18n.locales.storageOperations.list({
56
- where: {
57
- tenant: tenant.id
58
- },
59
- limit: 100
60
- });
61
-
62
- if (locales.length === 0) {
63
- console.log(`There are no locales under the tenant "${tenant.id}".`);
64
- return;
65
- }
66
-
67
- for (const locale of locales) {
68
- /**
69
- * We need all the models that are not plugin models.
70
- */
71
- const models = await cms.storageOperations.models.list({
72
- where: {
73
- tenant: tenant.id,
74
- locale: locale.code
75
- }
76
- });
77
-
78
- if (models.length === 0) {
79
- console.log(`No models in tenant "${tenant.id}" and locale "${locale.code}" combination.`);
80
- continue;
81
- }
82
- /**
83
- * Then we need to go into each of the model fields and add the storageId, which is the same as the fieldId
84
- */
85
-
86
-
87
- const updatedModels = models.filter(model => {
88
- /**
89
- * If model has at least one field with no storageId, continue with the update.
90
- */
91
- const toUpdate = shouldUpdate(model.fields);
92
- /**
93
- * If not updating the model, lets log it - just in case...
94
- */
95
-
96
- if (!toUpdate) {
97
- console.log(`Skipping update of model "${model.modelId} - ${tenant.id} - ${locale.code}".`);
98
- return false;
99
- }
100
-
101
- return true;
102
- }).map(model => {
103
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, model), {}, {
104
- fields: assignStorageId(model.fields)
105
- });
106
- });
107
- /**
108
- * And update all the models
109
- */
110
-
111
- for (const model of updatedModels) {
112
- try {
113
- await cms.storageOperations.models.update({
114
- model
115
- });
116
- } catch (ex) {
117
- throw new _error.default(`Could not update CMS model ${model.modelId}`, "MODEL_UPGRADE_ERROR", {
118
- model
119
- });
120
- }
121
- }
122
- }
123
- /**
124
- * In the end we need to write the new cms system version.
125
- */
126
-
127
-
128
- await cms.setSystemVersion("5.33.0");
129
- };
130
-
131
- const createUpgrade = () => {
132
- return {
133
- type: "api-upgrade",
134
- version: "5.33.0",
135
- app: "headless-cms",
136
- apply: async context => {
137
- const {
138
- security,
139
- tenancy,
140
- cms,
141
- i18n
142
- } = context;
143
- /**
144
- * We need to be able to access all data.
145
- */
146
-
147
- security.disableAuthorization();
148
- const initialTenant = tenancy.getCurrentTenant();
149
- const tenants = await tenancy.listTenants();
150
-
151
- try {
152
- for (const tenant of tenants) {
153
- tenancy.setCurrentTenant(tenant);
154
- await upgradeTenantModels({
155
- tenant,
156
- cms,
157
- i18n
158
- });
159
- }
160
- } catch (ex) {
161
- console.log(`Upgrade error: ${JSON.stringify({
162
- message: ex.message,
163
- code: ex.code,
164
- data: ex.data
165
- })}`);
166
- throw new _error.default(`Could not finish the 5.33.0 upgrade. Please contact Webiny team on Slack and share the error.`, "UPGRADE_ERROR", {
167
- message: ex.message,
168
- code: ex.code,
169
- data: ex.data
170
- });
171
- } finally {
172
- /**
173
- * Always enable the security after all the code runs.
174
- */
175
- security.enableAuthorization();
176
- tenancy.setCurrentTenant(initialTenant);
177
- }
178
- }
179
- };
180
- };
181
-
182
- exports.createUpgrade = createUpgrade;
@@ -1 +0,0 @@
1
- {"version":3,"names":["assignStorageId","fields","map","field","settings","Array","isArray","storageId","fieldId","shouldUpdate","some","upgradeTenantModels","params","tenant","cms","i18n","locales","storageOperations","list","where","id","limit","length","console","log","locale","models","code","updatedModels","filter","model","toUpdate","modelId","update","ex","WebinyError","setSystemVersion","createUpgrade","type","version","app","apply","context","security","tenancy","disableAuthorization","initialTenant","getCurrentTenant","tenants","listTenants","setCurrentTenant","JSON","stringify","message","data","enableAuthorization"],"sources":["index.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { UpgradePlugin } from \"@webiny/api-upgrade\";\nimport { CmsContext, CmsModelField, HeadlessCms } from \"~/types\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { I18NContextObject } from \"@webiny/api-i18n/types\";\n\nconst assignStorageId = (fields: CmsModelField[]): CmsModelField[] => {\n return fields.map(field => {\n const settings = {\n ...(field.settings || {})\n };\n if (settings.fields && Array.isArray(settings.fields) === true) {\n settings.fields = assignStorageId(settings.fields);\n }\n return {\n ...field,\n storageId: field.fieldId,\n settings\n };\n });\n};\n/**\n * If at least one field does not have storageId define, we should definitely update the model.\n */\nconst shouldUpdate = (fields: CmsModelField[]): boolean => {\n return fields.some(field => {\n if (field.settings?.fields) {\n return shouldUpdate(field.settings.fields);\n }\n return !field.storageId;\n });\n};\n\ninterface UpgradeTenantModelsParams {\n tenant: Tenant;\n cms: HeadlessCms;\n i18n: I18NContextObject;\n}\n\nconst upgradeTenantModels = async (params: UpgradeTenantModelsParams): Promise<void> => {\n const { tenant, cms, i18n } = params;\n /**\n * We need all locales for this tenant, so we can go and find all models for all the locales.\n */\n const [locales] = await i18n.locales.storageOperations.list({\n where: {\n tenant: tenant.id\n },\n limit: 100\n });\n if (locales.length === 0) {\n console.log(`There are no locales under the tenant \"${tenant.id}\".`);\n return;\n }\n for (const locale of locales) {\n /**\n * We need all the models that are not plugin models.\n */\n const models = await cms.storageOperations.models.list({\n where: {\n tenant: tenant.id,\n locale: locale.code\n }\n });\n if (models.length === 0) {\n console.log(\n `No models in tenant \"${tenant.id}\" and locale \"${locale.code}\" combination.`\n );\n continue;\n }\n\n /**\n * Then we need to go into each of the model fields and add the storageId, which is the same as the fieldId\n */\n const updatedModels = models\n .filter(model => {\n /**\n * If model has at least one field with no storageId, continue with the update.\n */\n const toUpdate = shouldUpdate(model.fields);\n\n /**\n * If not updating the model, lets log it - just in case...\n */\n if (!toUpdate) {\n console.log(\n `Skipping update of model \"${model.modelId} - ${tenant.id} - ${locale.code}\".`\n );\n return false;\n }\n return true;\n })\n .map(model => {\n return {\n ...model,\n fields: assignStorageId(model.fields)\n };\n });\n /**\n * And update all the models\n */\n for (const model of updatedModels) {\n try {\n await cms.storageOperations.models.update({\n model\n });\n } catch (ex) {\n throw new WebinyError(\n `Could not update CMS model ${model.modelId}`,\n \"MODEL_UPGRADE_ERROR\",\n {\n model\n }\n );\n }\n }\n }\n /**\n * In the end we need to write the new cms system version.\n */\n await cms.setSystemVersion(\"5.33.0\");\n};\n\nexport const createUpgrade = (): UpgradePlugin<CmsContext> => {\n return {\n type: \"api-upgrade\",\n version: \"5.33.0\",\n app: \"headless-cms\",\n apply: async context => {\n const { security, tenancy, cms, i18n } = context;\n\n /**\n * We need to be able to access all data.\n */\n security.disableAuthorization();\n\n const initialTenant = tenancy.getCurrentTenant();\n\n const tenants = await tenancy.listTenants();\n try {\n for (const tenant of tenants) {\n tenancy.setCurrentTenant(tenant);\n await upgradeTenantModels({\n tenant,\n cms,\n i18n\n });\n }\n } catch (ex) {\n console.log(\n `Upgrade error: ${JSON.stringify({\n message: ex.message,\n code: ex.code,\n data: ex.data\n })}`\n );\n throw new WebinyError(\n `Could not finish the 5.33.0 upgrade. Please contact Webiny team on Slack and share the error.`,\n \"UPGRADE_ERROR\",\n {\n message: ex.message,\n code: ex.code,\n data: ex.data\n }\n );\n } finally {\n /**\n * Always enable the security after all the code runs.\n */\n security.enableAuthorization();\n tenancy.setCurrentTenant(initialTenant);\n }\n }\n };\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAMA,MAAMA,eAAe,GAAIC,MAAD,IAA8C;EAClE,OAAOA,MAAM,CAACC,GAAP,CAAWC,KAAK,IAAI;IACvB,MAAMC,QAAQ,mCACND,KAAK,CAACC,QAAN,IAAkB,EADZ,CAAd;;IAGA,IAAIA,QAAQ,CAACH,MAAT,IAAmBI,KAAK,CAACC,OAAN,CAAcF,QAAQ,CAACH,MAAvB,MAAmC,IAA1D,EAAgE;MAC5DG,QAAQ,CAACH,MAAT,GAAkBD,eAAe,CAACI,QAAQ,CAACH,MAAV,CAAjC;IACH;;IACD,mEACOE,KADP;M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MAA1B,IAAmC2B,OAAzC;MAEA;AACZ;AACA;;MACYC,QAAQ,CAACE,oBAAT;MAEA,MAAMC,aAAa,GAAGF,OAAO,CAACG,gBAAR,EAAtB;MAEA,MAAMC,OAAO,GAAG,MAAMJ,OAAO,CAACK,WAAR,EAAtB;;MACA,IAAI;QACA,KAAK,MAAMpC,MAAX,IAAqBmC,OAArB,EAA8B;UAC1BJ,OAAO,CAACM,gBAAR,CAAyBrC,MAAzB;UACA,MAAMF,mBAAmB,CAAC;YACtBE,MADsB;YAEtBC,GAFsB;YAGtBC;UAHsB,CAAD,CAAzB;QAKH;MACJ,CATD,CASE,OAAOmB,EAAP,EAAW;QACTX,OAAO,CAACC,GAAR,CACK,kBAAiB2B,IAAI,CAACC,SAAL,CAAe;UAC7BC,OAAO,EAAEnB,EAAE,CAACmB,OADiB;UAE7B1B,IAAI,EAAEO,EAAE,CAACP,IAFoB;UAG7B2B,IAAI,EAAEpB,EAAE,CAACoB;QAHoB,CAAf,CAIf,EALP;QAOA,MAAM,IAAInB,cAAJ,CACD,+FADC,EAEF,eAFE,EAGF;UACIkB,OAAO,EAAEnB,EAAE,CAACmB,OADhB;UAEI1B,IAAI,EAAEO,EAAE,CAACP,IAFb;UAGI2B,IAAI,EAAEpB,EAAE,CAACoB;QAHb,CAHE,CAAN;MASH,CA1BD,SA0BU;QACN;AAChB;AACA;QACgBX,QAAQ,CAACY,mBAAT;QACAX,OAAO,CAACM,gBAAR,CAAyBJ,aAAzB;MACH;IACJ;EAhDE,CAAP;AAkDH,CAnDM"}
@@ -1 +0,0 @@
1
- export declare const createUpgrades: () => import("@webiny/api-upgrade").UpgradePlugin<import("../types").CmsContext>[];
package/upgrades/index.js DELETED
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createUpgrades = void 0;
7
-
8
- var _ = require("./5.33.0");
9
-
10
- const createUpgrades = () => [(0, _.createUpgrade)()];
11
-
12
- exports.createUpgrades = createUpgrades;
@@ -1 +0,0 @@
1
- {"version":3,"names":["createUpgrades","create533Upgrade"],"sources":["index.ts"],"sourcesContent":["import { createUpgrade as create533Upgrade } from \"~/upgrades/5.33.0\";\n\nexport const createUpgrades = () => [create533Upgrade()];\n"],"mappings":";;;;;;;AAAA;;AAEO,MAAMA,cAAc,GAAG,MAAM,CAAC,IAAAC,eAAA,GAAD,CAA7B"}
@@ -1 +0,0 @@
1
- export declare const pluralizedTypeName: (typeName: string) => string;
@@ -1,26 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.pluralizedTypeName = void 0;
9
-
10
- var _pluralize = _interopRequireDefault(require("pluralize"));
11
-
12
- // This will make it so if the content model name is a single capitalized letter
13
- // Ex. A, pluralizedTypeName will capitalize the name to As, instead of AS
14
- const pluralizedTypeName = typeName => {
15
- let pluralizedTypeName;
16
-
17
- if (typeName.length === 1) {
18
- pluralizedTypeName = `${typeName}s`;
19
- } else {
20
- pluralizedTypeName = (0, _pluralize.default)(typeName);
21
- }
22
-
23
- return pluralizedTypeName;
24
- };
25
-
26
- exports.pluralizedTypeName = pluralizedTypeName;
@@ -1 +0,0 @@
1
- {"version":3,"names":["pluralizedTypeName","typeName","length","pluralize"],"sources":["pluralizedTypeName.ts"],"sourcesContent":["import pluralize from \"pluralize\";\n\n// This will make it so if the content model name is a single capitalized letter\n// Ex. A, pluralizedTypeName will capitalize the name to As, instead of AS\nexport const pluralizedTypeName = (typeName: string): string => {\n let pluralizedTypeName;\n if (typeName.length === 1) {\n pluralizedTypeName = `${typeName}s`;\n } else {\n pluralizedTypeName = pluralize(typeName);\n }\n return pluralizedTypeName;\n};\n"],"mappings":";;;;;;;;;AAAA;;AAEA;AACA;AACO,MAAMA,kBAAkB,GAAIC,QAAD,IAA8B;EAC5D,IAAID,kBAAJ;;EACA,IAAIC,QAAQ,CAACC,MAAT,KAAoB,CAAxB,EAA2B;IACvBF,kBAAkB,GAAI,GAAEC,QAAS,GAAjC;EACH,CAFD,MAEO;IACHD,kBAAkB,GAAG,IAAAG,kBAAA,EAAUF,QAAV,CAArB;EACH;;EACD,OAAOD,kBAAP;AACH,CARM"}