@webiny/api-headless-cms 0.0.0-unstable.bca7b3e350 → 0.0.0-unstable.c59b9cc5b9

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 (215) hide show
  1. package/context.js +47 -43
  2. package/context.js.map +1 -1
  3. package/crud/contentEntry/markLockedFields.d.ts +1 -1
  4. package/crud/contentEntry/markLockedFields.js +3 -0
  5. package/crud/contentEntry/markLockedFields.js.map +1 -1
  6. package/crud/contentEntry/referenceFieldsMapping.js +34 -5
  7. package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
  8. package/crud/contentEntry.crud.d.ts +8 -5
  9. package/crud/contentEntry.crud.js +1023 -840
  10. package/crud/contentEntry.crud.js.map +1 -1
  11. package/crud/contentModel/beforeCreate.js +39 -76
  12. package/crud/contentModel/beforeCreate.js.map +1 -1
  13. package/crud/contentModel/beforeDelete.d.ts +1 -1
  14. package/crud/contentModel/beforeDelete.js +1 -5
  15. package/crud/contentModel/beforeDelete.js.map +1 -1
  16. package/crud/contentModel/beforeUpdate.js +31 -3
  17. package/crud/contentModel/beforeUpdate.js.map +1 -1
  18. package/crud/contentModel/compatibility/modelApiName.d.ts +3 -0
  19. package/crud/contentModel/compatibility/modelApiName.js +24 -0
  20. package/crud/contentModel/compatibility/modelApiName.js.map +1 -0
  21. package/crud/contentModel/defaultFields.d.ts +5 -0
  22. package/crud/contentModel/defaultFields.js +58 -0
  23. package/crud/contentModel/defaultFields.js.map +1 -0
  24. package/crud/contentModel/fields/descriptionField.d.ts +2 -0
  25. package/crud/contentModel/fields/descriptionField.js +42 -0
  26. package/crud/contentModel/fields/descriptionField.js.map +1 -0
  27. package/crud/contentModel/fields/imageField.d.ts +2 -0
  28. package/crud/contentModel/fields/imageField.js +46 -0
  29. package/crud/contentModel/fields/imageField.js.map +1 -0
  30. package/crud/contentModel/fields/titleField.d.ts +2 -0
  31. package/crud/contentModel/fields/titleField.js +58 -0
  32. package/crud/contentModel/fields/titleField.js.map +1 -0
  33. package/crud/contentModel/validate/endingAllowed.d.ts +6 -0
  34. package/crud/contentModel/validate/endingAllowed.js +26 -0
  35. package/crud/contentModel/validate/endingAllowed.js.map +1 -0
  36. package/crud/contentModel/validate/isModelEndingAllowed.d.ts +6 -0
  37. package/crud/contentModel/validate/isModelEndingAllowed.js +24 -0
  38. package/crud/contentModel/validate/isModelEndingAllowed.js.map +1 -0
  39. package/crud/contentModel/validate/modelId.d.ts +11 -0
  40. package/crud/contentModel/validate/modelId.js +36 -0
  41. package/crud/contentModel/validate/modelId.js.map +1 -0
  42. package/crud/contentModel/validate/pluralApiName.d.ts +7 -0
  43. package/crud/contentModel/validate/pluralApiName.js +24 -0
  44. package/crud/contentModel/validate/pluralApiName.js.map +1 -0
  45. package/crud/contentModel/validate/singularApiName.d.ts +7 -0
  46. package/crud/contentModel/validate/singularApiName.js +24 -0
  47. package/crud/contentModel/validate/singularApiName.js.map +1 -0
  48. package/crud/contentModel/validateModel.d.ts +1 -0
  49. package/crud/contentModel/validateModel.js.map +1 -1
  50. package/crud/contentModel/validateModelFields.d.ts +2 -1
  51. package/crud/contentModel/validateModelFields.js +19 -57
  52. package/crud/contentModel/validateModelFields.js.map +1 -1
  53. package/crud/contentModel/validation.d.ts +136 -62
  54. package/crud/contentModel/validation.js +61 -13
  55. package/crud/contentModel/validation.js.map +1 -1
  56. package/crud/contentModel.crud.js +346 -285
  57. package/crud/contentModel.crud.js.map +1 -1
  58. package/crud/contentModelGroup.crud.js +170 -148
  59. package/crud/contentModelGroup.crud.js.map +1 -1
  60. package/crud/settings.crud.d.ts +1 -1
  61. package/crud/settings.crud.js +5 -10
  62. package/crud/settings.crud.js.map +1 -1
  63. package/crud/system.crud.js +0 -60
  64. package/crud/system.crud.js.map +1 -1
  65. package/graphql/checkEndpointAccess.d.ts +2 -0
  66. package/graphql/checkEndpointAccess.js +18 -0
  67. package/graphql/checkEndpointAccess.js.map +1 -0
  68. package/graphql/createExecutableSchema.d.ts +2 -3
  69. package/graphql/createExecutableSchema.js.map +1 -1
  70. package/graphql/createRequestBody.d.ts +2 -0
  71. package/graphql/createRequestBody.js +14 -0
  72. package/graphql/createRequestBody.js.map +1 -0
  73. package/graphql/formatErrorPayload.d.ts +1 -0
  74. package/graphql/formatErrorPayload.js +25 -0
  75. package/graphql/formatErrorPayload.js.map +1 -0
  76. package/graphql/generateSchema.js.map +1 -1
  77. package/graphql/getSchema.d.ts +17 -0
  78. package/graphql/getSchema.js +102 -0
  79. package/graphql/getSchema.js.map +1 -0
  80. package/graphql/graphQLHandlerFactory.js +6 -145
  81. package/graphql/graphQLHandlerFactory.js.map +1 -1
  82. package/graphql/handleRequest.d.ts +11 -0
  83. package/graphql/handleRequest.js +81 -0
  84. package/graphql/handleRequest.js.map +1 -0
  85. package/graphql/schema/baseContentSchema.js +1 -7
  86. package/graphql/schema/baseContentSchema.js.map +1 -1
  87. package/graphql/schema/baseSchema.js +15 -0
  88. package/graphql/schema/baseSchema.js.map +1 -1
  89. package/graphql/schema/contentEntries.js +90 -53
  90. package/graphql/schema/contentEntries.js.map +1 -1
  91. package/graphql/schema/contentModelGroups.js +7 -7
  92. package/graphql/schema/contentModelGroups.js.map +1 -1
  93. package/graphql/schema/contentModels.js +23 -4
  94. package/graphql/schema/contentModels.js.map +1 -1
  95. package/graphql/schema/createFieldResolvers.d.ts +1 -1
  96. package/graphql/schema/createFieldResolvers.js +6 -12
  97. package/graphql/schema/createFieldResolvers.js.map +1 -1
  98. package/graphql/schema/createFieldTypePluginRecords.d.ts +3 -0
  99. package/graphql/schema/createFieldTypePluginRecords.js +13 -0
  100. package/graphql/schema/createFieldTypePluginRecords.js.map +1 -0
  101. package/graphql/schema/createManageResolvers.d.ts +1 -1
  102. package/graphql/schema/createManageResolvers.js +37 -17
  103. package/graphql/schema/createManageResolvers.js.map +1 -1
  104. package/graphql/schema/createManageSDL.d.ts +1 -0
  105. package/graphql/schema/createManageSDL.js +76 -62
  106. package/graphql/schema/createManageSDL.js.map +1 -1
  107. package/graphql/schema/createPreviewResolvers.js +3 -7
  108. package/graphql/schema/createPreviewResolvers.js.map +1 -1
  109. package/graphql/schema/createReadResolvers.js +4 -8
  110. package/graphql/schema/createReadResolvers.js.map +1 -1
  111. package/graphql/schema/createReadSDL.d.ts +1 -0
  112. package/graphql/schema/createReadSDL.js +40 -35
  113. package/graphql/schema/createReadSDL.js.map +1 -1
  114. package/graphql/schema/resolvers/commonFieldResolvers.d.ts +3 -2
  115. package/graphql/schema/resolvers/commonFieldResolvers.js +2 -1
  116. package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
  117. package/graphql/schema/resolvers/manage/resolveDelete.d.ts +2 -1
  118. package/graphql/schema/resolvers/manage/resolveDelete.js +13 -3
  119. package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
  120. package/graphql/schema/resolvers/manage/resolveDeleteMultiple.d.ts +7 -0
  121. package/graphql/schema/resolvers/manage/resolveDeleteMultiple.js +20 -0
  122. package/graphql/schema/resolvers/manage/resolveDeleteMultiple.js.map +1 -0
  123. package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.d.ts +4 -0
  124. package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.js +18 -0
  125. package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.js.map +1 -0
  126. package/graphql/schema/schemaPlugins.js +7 -16
  127. package/graphql/schema/schemaPlugins.js.map +1 -1
  128. package/graphql/system.js +0 -16
  129. package/graphql/system.js.map +1 -1
  130. package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +1 -1
  131. package/graphqlFields/dynamicZone/dynamicZoneField.js +54 -19
  132. package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -1
  133. package/graphqlFields/object.js +21 -2
  134. package/graphqlFields/object.js.map +1 -1
  135. package/graphqlFields/ref.js +42 -14
  136. package/graphqlFields/ref.js.map +1 -1
  137. package/index.d.ts +3 -1
  138. package/index.js +25 -2
  139. package/index.js.map +1 -1
  140. package/package.json +35 -36
  141. package/plugins/CmsModelPlugin.d.ts +21 -3
  142. package/plugins/CmsModelPlugin.js +28 -2
  143. package/plugins/CmsModelPlugin.js.map +1 -1
  144. package/plugins/StorageOperationsCmsModelPlugin.d.ts +23 -0
  145. package/plugins/StorageOperationsCmsModelPlugin.js +42 -0
  146. package/plugins/StorageOperationsCmsModelPlugin.js.map +1 -0
  147. package/plugins/index.d.ts +1 -0
  148. package/plugins/index.js +11 -0
  149. package/plugins/index.js.map +1 -1
  150. package/types.d.ts +200 -97
  151. package/types.js +12 -1
  152. package/types.js.map +1 -1
  153. package/utils/converters/valueKeyStorageConverter.d.ts +1 -5
  154. package/utils/converters/valueKeyStorageConverter.js +26 -20
  155. package/utils/converters/valueKeyStorageConverter.js.map +1 -1
  156. package/utils/createTypeFromFields.d.ts +1 -0
  157. package/utils/createTypeFromFields.js +7 -5
  158. package/utils/createTypeFromFields.js.map +1 -1
  159. package/utils/createTypeName.d.ts +0 -2
  160. package/utils/createTypeName.js +2 -10
  161. package/utils/createTypeName.js.map +1 -1
  162. package/utils/getBaseFieldType.d.ts +1 -3
  163. package/utils/getBaseFieldType.js.map +1 -1
  164. package/utils/getEntryDescription.d.ts +2 -0
  165. package/utils/getEntryDescription.js +17 -0
  166. package/utils/getEntryDescription.js.map +1 -0
  167. package/utils/getEntryImage.d.ts +2 -0
  168. package/utils/getEntryImage.js +17 -0
  169. package/utils/getEntryImage.js.map +1 -0
  170. package/utils/getEntryTitle.d.ts +1 -1
  171. package/utils/getEntryTitle.js.map +1 -1
  172. package/utils/incrementEntryIdVersion.d.ts +5 -0
  173. package/utils/incrementEntryIdVersion.js +29 -0
  174. package/utils/incrementEntryIdVersion.js.map +1 -0
  175. package/utils/ownership.d.ts +3 -3
  176. package/utils/ownership.js.map +1 -1
  177. package/utils/renderFields.d.ts +4 -2
  178. package/utils/renderFields.js +10 -2
  179. package/utils/renderFields.js.map +1 -1
  180. package/utils/renderGetFilterFields.d.ts +2 -2
  181. package/utils/renderGetFilterFields.js +7 -20
  182. package/utils/renderGetFilterFields.js.map +1 -1
  183. package/utils/renderInputFields.d.ts +4 -2
  184. package/utils/renderInputFields.js +17 -5
  185. package/utils/renderInputFields.js.map +1 -1
  186. package/utils/renderListFilterFields.d.ts +2 -1
  187. package/utils/renderListFilterFields.js +9 -20
  188. package/utils/renderListFilterFields.js.map +1 -1
  189. package/utils/renderSortEnum.d.ts +2 -1
  190. package/utils/renderSortEnum.js +2 -1
  191. package/utils/renderSortEnum.js.map +1 -1
  192. package/crud/contentModel/createFieldModels.d.ts +0 -2
  193. package/crud/contentModel/createFieldModels.js +0 -26
  194. package/crud/contentModel/createFieldModels.js.map +0 -1
  195. package/crud/contentModel/fieldIdValidation.d.ts +0 -1
  196. package/crud/contentModel/fieldIdValidation.js +0 -25
  197. package/crud/contentModel/fieldIdValidation.js.map +0 -1
  198. package/crud/contentModel/idValidation.d.ts +0 -1
  199. package/crud/contentModel/idValidation.js +0 -22
  200. package/crud/contentModel/idValidation.js.map +0 -1
  201. package/crud/contentModel/models.d.ts +0 -4
  202. package/crud/contentModel/models.js +0 -192
  203. package/crud/contentModel/models.js.map +0 -1
  204. package/crud/contentModel/systemFields.d.ts +0 -1
  205. package/crud/contentModel/systemFields.js +0 -8
  206. package/crud/contentModel/systemFields.js.map +0 -1
  207. package/upgrades/5.33.0/index.d.ts +0 -3
  208. package/upgrades/5.33.0/index.js +0 -159
  209. package/upgrades/5.33.0/index.js.map +0 -1
  210. package/upgrades/index.d.ts +0 -1
  211. package/upgrades/index.js +0 -9
  212. package/upgrades/index.js.map +0 -1
  213. package/utils/pluralizedTypeName.d.ts +0 -1
  214. package/utils/pluralizedTypeName.js +0 -20
  215. package/utils/pluralizedTypeName.js.map +0 -1
