@webiny/api-headless-cms 0.0.0-mt-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 (231) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +73 -0
  3. package/content/contextSetup.d.ts +4 -0
  4. package/content/contextSetup.js +65 -0
  5. package/content/graphQLHandlerFactory.d.ts +5 -0
  6. package/content/graphQLHandlerFactory.js +173 -0
  7. package/content/plugins/CmsGroupPlugin.d.ts +11 -0
  8. package/content/plugins/CmsGroupPlugin.js +24 -0
  9. package/content/plugins/CmsModelPlugin.d.ts +11 -0
  10. package/content/plugins/CmsModelPlugin.js +24 -0
  11. package/content/plugins/buildSchemaPlugins.d.ts +7 -0
  12. package/content/plugins/buildSchemaPlugins.js +29 -0
  13. package/content/plugins/crud/contentEntry/afterDelete.d.ts +7 -0
  14. package/content/plugins/crud/contentEntry/afterDelete.js +41 -0
  15. package/content/plugins/crud/contentEntry/beforeCreate.d.ts +7 -0
  16. package/content/plugins/crud/contentEntry/beforeCreate.js +28 -0
  17. package/content/plugins/crud/contentEntry/beforeUpdate.d.ts +7 -0
  18. package/content/plugins/crud/contentEntry/beforeUpdate.js +28 -0
  19. package/content/plugins/crud/contentEntry/entryDataValidation.d.ts +4 -0
  20. package/content/plugins/crud/contentEntry/entryDataValidation.js +188 -0
  21. package/content/plugins/crud/contentEntry/markLockedFields.d.ts +12 -0
  22. package/content/plugins/crud/contentEntry/markLockedFields.js +117 -0
  23. package/content/plugins/crud/contentEntry.crud.d.ts +17 -0
  24. package/content/plugins/crud/contentEntry.crud.js +931 -0
  25. package/content/plugins/crud/contentModel/afterCreate.d.ts +7 -0
  26. package/content/plugins/crud/contentModel/afterCreate.js +18 -0
  27. package/content/plugins/crud/contentModel/afterDelete.d.ts +7 -0
  28. package/content/plugins/crud/contentModel/afterDelete.js +18 -0
  29. package/content/plugins/crud/contentModel/afterUpdate.d.ts +7 -0
  30. package/content/plugins/crud/contentModel/afterUpdate.js +18 -0
  31. package/content/plugins/crud/contentModel/beforeCreate.d.ts +9 -0
  32. package/content/plugins/crud/contentModel/beforeCreate.js +146 -0
  33. package/content/plugins/crud/contentModel/beforeDelete.d.ts +9 -0
  34. package/content/plugins/crud/contentModel/beforeDelete.js +56 -0
  35. package/content/plugins/crud/contentModel/beforeUpdate.d.ts +9 -0
  36. package/content/plugins/crud/contentModel/beforeUpdate.js +128 -0
  37. package/content/plugins/crud/contentModel/contentModelManagerFactory.d.ts +2 -0
  38. package/content/plugins/crud/contentModel/contentModelManagerFactory.js +29 -0
  39. package/content/plugins/crud/contentModel/createFieldModels.d.ts +2 -0
  40. package/content/plugins/crud/contentModel/createFieldModels.js +22 -0
  41. package/content/plugins/crud/contentModel/idValidation.d.ts +2 -0
  42. package/content/plugins/crud/contentModel/idValidation.js +22 -0
  43. package/content/plugins/crud/contentModel/models.d.ts +3 -0
  44. package/content/plugins/crud/contentModel/models.js +141 -0
  45. package/content/plugins/crud/contentModel/validateLayout.d.ts +2 -0
  46. package/content/plugins/crud/contentModel/validateLayout.js +38 -0
  47. package/content/plugins/crud/contentModel.crud.d.ts +12 -0
  48. package/content/plugins/crud/contentModel.crud.js +425 -0
  49. package/content/plugins/crud/contentModelGroup/beforeCreate.d.ts +9 -0
  50. package/content/plugins/crud/contentModelGroup/beforeCreate.js +66 -0
  51. package/content/plugins/crud/contentModelGroup/beforeDelete.d.ts +9 -0
  52. package/content/plugins/crud/contentModelGroup/beforeDelete.js +48 -0
  53. package/content/plugins/crud/contentModelGroup/beforeUpdate.d.ts +8 -0
  54. package/content/plugins/crud/contentModelGroup/beforeUpdate.js +28 -0
  55. package/content/plugins/crud/contentModelGroup.crud.d.ts +12 -0
  56. package/content/plugins/crud/contentModelGroup.crud.js +351 -0
  57. package/content/plugins/crud/index.d.ts +6 -0
  58. package/content/plugins/crud/index.js +100 -0
  59. package/content/plugins/graphqlFields/boolean.d.ts +3 -0
  60. package/content/plugins/graphqlFields/boolean.js +69 -0
  61. package/content/plugins/graphqlFields/datetime.d.ts +3 -0
  62. package/content/plugins/graphqlFields/datetime.js +83 -0
  63. package/content/plugins/graphqlFields/file.d.ts +3 -0
  64. package/content/plugins/graphqlFields/file.js +49 -0
  65. package/content/plugins/graphqlFields/index.d.ts +2 -0
  66. package/content/plugins/graphqlFields/index.js +30 -0
  67. package/content/plugins/graphqlFields/longText.d.ts +3 -0
  68. package/content/plugins/graphqlFields/longText.js +62 -0
  69. package/content/plugins/graphqlFields/number.d.ts +3 -0
  70. package/content/plugins/graphqlFields/number.js +75 -0
  71. package/content/plugins/graphqlFields/object.d.ts +3 -0
  72. package/content/plugins/graphqlFields/object.js +180 -0
  73. package/content/plugins/graphqlFields/ref.d.ts +3 -0
  74. package/content/plugins/graphqlFields/ref.js +205 -0
  75. package/content/plugins/graphqlFields/richText.d.ts +3 -0
  76. package/content/plugins/graphqlFields/richText.js +55 -0
  77. package/content/plugins/graphqlFields/text.d.ts +3 -0
  78. package/content/plugins/graphqlFields/text.js +72 -0
  79. package/content/plugins/internalSecurity/InternalAuthenticationPlugin.d.ts +8 -0
  80. package/content/plugins/internalSecurity/InternalAuthenticationPlugin.js +54 -0
  81. package/content/plugins/internalSecurity/InternalAuthorizationPlugin.d.ts +7 -0
  82. package/content/plugins/internalSecurity/InternalAuthorizationPlugin.js +35 -0
  83. package/content/plugins/modelManager/DefaultCmsModelManager.d.ts +15 -0
  84. package/content/plugins/modelManager/DefaultCmsModelManager.js +62 -0
  85. package/content/plugins/modelManager/index.d.ts +3 -0
  86. package/content/plugins/modelManager/index.js +20 -0
  87. package/content/plugins/schema/baseSchema.d.ts +4 -0
  88. package/content/plugins/schema/baseSchema.js +98 -0
  89. package/content/plugins/schema/contentEntries.d.ts +4 -0
  90. package/content/plugins/schema/contentEntries.js +166 -0
  91. package/content/plugins/schema/contentModelGroups.d.ts +4 -0
  92. package/content/plugins/schema/contentModelGroups.js +153 -0
  93. package/content/plugins/schema/contentModels.d.ts +4 -0
  94. package/content/plugins/schema/contentModels.js +225 -0
  95. package/content/plugins/schema/createFieldResolvers.d.ts +19 -0
  96. package/content/plugins/schema/createFieldResolvers.js +92 -0
  97. package/content/plugins/schema/createManageResolvers.d.ts +11 -0
  98. package/content/plugins/schema/createManageResolvers.js +135 -0
  99. package/content/plugins/schema/createManageSDL.d.ts +9 -0
  100. package/content/plugins/schema/createManageSDL.js +153 -0
  101. package/content/plugins/schema/createPreviewResolvers.d.ts +10 -0
  102. package/content/plugins/schema/createPreviewResolvers.js +55 -0
  103. package/content/plugins/schema/createReadResolvers.d.ts +10 -0
  104. package/content/plugins/schema/createReadResolvers.js +55 -0
  105. package/content/plugins/schema/createReadSDL.d.ts +9 -0
  106. package/content/plugins/schema/createReadSDL.js +96 -0
  107. package/content/plugins/schema/resolvers/commonFieldResolvers.d.ts +6 -0
  108. package/content/plugins/schema/resolvers/commonFieldResolvers.js +14 -0
  109. package/content/plugins/schema/resolvers/manage/resolveCreate.d.ts +6 -0
  110. package/content/plugins/schema/resolvers/manage/resolveCreate.js +23 -0
  111. package/content/plugins/schema/resolvers/manage/resolveCreateFrom.d.ts +7 -0
  112. package/content/plugins/schema/resolvers/manage/resolveCreateFrom.js +23 -0
  113. package/content/plugins/schema/resolvers/manage/resolveDelete.d.ts +2 -0
  114. package/content/plugins/schema/resolvers/manage/resolveDelete.js +30 -0
  115. package/content/plugins/schema/resolvers/manage/resolveGet.d.ts +2 -0
  116. package/content/plugins/schema/resolvers/manage/resolveGet.js +21 -0
  117. package/content/plugins/schema/resolvers/manage/resolveGetByIds.d.ts +2 -0
  118. package/content/plugins/schema/resolvers/manage/resolveGetByIds.js +23 -0
  119. package/content/plugins/schema/resolvers/manage/resolveGetRevisions.d.ts +2 -0
  120. package/content/plugins/schema/resolvers/manage/resolveGetRevisions.js +23 -0
  121. package/content/plugins/schema/resolvers/manage/resolveList.d.ts +2 -0
  122. package/content/plugins/schema/resolvers/manage/resolveList.js +23 -0
  123. package/content/plugins/schema/resolvers/manage/resolvePublish.d.ts +2 -0
  124. package/content/plugins/schema/resolvers/manage/resolvePublish.js +21 -0
  125. package/content/plugins/schema/resolvers/manage/resolveRequestChanges.d.ts +6 -0
  126. package/content/plugins/schema/resolvers/manage/resolveRequestChanges.js +23 -0
  127. package/content/plugins/schema/resolvers/manage/resolveRequestReview.d.ts +6 -0
  128. package/content/plugins/schema/resolvers/manage/resolveRequestReview.js +23 -0
  129. package/content/plugins/schema/resolvers/manage/resolveUnpublish.d.ts +2 -0
  130. package/content/plugins/schema/resolvers/manage/resolveUnpublish.js +21 -0
  131. package/content/plugins/schema/resolvers/manage/resolveUpdate.d.ts +7 -0
  132. package/content/plugins/schema/resolvers/manage/resolveUpdate.js +23 -0
  133. package/content/plugins/schema/resolvers/preview/resolveGet.d.ts +2 -0
  134. package/content/plugins/schema/resolvers/preview/resolveGet.js +38 -0
  135. package/content/plugins/schema/resolvers/preview/resolveList.d.ts +2 -0
  136. package/content/plugins/schema/resolvers/preview/resolveList.js +23 -0
  137. package/content/plugins/schema/resolvers/read/resolveGet.d.ts +2 -0
  138. package/content/plugins/schema/resolvers/read/resolveGet.js +38 -0
  139. package/content/plugins/schema/resolvers/read/resolveList.d.ts +2 -0
  140. package/content/plugins/schema/resolvers/read/resolveList.js +23 -0
  141. package/content/plugins/schema/schemaPlugins.d.ts +3 -0
  142. package/content/plugins/schema/schemaPlugins.js +92 -0
  143. package/content/plugins/storage/StorageTransformPlugin.d.ts +30 -0
  144. package/content/plugins/storage/StorageTransformPlugin.js +36 -0
  145. package/content/plugins/storage/default.d.ts +3 -0
  146. package/content/plugins/storage/default.js +28 -0
  147. package/content/plugins/storage/object.d.ts +3 -0
  148. package/content/plugins/storage/object.js +119 -0
  149. package/content/plugins/utils/createTypeName.d.ts +3 -0
  150. package/content/plugins/utils/createTypeName.js +28 -0
  151. package/content/plugins/utils/entryStorage.d.ts +17 -0
  152. package/content/plugins/utils/entryStorage.js +125 -0
  153. package/content/plugins/utils/getEntryTitle.d.ts +2 -0
  154. package/content/plugins/utils/getEntryTitle.js +42 -0
  155. package/content/plugins/utils/getSchemaFromFieldPlugins.d.ts +11 -0
  156. package/content/plugins/utils/getSchemaFromFieldPlugins.js +30 -0
  157. package/content/plugins/utils/pluralizedTypeName.d.ts +1 -0
  158. package/content/plugins/utils/pluralizedTypeName.js +26 -0
  159. package/content/plugins/utils/renderFields.d.ts +16 -0
  160. package/content/plugins/utils/renderFields.js +51 -0
  161. package/content/plugins/utils/renderGetFilterFields.d.ts +9 -0
  162. package/content/plugins/utils/renderGetFilterFields.js +41 -0
  163. package/content/plugins/utils/renderInputFields.d.ts +14 -0
  164. package/content/plugins/utils/renderInputFields.js +53 -0
  165. package/content/plugins/utils/renderListFilterFields.d.ts +10 -0
  166. package/content/plugins/utils/renderListFilterFields.js +39 -0
  167. package/content/plugins/utils/renderSortEnum.d.ts +9 -0
  168. package/content/plugins/utils/renderSortEnum.js +32 -0
  169. package/content/plugins/validators/dateGte.d.ts +3 -0
  170. package/content/plugins/validators/dateGte.js +37 -0
  171. package/content/plugins/validators/dateLte.d.ts +3 -0
  172. package/content/plugins/validators/dateLte.js +37 -0
  173. package/content/plugins/validators/gte.d.ts +3 -0
  174. package/content/plugins/validators/gte.js +32 -0
  175. package/content/plugins/validators/in.d.ts +3 -0
  176. package/content/plugins/validators/in.js +32 -0
  177. package/content/plugins/validators/index.d.ts +2 -0
  178. package/content/plugins/validators/index.js +36 -0
  179. package/content/plugins/validators/lte.d.ts +3 -0
  180. package/content/plugins/validators/lte.js +32 -0
  181. package/content/plugins/validators/maxLength.d.ts +3 -0
  182. package/content/plugins/validators/maxLength.js +32 -0
  183. package/content/plugins/validators/minLength.d.ts +3 -0
  184. package/content/plugins/validators/minLength.js +32 -0
  185. package/content/plugins/validators/pattern.d.ts +3 -0
  186. package/content/plugins/validators/pattern.js +47 -0
  187. package/content/plugins/validators/patternPlugins/email.d.ts +3 -0
  188. package/content/plugins/validators/patternPlugins/email.js +17 -0
  189. package/content/plugins/validators/patternPlugins/index.d.ts +2 -0
  190. package/content/plugins/validators/patternPlugins/index.js +19 -0
  191. package/content/plugins/validators/patternPlugins/lowerCase.d.ts +3 -0
  192. package/content/plugins/validators/patternPlugins/lowerCase.js +17 -0
  193. package/content/plugins/validators/patternPlugins/upperCase.d.ts +3 -0
  194. package/content/plugins/validators/patternPlugins/upperCase.js +17 -0
  195. package/content/plugins/validators/patternPlugins/url.d.ts +3 -0
  196. package/content/plugins/validators/patternPlugins/url.js +17 -0
  197. package/content/plugins/validators/required.d.ts +3 -0
  198. package/content/plugins/validators/required.js +25 -0
  199. package/content/plugins/validators/timeGte.d.ts +3 -0
  200. package/content/plugins/validators/timeGte.js +32 -0
  201. package/content/plugins/validators/timeLte.d.ts +3 -0
  202. package/content/plugins/validators/timeLte.js +32 -0
  203. package/index.d.ts +12 -0
  204. package/index.js +66 -0
  205. package/migrateCMSPermissions.d.ts +17 -0
  206. package/migrateCMSPermissions.js +193 -0
  207. package/package.json +80 -0
  208. package/plugins/context.d.ts +4 -0
  209. package/plugins/context.js +34 -0
  210. package/plugins/crud/index.d.ts +6 -0
  211. package/plugins/crud/index.js +100 -0
  212. package/plugins/crud/settings.crud.d.ts +10 -0
  213. package/plugins/crud/settings.crud.js +93 -0
  214. package/plugins/crud/system.crud.d.ts +10 -0
  215. package/plugins/crud/system.crud.js +182 -0
  216. package/plugins/graphql/system.d.ts +17 -0
  217. package/plugins/graphql/system.js +72 -0
  218. package/plugins/graphql.d.ts +2 -0
  219. package/plugins/graphql.js +79 -0
  220. package/plugins/upgrades/index.d.ts +2 -0
  221. package/plugins/upgrades/index.js +14 -0
  222. package/plugins/upgrades/v5.5.0/helpers.d.ts +6 -0
  223. package/plugins/upgrades/v5.5.0/helpers.js +10 -0
  224. package/plugins/upgrades/v5.5.0/index.d.ts +4 -0
  225. package/plugins/upgrades/v5.5.0/index.js +129 -0
  226. package/transformers.d.ts +2 -0
  227. package/transformers.js +25 -0
  228. package/types.d.ts +2149 -0
  229. package/types.js +366 -0
  230. package/utils.d.ts +25 -0
  231. package/utils.js +251 -0
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.resolveList = void 0;
7
+
8
+ var _responses = require("@webiny/handler-graphql/responses");
9
+
10
+ const resolveList = ({
11
+ model
12
+ }) => async (_, args, {
13
+ cms
14
+ }) => {
15
+ try {
16
+ const response = await cms.listLatestEntries(model, args);
17
+ return new _responses.ListResponse(...response);
18
+ } catch (e) {
19
+ return new _responses.ListErrorResponse(e);
20
+ }
21
+ };
22
+
23
+ exports.resolveList = resolveList;
@@ -0,0 +1,2 @@
1
+ import { CmsEntryResolverFactory as ResolverFactory } from "../../../../../types";
2
+ export declare const resolveGet: ResolverFactory;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.resolveGet = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _responses = require("@webiny/handler-graphql/responses");
13
+
14
+ var _handlerGraphql = require("@webiny/handler-graphql");
15
+
16
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
17
+
18
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
19
+
20
+ const resolveGet = ({
21
+ model
22
+ }) => async (_, args, context) => {
23
+ try {
24
+ const [[entry]] = await context.cms.listPublishedEntries(model, _objectSpread(_objectSpread({}, args), {}, {
25
+ limit: 1
26
+ }));
27
+
28
+ if (!entry) {
29
+ throw new _handlerGraphql.NotFoundError(`Entry not found!`);
30
+ }
31
+
32
+ return new _responses.Response(entry);
33
+ } catch (e) {
34
+ return new _responses.ErrorResponse(e);
35
+ }
36
+ };
37
+
38
+ exports.resolveGet = resolveGet;
@@ -0,0 +1,2 @@
1
+ import { CmsEntryResolverFactory as ResolverFactory } from "../../../../../types";
2
+ export declare const resolveList: ResolverFactory;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.resolveList = void 0;
7
+
8
+ var _responses = require("@webiny/handler-graphql/responses");
9
+
10
+ const resolveList = ({
11
+ model
12
+ }) => async (_, args, {
13
+ cms
14
+ }) => {
15
+ try {
16
+ const response = await cms.listPublishedEntries(model, args);
17
+ return new _responses.ListResponse(...response);
18
+ } catch (e) {
19
+ return new _responses.ListErrorResponse(e);
20
+ }
21
+ };
22
+
23
+ exports.resolveList = resolveList;
@@ -0,0 +1,3 @@
1
+ import { GraphQLSchemaPlugin } from "@webiny/handler-graphql/plugins/GraphQLSchemaPlugin";
2
+ import { CmsContext } from "../../../types";
3
+ export declare const generateSchemaPlugins: (context: CmsContext) => Promise<GraphQLSchemaPlugin<CmsContext>[]>;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.generateSchemaPlugins = void 0;
7
+
8
+ var _GraphQLSchemaPlugin = require("@webiny/handler-graphql/plugins/GraphQLSchemaPlugin");
9
+
10
+ var _createManageSDL = require("./createManageSDL");
11
+
12
+ var _createReadSDL = require("./createReadSDL");
13
+
14
+ var _createManageResolvers = require("./createManageResolvers");
15
+
16
+ var _createReadResolvers = require("./createReadResolvers");
17
+
18
+ var _createPreviewResolvers = require("./createPreviewResolvers");
19
+
20
+ var _getSchemaFromFieldPlugins = require("../utils/getSchemaFromFieldPlugins");
21
+
22
+ const generateSchemaPlugins = async context => {
23
+ const {
24
+ plugins,
25
+ cms
26
+ } = context; // Structure plugins for faster access
27
+
28
+ const fieldTypePlugins = plugins.byType("cms-model-field-to-graphql").reduce((acc, pl) => {
29
+ acc[pl.fieldType] = pl;
30
+ return acc;
31
+ }, {}); // Load model data
32
+
33
+ context.security.disableAuthorization();
34
+ const models = await cms.listModels();
35
+ context.security.enableAuthorization();
36
+ const schemas = (0, _getSchemaFromFieldPlugins.getSchemaFromFieldPlugins)({
37
+ models,
38
+ fieldTypePlugins,
39
+ type: cms.type
40
+ });
41
+ const newPlugins = [];
42
+
43
+ for (const schema of schemas) {
44
+ newPlugins.push(new _GraphQLSchemaPlugin.GraphQLSchemaPlugin(schema));
45
+ }
46
+
47
+ models.filter(model => model.fields.length > 0).forEach(model => {
48
+ switch (cms.type) {
49
+ case "manage":
50
+ newPlugins.push(new _GraphQLSchemaPlugin.GraphQLSchemaPlugin({
51
+ typeDefs: (0, _createManageSDL.createManageSDL)({
52
+ model,
53
+ fieldTypePlugins
54
+ }),
55
+ resolvers: (0, _createManageResolvers.createManageResolvers)({
56
+ models,
57
+ model,
58
+ fieldTypePlugins,
59
+ context
60
+ })
61
+ }));
62
+ break;
63
+
64
+ case "preview":
65
+ case "read":
66
+ newPlugins.push(new _GraphQLSchemaPlugin.GraphQLSchemaPlugin({
67
+ typeDefs: (0, _createReadSDL.createReadSDL)({
68
+ model,
69
+ fieldTypePlugins
70
+ }),
71
+ resolvers: cms.READ ? (0, _createReadResolvers.createReadResolvers)({
72
+ models,
73
+ model,
74
+ fieldTypePlugins,
75
+ context
76
+ }) : (0, _createPreviewResolvers.createPreviewResolvers)({
77
+ models,
78
+ model,
79
+ fieldTypePlugins,
80
+ context
81
+ })
82
+ }));
83
+ break;
84
+
85
+ default:
86
+ return;
87
+ }
88
+ });
89
+ return newPlugins;
90
+ };
91
+
92
+ exports.generateSchemaPlugins = generateSchemaPlugins;
@@ -0,0 +1,30 @@
1
+ import { Plugin } from "@webiny/plugins/Plugin";
2
+ import { CmsModel, CmsModelField } from "../../../types";
3
+ import { PluginsContainer } from "@webiny/plugins";
4
+ export interface ToStorageParams<T> {
5
+ model: CmsModel;
6
+ field: CmsModelField;
7
+ value: T;
8
+ getStoragePlugin(fieldType: string): StorageTransformPlugin<T>;
9
+ plugins: PluginsContainer;
10
+ }
11
+ export interface FromStorageParams<T> {
12
+ model: CmsModel;
13
+ field: CmsModelField;
14
+ value: T;
15
+ getStoragePlugin(fieldType: string): StorageTransformPlugin<T>;
16
+ plugins: PluginsContainer;
17
+ }
18
+ export interface Params<T, R> {
19
+ fieldType: string;
20
+ toStorage: (params: ToStorageParams<T>) => Promise<R>;
21
+ fromStorage: (params: FromStorageParams<R>) => Promise<T>;
22
+ }
23
+ export declare class StorageTransformPlugin<T = any, R = any> extends Plugin {
24
+ static readonly type: string;
25
+ get fieldType(): string;
26
+ private readonly config;
27
+ constructor(config: Params<T, R>);
28
+ toStorage(params: ToStorageParams<T>): Promise<R>;
29
+ fromStorage(params: FromStorageParams<R>): Promise<T>;
30
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.StorageTransformPlugin = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _Plugin = require("@webiny/plugins/Plugin");
13
+
14
+ class StorageTransformPlugin extends _Plugin.Plugin {
15
+ get fieldType() {
16
+ return this.config.fieldType;
17
+ }
18
+
19
+ constructor(config) {
20
+ super();
21
+ (0, _defineProperty2.default)(this, "config", void 0);
22
+ this.config = config;
23
+ }
24
+
25
+ toStorage(params) {
26
+ return this.config.toStorage(params);
27
+ }
28
+
29
+ fromStorage(params) {
30
+ return this.config.fromStorage(params);
31
+ }
32
+
33
+ }
34
+
35
+ exports.StorageTransformPlugin = StorageTransformPlugin;
36
+ (0, _defineProperty2.default)(StorageTransformPlugin, "type", "cms.storage.transform.plugin");
@@ -0,0 +1,3 @@
1
+ import { StorageTransformPlugin } from "./StorageTransformPlugin";
2
+ declare const _default: () => StorageTransformPlugin;
3
+ export default _default;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _StorageTransformPlugin = require("./StorageTransformPlugin");
9
+
10
+ const plugin = new _StorageTransformPlugin.StorageTransformPlugin({
11
+ fieldType: "*",
12
+ fromStorage: async ({
13
+ value
14
+ }) => {
15
+ return value;
16
+ },
17
+ toStorage: async ({
18
+ value
19
+ }) => {
20
+ return value;
21
+ }
22
+ });
23
+
24
+ var _default = () => {
25
+ return plugin;
26
+ };
27
+
28
+ exports.default = _default;
@@ -0,0 +1,3 @@
1
+ import { StorageTransformPlugin } from "./StorageTransformPlugin";
2
+ declare const _default: () => StorageTransformPlugin;
3
+ export default _default;
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _pReduce = _interopRequireDefault(require("p-reduce"));
13
+
14
+ var _pMap = _interopRequireDefault(require("p-map"));
15
+
16
+ var _StorageTransformPlugin = require("./StorageTransformPlugin");
17
+
18
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
19
+
20
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
21
+
22
+ const processValue = async ({
23
+ fields,
24
+ sourceValue,
25
+ getStoragePlugin,
26
+ plugins,
27
+ model,
28
+ operation
29
+ }) => {
30
+ return await (0, _pReduce.default)(fields, async (values, field) => {
31
+ const plugin = getStoragePlugin(field.type);
32
+ const value = await plugin[operation]({
33
+ plugins,
34
+ model,
35
+ field,
36
+ value: sourceValue[field.fieldId],
37
+ getStoragePlugin
38
+ });
39
+ return _objectSpread(_objectSpread({}, values), {}, {
40
+ [field.fieldId]: value
41
+ });
42
+ }, {});
43
+ };
44
+
45
+ const plugin = new _StorageTransformPlugin.StorageTransformPlugin({
46
+ fieldType: "object",
47
+ toStorage: async ({
48
+ field,
49
+ value,
50
+ getStoragePlugin,
51
+ model,
52
+ plugins
53
+ }) => {
54
+ if (!value) {
55
+ return null;
56
+ }
57
+
58
+ const fields = field.settings.fields;
59
+
60
+ if (field.multipleValues) {
61
+ return await (0, _pMap.default)(value, value => processValue({
62
+ sourceValue: value,
63
+ getStoragePlugin,
64
+ model,
65
+ plugins,
66
+ operation: "toStorage",
67
+ fields
68
+ }));
69
+ }
70
+
71
+ return processValue({
72
+ sourceValue: value,
73
+ getStoragePlugin,
74
+ model,
75
+ plugins,
76
+ operation: "toStorage",
77
+ fields
78
+ });
79
+ },
80
+ fromStorage: async ({
81
+ field,
82
+ value,
83
+ getStoragePlugin,
84
+ plugins,
85
+ model
86
+ }) => {
87
+ if (!value) {
88
+ return null;
89
+ }
90
+
91
+ const fields = field.settings.fields;
92
+
93
+ if (field.multipleValues) {
94
+ return (0, _pMap.default)(value, value => processValue({
95
+ sourceValue: value,
96
+ getStoragePlugin,
97
+ model,
98
+ plugins,
99
+ operation: "fromStorage",
100
+ fields
101
+ }));
102
+ }
103
+
104
+ return processValue({
105
+ sourceValue: value,
106
+ getStoragePlugin,
107
+ model,
108
+ plugins,
109
+ operation: "fromStorage",
110
+ fields
111
+ });
112
+ }
113
+ });
114
+
115
+ var _default = () => {
116
+ return plugin;
117
+ };
118
+
119
+ exports.default = _default;
@@ -0,0 +1,3 @@
1
+ export declare const createTypeName: (modelId: string) => any;
2
+ export declare const createReadTypeName: (baseTypeName: string) => any;
3
+ export declare const createManageTypeName: (baseTypeName: string) => any;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createTypeName = exports.createReadTypeName = exports.createManageTypeName = void 0;
9
+
10
+ var _upperFirst = _interopRequireDefault(require("lodash/upperFirst"));
11
+
12
+ const createTypeName = modelId => {
13
+ return (0, _upperFirst.default)(modelId);
14
+ };
15
+
16
+ exports.createTypeName = createTypeName;
17
+
18
+ const createReadTypeName = baseTypeName => {
19
+ return createTypeName(baseTypeName);
20
+ };
21
+
22
+ exports.createReadTypeName = createReadTypeName;
23
+
24
+ const createManageTypeName = baseTypeName => {
25
+ return createTypeName(baseTypeName);
26
+ };
27
+
28
+ exports.createManageTypeName = createManageTypeName;
@@ -0,0 +1,17 @@
1
+ import { CmsEntry, CmsModel, CmsModelField, CmsContext } from "../../../types";
2
+ /**
3
+ * A function that is used in crud to transform entry into the storage type.
4
+ */
5
+ export declare const entryToStorageTransform: (context: CmsContext, model: CmsModel, entry: CmsEntry) => Promise<CmsEntry>;
6
+ /**
7
+ * A function that is used to transform the whole entry from storage into its native form.
8
+ */
9
+ export declare const entryFromStorageTransform: (context: CmsContext, model: CmsModel, entry?: CmsEntry & Record<string, any>) => Promise<CmsEntry>;
10
+ interface EntryFieldFromStorageTransformParams {
11
+ context: CmsContext;
12
+ model: CmsModel;
13
+ field: CmsModelField;
14
+ value: any;
15
+ }
16
+ export declare const entryFieldFromStorageTransform: (params: EntryFieldFromStorageTransformParams) => Promise<any>;
17
+ export {};
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.entryToStorageTransform = exports.entryFromStorageTransform = exports.entryFieldFromStorageTransform = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _error = _interopRequireDefault(require("@webiny/error"));
13
+
14
+ var _StorageTransformPlugin = require("../storage/StorageTransformPlugin");
15
+
16
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
17
+
18
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
19
+
20
+ const getStoragePluginFactory = context => {
21
+ let defaultStoragePlugin;
22
+ const plugins = context.plugins.byType(_StorageTransformPlugin.StorageTransformPlugin.type) // we reverse plugins because we want to get latest added only
23
+ .reverse().reduce((collection, plugin) => {
24
+ // check if it's a default plugin
25
+ if (plugin.fieldType === "*" && !defaultStoragePlugin) {
26
+ defaultStoragePlugin = plugin;
27
+ return collection;
28
+ }
29
+ /**
30
+ * either existing plugin added or plugin fieldType does not exist in current model
31
+ * this is to iterate a bit less later
32
+ */
33
+
34
+
35
+ if (!collection[plugin.fieldType]) {
36
+ collection[plugin.fieldType] = plugin;
37
+ }
38
+
39
+ return collection;
40
+ }, {});
41
+ return fieldType => {
42
+ return plugins[fieldType] || defaultStoragePlugin;
43
+ };
44
+ };
45
+ /**
46
+ * This should be used when transforming the whole entry.
47
+ */
48
+
49
+
50
+ const entryStorageTransform = async (context, model, operation, entry) => {
51
+ const getStoragePlugin = getStoragePluginFactory(context);
52
+ const transformedValues = {};
53
+
54
+ for (const field of model.fields) {
55
+ const plugin = getStoragePlugin(field.type); // TODO: remove this once plugins are converted into classes
56
+
57
+ if (typeof plugin[operation] !== "function") {
58
+ throw new _error.default(`Missing "${operation}" function in storage plugin "${plugin.name}" for field type "${field.type}"`);
59
+ }
60
+
61
+ transformedValues[field.fieldId] = await plugin[operation]({
62
+ plugins: context.plugins,
63
+ model,
64
+ field,
65
+ value: entry.values[field.fieldId],
66
+ getStoragePlugin
67
+ });
68
+ }
69
+
70
+ return _objectSpread(_objectSpread({}, entry), {}, {
71
+ values: transformedValues
72
+ });
73
+ };
74
+ /**
75
+ * A function that is used in crud to transform entry into the storage type.
76
+ */
77
+
78
+
79
+ const entryToStorageTransform = async (context, model, entry) => {
80
+ return entryStorageTransform(context, model, "toStorage", entry);
81
+ };
82
+ /**
83
+ * A function that is used to transform the whole entry from storage into its native form.
84
+ */
85
+
86
+
87
+ exports.entryToStorageTransform = entryToStorageTransform;
88
+
89
+ const entryFromStorageTransform = async (context, model, entry) => {
90
+ if (!entry) {
91
+ return null;
92
+ }
93
+
94
+ return entryStorageTransform(context, model, "fromStorage", entry);
95
+ };
96
+
97
+ exports.entryFromStorageTransform = entryFromStorageTransform;
98
+
99
+ /*
100
+ * A function that is used to transform a single field from storage
101
+ */
102
+ const entryFieldFromStorageTransform = async params => {
103
+ const {
104
+ context,
105
+ model,
106
+ field,
107
+ value
108
+ } = params;
109
+ const getStoragePlugin = getStoragePluginFactory(context);
110
+ const plugin = getStoragePlugin(field.type); // TODO: remove this once plugins are converted into classes
111
+
112
+ if (typeof plugin.fromStorage !== "function") {
113
+ throw new _error.default(`Missing "fromStorage" function in storage plugin "${plugin.name}" for field type "${field.type}"`);
114
+ }
115
+
116
+ return plugin.fromStorage({
117
+ plugins: context.plugins,
118
+ model,
119
+ field,
120
+ value,
121
+ getStoragePlugin
122
+ });
123
+ };
124
+
125
+ exports.entryFieldFromStorageTransform = entryFieldFromStorageTransform;
@@ -0,0 +1,2 @@
1
+ import { CmsEntry, CmsModel } from "../../../types";
2
+ export declare function getEntryTitle(model: CmsModel, entry: CmsEntry): any;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getEntryTitle = getEntryTitle;
7
+
8
+ function getEntryTitle(model, entry) {
9
+ if (!model.titleFieldId) {
10
+ return entry.id;
11
+ }
12
+
13
+ const titleValue = entry.values[model.titleFieldId];
14
+
15
+ if (!titleValue) {
16
+ return entry.id;
17
+ }
18
+
19
+ const field = model.fields.find(f => f.fieldId === model.titleFieldId);
20
+
21
+ if (!field) {
22
+ return titleValue;
23
+ }
24
+
25
+ const {
26
+ enabled = false,
27
+ values
28
+ } = field.predefinedValues || {};
29
+
30
+ if (!enabled || Array.isArray(values) === false) {
31
+ return titleValue;
32
+ }
33
+
34
+ for (const value of values) {
35
+ // needs to be loose because titleValue can be a number and value can be a string - but it must match
36
+ if (value.value == titleValue) {
37
+ return value.label;
38
+ }
39
+ }
40
+
41
+ return titleValue;
42
+ }
@@ -0,0 +1,11 @@
1
+ import { CmsModel, CmsContext, CmsFieldTypePlugins } from "../../../types";
2
+ import { GraphQLSchemaDefinition } from "@webiny/handler-graphql/types";
3
+ interface RenderTypesFromFieldPlugins {
4
+ (params: {
5
+ models: CmsModel[];
6
+ fieldTypePlugins: CmsFieldTypePlugins;
7
+ type: string;
8
+ }): GraphQLSchemaDefinition<CmsContext>[];
9
+ }
10
+ export declare const getSchemaFromFieldPlugins: RenderTypesFromFieldPlugins;
11
+ export {};
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getSchemaFromFieldPlugins = void 0;
7
+ const TYPE_MAP = {
8
+ preview: "read",
9
+ read: "read",
10
+ manage: "manage"
11
+ };
12
+
13
+ const getSchemaFromFieldPlugins = ({
14
+ models,
15
+ fieldTypePlugins,
16
+ type
17
+ }) => {
18
+ return Object.values(fieldTypePlugins).map(pl => {
19
+ // Render gql types generated by field type plugins
20
+ if (typeof pl[TYPE_MAP[type]].createSchema === "function") {
21
+ return pl[TYPE_MAP[type]].createSchema({
22
+ models
23
+ });
24
+ }
25
+
26
+ return null;
27
+ }).filter(Boolean);
28
+ };
29
+
30
+ exports.getSchemaFromFieldPlugins = getSchemaFromFieldPlugins;