@@ -1,2 +0,0 @@
1
- import { CmsModelField, CmsModelFieldInput } from "../../types";
2
- export declare const createFieldModels: (input?: CmsModelFieldInput[]) => Promise<CmsModelField[]>;
@@ -1,26 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createFieldModels = void 0;
7
-
8
- var _models = require("./models");
9
-
10
- const createFieldModels = async input => {
11
- if (!input || input.length === 0) {
12
- return [];
13
- }
14
-
15
- const fields = [];
16
-
17
- for (const field of input) {
18
- const fieldData = new _models.ContentModelFieldModel().populate(field);
19
- await fieldData.validate();
20
- fields.push(await fieldData.toJSON());
21
- }
22
-
23
- return fields;
24
- };
25
-
26
- exports.createFieldModels = createFieldModels;
@@ -1 +0,0 @@
1
- {"version":3,"names":["createFieldModels","input","length","fields","field","fieldData","ContentModelFieldModel","populate","validate","push","toJSON"],"sources":["createFieldModels.ts"],"sourcesContent":["import { CmsModelField, CmsModelFieldInput } from \"~/types\";\nimport { ContentModelFieldModel } from \"./models\";\n\nexport const createFieldModels = async (input?: CmsModelFieldInput[]): Promise<CmsModelField[]> => {\n if (!input || input.length === 0) {\n return [];\n }\n const fields: CmsModelField[] = [];\n for (const field of input) {\n const fieldData = new ContentModelFieldModel().populate(field);\n await fieldData.validate();\n fields.push(await fieldData.toJSON());\n }\n return fields;\n};\n"],"mappings":";;;;;;;AACA;;AAEO,MAAMA,iBAAiB,GAAG,MAAOC,KAAP,IAAkE;EAC/F,IAAI,CAACA,KAAD,IAAUA,KAAK,CAACC,MAAN,KAAiB,CAA/B,EAAkC;IAC9B,OAAO,EAAP;EACH;;EACD,MAAMC,MAAuB,GAAG,EAAhC;;EACA,KAAK,MAAMC,KAAX,IAAoBH,KAApB,EAA2B;IACvB,MAAMI,SAAS,GAAG,IAAIC,8BAAJ,GAA6BC,QAA7B,CAAsCH,KAAtC,CAAlB;IACA,MAAMC,SAAS,CAACG,QAAV,EAAN;IACAL,MAAM,CAACM,IAAP,CAAY,MAAMJ,SAAS,CAACK,MAAV,EAAlB;EACH;;EACD,OAAOP,MAAP;AACH,CAXM"}
@@ -1 +0,0 @@
1
- export declare const validateFieldId: (input: string) => Promise<void>;
@@ -1,25 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.validateFieldId = void 0;
7
-
8
- var _validation = require("@webiny/validation");
9
-
10
- var _systemFields = require("./systemFields");
11
-
12
- const validateFieldId = async input => {
13
- await _validation.validation.validate(input, "required,maxLength:100");
14
- const value = String(input || "").trim();
15
-
16
- if (!value.charAt(0).match(/^[a-zA-Z]/)) {
17
- throw new Error(`Provided ${value} is not valid - must not start with a number.`);
18
- } else if (value.match(/^([a-zA-Z0-9]+)$/) === null) {
19
- throw new Error(`Provided ${value} is not valid - must be alphanumeric string.`);
20
- } else if (_systemFields.fieldSystemFields.includes(value)) {
21
- throw new Error(`Provided ${value} is not valid - "${value}" is an auto-generated field.`);
22
- }
23
- };
24
-
25
- exports.validateFieldId = validateFieldId;
@@ -1 +0,0 @@
1
- {"version":3,"names":["validateFieldId","input","validation","validate","value","String","trim","charAt","match","Error","fieldSystemFields","includes"],"sources":["fieldIdValidation.ts"],"sourcesContent":["import { validation } from \"@webiny/validation\";\nimport { fieldSystemFields } from \"~/crud/contentModel/systemFields\";\n\nexport const validateFieldId = async (input: string): Promise<void> => {\n await validation.validate(input, \"required,maxLength:100\");\n\n const value = String(input || \"\").trim();\n\n if (!value.charAt(0).match(/^[a-zA-Z]/)) {\n throw new Error(`Provided ${value} is not valid - must not start with a number.`);\n } else if (value.match(/^([a-zA-Z0-9]+)$/) === null) {\n throw new Error(`Provided ${value} is not valid - must be alphanumeric string.`);\n } else if (fieldSystemFields.includes(value)) {\n throw new Error(`Provided ${value} is not valid - \"${value}\" is an auto-generated field.`);\n }\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AAEO,MAAMA,eAAe,GAAG,MAAOC,KAAP,IAAwC;EACnE,MAAMC,sBAAA,CAAWC,QAAX,CAAoBF,KAApB,EAA2B,wBAA3B,CAAN;EAEA,MAAMG,KAAK,GAAGC,MAAM,CAACJ,KAAK,IAAI,EAAV,CAAN,CAAoBK,IAApB,EAAd;;EAEA,IAAI,CAACF,KAAK,CAACG,MAAN,CAAa,CAAb,EAAgBC,KAAhB,CAAsB,WAAtB,CAAL,EAAyC;IACrC,MAAM,IAAIC,KAAJ,CAAW,YAAWL,KAAM,+CAA5B,CAAN;EACH,CAFD,MAEO,IAAIA,KAAK,CAACI,KAAN,CAAY,kBAAZ,MAAoC,IAAxC,EAA8C;IACjD,MAAM,IAAIC,KAAJ,CAAW,YAAWL,KAAM,8CAA5B,CAAN;EACH,CAFM,MAEA,IAAIM,+BAAA,CAAkBC,QAAlB,CAA2BP,KAA3B,CAAJ,EAAuC;IAC1C,MAAM,IAAIK,KAAJ,CAAW,YAAWL,KAAM,oBAAmBA,KAAM,+BAArD,CAAN;EACH;AACJ,CAZM"}
@@ -1 +0,0 @@
1
- export declare const validateId: (value: string) => Promise<void>;
@@ -1,22 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.validateId = void 0;
7
-
8
- var _validation = require("@webiny/validation");
9
-
10
- const validateId = async value => {
11
- await _validation.validation.validate(value, "required,maxLength:100");
12
-
13
- if (!value.charAt(0).match(/[a-zA-Z]/)) {
14
- throw new Error(`Provided ID ${value} is not valid - must not start with a number.`);
15
- }
16
-
17
- if (value.trim().toLowerCase() === "id") {
18
- throw new Error(`Provided ID ${value} is not valid - "id" is an auto-generated field.`);
19
- }
20
- };
21
-
22
- exports.validateId = validateId;
@@ -1 +0,0 @@
1
- {"version":3,"names":["validateId","value","validation","validate","charAt","match","Error","trim","toLowerCase"],"sources":["idValidation.ts"],"sourcesContent":["import { validation } from \"@webiny/validation\";\n\nexport const validateId = async (value: string): Promise<void> => {\n await validation.validate(value, \"required,maxLength:100\");\n if (!value.charAt(0).match(/[a-zA-Z]/)) {\n throw new Error(`Provided ID ${value} is not valid - must not start with a number.`);\n }\n if (value.trim().toLowerCase() === \"id\") {\n throw new Error(`Provided ID ${value} is not valid - \"id\" is an auto-generated field.`);\n }\n};\n"],"mappings":";;;;;;;AAAA;;AAEO,MAAMA,UAAU,GAAG,MAAOC,KAAP,IAAwC;EAC9D,MAAMC,sBAAA,CAAWC,QAAX,CAAoBF,KAApB,EAA2B,wBAA3B,CAAN;;EACA,IAAI,CAACA,KAAK,CAACG,MAAN,CAAa,CAAb,EAAgBC,KAAhB,CAAsB,UAAtB,CAAL,EAAwC;IACpC,MAAM,IAAIC,KAAJ,CAAW,eAAcL,KAAM,+CAA/B,CAAN;EACH;;EACD,IAAIA,KAAK,CAACM,IAAN,GAAaC,WAAb,OAA+B,IAAnC,EAAyC;IACrC,MAAM,IAAIF,KAAJ,CAAW,eAAcL,KAAM,kDAA/B,CAAN;EACH;AACJ,CARM"}
@@ -1,4 +0,0 @@
1
- export declare const ContentModelFieldModel: any;
2
- export declare const CreateContentModelModel: any;
3
- export declare const CreateContentModelModelFrom: any;
4
- export declare const UpdateContentModelModel: any;
@@ -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;E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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,IAAI,EACJ,SAAS,EACT,WAAW,EACX,OAAO,EACP,UAAU,EACV,iBAAiB,EACjB,MAAM,EACN,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,YAAY,EACZ,gBAAgB,EAChB,UAAU,CACb;AAAC"}
@@ -1,3 +0,0 @@
1
- import { UpgradePlugin } from "@webiny/api-upgrade";
2
- import { CmsContext } from "../../types";
3
- export declare const createUpgrade: () => UpgradePlugin<CmsContext>;
@@ -1,159 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createUpgrade = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
- var _error = _interopRequireDefault(require("@webiny/error"));
10
- const assignStorageId = fields => {
11
- return fields.map(field => {
12
- const settings = (0, _objectSpread2.default)({}, field.settings || {});
13
- if (settings.fields && Array.isArray(settings.fields) === true) {
14
- settings.fields = assignStorageId(settings.fields);
15
- }
16
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, field), {}, {
17
- storageId: field.fieldId,
18
- settings
19
- });
20
- });
21
- };
22
- /**
23
- * If at least one field does not have storageId define, we should definitely update the model.
24
- */
25
- const shouldUpdate = fields => {
26
- return fields.some(field => {
27
- var _field$settings;
28
- if ((_field$settings = field.settings) !== null && _field$settings !== void 0 && _field$settings.fields) {
29
- return shouldUpdate(field.settings.fields);
30
- }
31
- return !field.storageId;
32
- });
33
- };
34
- const upgradeTenantModels = async params => {
35
- const {
36
- tenant,
37
- cms,
38
- i18n
39
- } = params;
40
- /**
41
- * We need all locales for this tenant, so we can go and find all models for all the locales.
42
- */
43
- const [locales] = await i18n.locales.storageOperations.list({
44
- where: {
45
- tenant: tenant.id
46
- },
47
- limit: 100
48
- });
49
- if (locales.length === 0) {
50
- console.log(`There are no locales under the tenant "${tenant.id}".`);
51
- return;
52
- }
53
- for (const locale of locales) {
54
- /**
55
- * We need all the models that are not plugin models.
56
- */
57
- const models = await cms.storageOperations.models.list({
58
- where: {
59
- tenant: tenant.id,
60
- locale: locale.code
61
- }
62
- });
63
- if (models.length === 0) {
64
- console.log(`No models in tenant "${tenant.id}" and locale "${locale.code}" combination.`);
65
- continue;
66
- }
67
-
68
- /**
69
- * Then we need to go into each of the model fields and add the storageId, which is the same as the fieldId
70
- */
71
- const updatedModels = models.filter(model => {
72
- /**
73
- * If model has at least one field with no storageId, continue with the update.
74
- */
75
- const toUpdate = shouldUpdate(model.fields);
76
-
77
- /**
78
- * If not updating the model, lets log it - just in case...
79
- */
80
- if (!toUpdate) {
81
- console.log(`Skipping update of model "${model.modelId} - ${tenant.id} - ${locale.code}".`);
82
- return false;
83
- }
84
- return true;
85
- }).map(model => {
86
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, model), {}, {
87
- fields: assignStorageId(model.fields)
88
- });
89
- });
90
- /**
91
- * And update all the models
92
- */
93
- for (const model of updatedModels) {
94
- try {
95
- await cms.storageOperations.models.update({
96
- model
97
- });
98
- } catch (ex) {
99
- throw new _error.default(`Could not update CMS model ${model.modelId}`, "MODEL_UPGRADE_ERROR", {
100
- model
101
- });
102
- }
103
- }
104
- }
105
- /**
106
- * In the end we need to write the new cms system version.
107
- */
108
- await cms.setSystemVersion("5.33.0");
109
- };
110
- const createUpgrade = () => {
111
- return {
112
- type: "api-upgrade",
113
- version: "5.33.0",
114
- app: "headless-cms",
115
- apply: async context => {
116
- const {
117
- security,
118
- tenancy,
119
- cms,
120
- i18n
121
- } = context;
122
-
123
- /**
124
- * We need to be able to access all data.
125
- */
126
- security.disableAuthorization();
127
- const initialTenant = tenancy.getCurrentTenant();
128
- const tenants = await tenancy.listTenants();
129
- try {
130
- for (const tenant of tenants) {
131
- tenancy.setCurrentTenant(tenant);
132
- await upgradeTenantModels({
133
- tenant,
134
- cms,
135
- i18n
136
- });
137
- }
138
- } catch (ex) {
139
- console.log(`Upgrade error: ${JSON.stringify({
140
- message: ex.message,
141
- code: ex.code,
142
- data: ex.data
143
- })}`);
144
- throw new _error.default(`Could not finish the 5.33.0 upgrade. Please contact Webiny team on Slack and share the error.`, "UPGRADE_ERROR", {
145
- message: ex.message,
146
- code: ex.code,
147
- data: ex.data
148
- });
149
- } finally {
150
- /**
151
- * Always enable the security after all the code runs.
152
- */
153
- security.enableAuthorization();
154
- tenancy.setCurrentTenant(initialTenant);
155
- }
156
- }
157
- };
158
- };
159
- 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,MAAuB,IAAsB;EAClE,OAAOA,MAAM,CAACC,GAAG,CAACC,KAAK,IAAI;IACvB,MAAMC,QAAQ,mCACND,KAAK,CAACC,QAAQ,IAAI,CAAC,CAAC,CAC3B;IACD,IAAIA,QAAQ,CAACH,MAAM,IAAII,KAAK,CAACC,OAAO,CAACF,QAAQ,CAACH,MAAM,CAAC,KAAK,IAAI,EAAE;MAC5DG,QAAQ,CAACH,MAAM,GAAGD,eAAe,CAACI,QAAQ,CAACH,MAAM,CAAC;IACtD;IACA,mEACOE,KAAK;MACRI,SAAS,EAAEJ,KAAK,CAACK,OAAO;M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B,MAAMC,aAAa,GAAGF,OAAO,CAACG,gBAAgB,EAAE;MAEhD,MAAMC,OAAO,GAAG,MAAMJ,OAAO,CAACK,WAAW,EAAE;MAC3C,IAAI;QACA,KAAK,MAAMpC,MAAM,IAAImC,OAAO,EAAE;UAC1BJ,OAAO,CAACM,gBAAgB,CAACrC,MAAM,CAAC;UAChC,MAAMF,mBAAmB,CAAC;YACtBE,MAAM;YACNC,GAAG;YACHC;UACJ,CAAC,CAAC;QACN;MACJ,CAAC,CAAC,OAAOmB,EAAE,EAAE;QACTX,OAAO,CAACC,GAAG,CACN,kBAAiB2B,IAAI,CAACC,SAAS,CAAC;UAC7BC,OAAO,EAAEnB,EAAE,CAACmB,OAAO;UACnB1B,IAAI,EAAEO,EAAE,CAACP,IAAI;UACb2B,IAAI,EAAEpB,EAAE,CAACoB;QACb,CAAC,CAAE,EAAC,CACP;QACD,MAAM,IAAInB,cAAW,CAChB,+FAA8F,EAC/F,eAAe,EACf;UACIkB,OAAO,EAAEnB,EAAE,CAACmB,OAAO;UACnB1B,IAAI,EAAEO,EAAE,CAACP,IAAI;UACb2B,IAAI,EAAEpB,EAAE,CAACoB;QACb,CAAC,CACJ;MACL,CAAC,SAAS;QACN;AAChB;AACA;QACgBX,QAAQ,CAACY,mBAAmB,EAAE;QAC9BX,OAAO,CAACM,gBAAgB,CAACJ,aAAa,CAAC;MAC3C;IACJ;EACJ,CAAC;AACL,CAAC;AAAC"}
@@ -1 +0,0 @@
1
- export declare const createUpgrades: () => import("@webiny/api-upgrade").UpgradePlugin<import("../types").CmsContext>[];
package/upgrades/index.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createUpgrades = void 0;
7
- var _ = require("./5.33.0");
8
- const createUpgrades = () => [(0, _.createUpgrade)()];
9
- 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,eAAgB,GAAE,CAAC;AAAC"}
@@ -1 +0,0 @@
1
- export declare const pluralizedTypeName: (typeName: string) => string;
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.pluralizedTypeName = void 0;
8
- var _pluralize = _interopRequireDefault(require("pluralize"));
9
- // This will make it so if the content model name is a single capitalized letter
10
- // Ex. A, pluralizedTypeName will capitalize the name to As, instead of AS
11
- const pluralizedTypeName = typeName => {
12
- let pluralizedTypeName;
13
- if (typeName.length === 1) {
14
- pluralizedTypeName = `${typeName}s`;
15
- } else {
16
- pluralizedTypeName = (0, _pluralize.default)(typeName);
17
- }
18
- return pluralizedTypeName;
19
- };
20
- 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,QAAgB,IAAa;EAC5D,IAAID,kBAAkB;EACtB,IAAIC,QAAQ,CAACC,MAAM,KAAK,CAAC,EAAE;IACvBF,kBAAkB,GAAI,GAAEC,QAAS,GAAE;EACvC,CAAC,MAAM;IACHD,kBAAkB,GAAG,IAAAG,kBAAS,EAACF,QAAQ,CAAC;EAC5C;EACA,OAAOD,kBAAkB;AAC7B,CAAC;AAAC"}