@webiny/app-headless-cms-common 0.0.0-unstable.06b2ede40f

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 (81) hide show
  1. package/Fields/ErrorBoundary.d.ts +24 -0
  2. package/Fields/ErrorBoundary.js +40 -0
  3. package/Fields/ErrorBoundary.js.map +1 -0
  4. package/Fields/FieldElement.d.ts +64 -0
  5. package/Fields/FieldElement.js +71 -0
  6. package/Fields/FieldElement.js.map +1 -0
  7. package/Fields/FieldElementError.d.ts +7 -0
  8. package/Fields/FieldElementError.js +26 -0
  9. package/Fields/FieldElementError.js.map +1 -0
  10. package/Fields/Fields.d.ts +11 -0
  11. package/Fields/Fields.js +35 -0
  12. package/Fields/Fields.js.map +1 -0
  13. package/Fields/Label.d.ts +6 -0
  14. package/Fields/Label.js +10 -0
  15. package/Fields/Label.js.map +1 -0
  16. package/Fields/index.d.ts +3 -0
  17. package/Fields/index.js +5 -0
  18. package/Fields/index.js.map +1 -0
  19. package/Fields/useBind.d.ts +9 -0
  20. package/Fields/useBind.js +113 -0
  21. package/Fields/useBind.js.map +1 -0
  22. package/Fields/useRenderPlugins.d.ts +1 -0
  23. package/Fields/useRenderPlugins.js +7 -0
  24. package/Fields/useRenderPlugins.js.map +1 -0
  25. package/LICENSE +21 -0
  26. package/ModelFieldProvider/ModelFieldContext.d.ts +36 -0
  27. package/ModelFieldProvider/ModelFieldContext.js +26 -0
  28. package/ModelFieldProvider/ModelFieldContext.js.map +1 -0
  29. package/ModelFieldProvider/index.d.ts +2 -0
  30. package/ModelFieldProvider/index.js +4 -0
  31. package/ModelFieldProvider/index.js.map +1 -0
  32. package/ModelFieldProvider/useModelField.d.ts +16 -0
  33. package/ModelFieldProvider/useModelField.js +29 -0
  34. package/ModelFieldProvider/useModelField.js.map +1 -0
  35. package/ModelProvider/ModelContext.d.ts +9 -0
  36. package/ModelProvider/ModelContext.js +12 -0
  37. package/ModelProvider/ModelContext.js.map +1 -0
  38. package/ModelProvider/index.d.ts +2 -0
  39. package/ModelProvider/index.js +4 -0
  40. package/ModelProvider/index.js.map +1 -0
  41. package/ModelProvider/useModel.d.ts +9 -0
  42. package/ModelProvider/useModel.js +16 -0
  43. package/ModelProvider/useModel.js.map +1 -0
  44. package/README.md +18 -0
  45. package/constants.d.ts +1 -0
  46. package/constants.js +3 -0
  47. package/constants.js.map +1 -0
  48. package/createFieldsList.d.ts +8 -0
  49. package/createFieldsList.js +49 -0
  50. package/createFieldsList.js.map +1 -0
  51. package/createValidationContainer.d.ts +18 -0
  52. package/createValidationContainer.js +26 -0
  53. package/createValidationContainer.js.map +1 -0
  54. package/createValidators.d.ts +3 -0
  55. package/createValidators.js +52 -0
  56. package/createValidators.js.map +1 -0
  57. package/entries.graphql.d.ts +218 -0
  58. package/entries.graphql.js +402 -0
  59. package/entries.graphql.js.map +1 -0
  60. package/getModelTitleFieldId.d.ts +2 -0
  61. package/getModelTitleFieldId.js +8 -0
  62. package/getModelTitleFieldId.js.map +1 -0
  63. package/index.d.ts +10 -0
  64. package/index.js +12 -0
  65. package/index.js.map +1 -0
  66. package/package.json +52 -0
  67. package/prepareFormData.d.ts +2 -0
  68. package/prepareFormData.js +71 -0
  69. package/prepareFormData.js.map +1 -0
  70. package/types/index.d.ts +567 -0
  71. package/types/index.js +56 -0
  72. package/types/index.js.map +1 -0
  73. package/types/model.d.ts +100 -0
  74. package/types/model.js +3 -0
  75. package/types/model.js.map +1 -0
  76. package/types/shared.d.ts +5 -0
  77. package/types/shared.js +3 -0
  78. package/types/shared.js.map +1 -0
  79. package/types/validation.d.ts +79 -0
  80. package/types/validation.js +3 -0
  81. package/types/validation.js.map +1 -0
@@ -0,0 +1,402 @@
1
+ import gql from "graphql-tag";
2
+ import { createFieldsList } from "./createFieldsList";
3
+ import { getModelTitleFieldId } from "./getModelTitleFieldId";
4
+ import { CMS_MODEL_SINGLETON_TAG } from "./constants";
5
+ const CONTENT_META_FIELDS = /* GraphQL */`
6
+ title
7
+ description
8
+ image
9
+ version
10
+ locked
11
+ status
12
+ `;
13
+ const createEntrySystemFields = model => {
14
+ const isSingletonModel = model.tags.includes(CMS_MODEL_SINGLETON_TAG);
15
+ let optionalFields = "";
16
+ if (!isSingletonModel) {
17
+ optionalFields = `
18
+ wbyAco_location {
19
+ folderId
20
+ }
21
+ meta {
22
+ ${CONTENT_META_FIELDS}
23
+ }
24
+ `;
25
+ }
26
+ return /* GraphQL */`
27
+ id
28
+ entryId
29
+ createdOn
30
+ savedOn
31
+ modifiedOn,
32
+ deletedOn
33
+ firstPublishedOn
34
+ lastPublishedOn
35
+ createdBy {
36
+ id
37
+ type
38
+ displayName
39
+ }
40
+ savedBy {
41
+ id
42
+ type
43
+ displayName
44
+ }
45
+ modifiedBy {
46
+ id
47
+ type
48
+ displayName
49
+ }
50
+ deletedBy {
51
+ id
52
+ type
53
+ displayName
54
+ }
55
+ firstPublishedBy {
56
+ id
57
+ type
58
+ displayName
59
+ }
60
+ lastPublishedBy {
61
+ id
62
+ type
63
+ displayName
64
+ }
65
+ revisionCreatedOn
66
+ revisionSavedOn
67
+ revisionModifiedOn
68
+ revisionDeletedOn
69
+ revisionFirstPublishedOn
70
+ revisionLastPublishedOn
71
+ revisionCreatedBy {
72
+ id
73
+ type
74
+ displayName
75
+ }
76
+ revisionSavedBy {
77
+ id
78
+ type
79
+ displayName
80
+ }
81
+ revisionModifiedBy {
82
+ id
83
+ type
84
+ displayName
85
+ }
86
+ revisionDeletedBy {
87
+ id
88
+ type
89
+ displayName
90
+ }
91
+ revisionFirstPublishedBy {
92
+ id
93
+ type
94
+ displayName
95
+ }
96
+ revisionLastPublishedBy {
97
+ id
98
+ type
99
+ displayName
100
+ }
101
+ ${optionalFields}
102
+ `;
103
+ };
104
+ const ERROR_FIELD = /* GraphQL */`
105
+ {
106
+ message
107
+ code
108
+ data
109
+ }
110
+ `;
111
+
112
+ /**
113
+ * ############################################
114
+ * Get CMS Entry Query
115
+ */
116
+
117
+ export const createReadQuery = model => {
118
+ /**
119
+ * This query now accepts both revision or entryId as we can load exact revision or latest (if entryId was sent).
120
+ */
121
+ return gql`
122
+ query CmsEntriesGet${model.singularApiName}($revision: ID, $entryId: ID) {
123
+ content: get${model.singularApiName}(revision: $revision, entryId: $entryId) {
124
+ data {
125
+ ${createEntrySystemFields(model)}
126
+ ${createFieldsList({
127
+ model,
128
+ fields: model.fields
129
+ })}
130
+ }
131
+ error ${ERROR_FIELD}
132
+ }
133
+ }
134
+ `;
135
+ };
136
+
137
+ /**
138
+ * ############################################
139
+ * Get CMS Singleton Entry Query
140
+ */
141
+
142
+ export const createReadSingletonQuery = model => {
143
+ return gql`
144
+ query CmsEntryGetSingleton${model.singularApiName} {
145
+ content: get${model.singularApiName} {
146
+ data {
147
+ ${createEntrySystemFields(model)}
148
+ ${createFieldsList({
149
+ model,
150
+ fields: model.fields
151
+ })}
152
+ }
153
+ error ${ERROR_FIELD}
154
+ }
155
+ }
156
+ `;
157
+ };
158
+
159
+ /**
160
+ * ############################################
161
+ * List CMS Entry Revisions Query
162
+ */
163
+
164
+ export const createRevisionsQuery = model => {
165
+ return gql`
166
+ query CmsEntriesGet${model.singularApiName}Revisions($id: ID!) {
167
+ revisions: get${model.singularApiName}Revisions(id: $id) {
168
+ data {
169
+ ${createEntrySystemFields(model)}
170
+ }
171
+ error ${ERROR_FIELD}
172
+ }
173
+ }
174
+ `;
175
+ };
176
+
177
+ /**
178
+ * ############################################
179
+ * List CMS Entries Query
180
+ */
181
+
182
+ export const createListQueryDataSelection = (model, fields) => {
183
+ return `
184
+ ${createEntrySystemFields(model)}
185
+ ${fields ? createFieldsList({
186
+ model,
187
+ fields
188
+ }) : ""}
189
+ ${!fields ? getModelTitleFieldId(model) : ""}
190
+ `;
191
+ };
192
+ export const createListQuery = (model, fields, deleted) => {
193
+ const queryName = deleted ? `Deleted${model.pluralApiName}` : model.pluralApiName;
194
+ return gql`
195
+ query CmsEntriesList${queryName}($where: ${model.singularApiName}ListWhereInput, $sort: [${model.singularApiName}ListSorter], $limit: Int, $after: String, $search: String) {
196
+ content: list${queryName}(
197
+ where: $where
198
+ sort: $sort
199
+ limit: $limit
200
+ after: $after
201
+ search: $search
202
+ ) {
203
+ data {
204
+ ${createListQueryDataSelection(model, fields)}
205
+ }
206
+ meta {
207
+ cursor
208
+ hasMoreItems
209
+ totalCount
210
+ }
211
+ error ${ERROR_FIELD}
212
+ }
213
+ }
214
+ `;
215
+ };
216
+
217
+ /**
218
+ * ############################################
219
+ * Delete Mutation
220
+ */
221
+
222
+ export const createDeleteMutation = model => {
223
+ return gql`
224
+ mutation CmsEntriesDelete${model.singularApiName}($revision: ID!, $permanently: Boolean) {
225
+ content: delete${model.singularApiName}(revision: $revision, options: {permanently: $permanently}) {
226
+ data
227
+ error ${ERROR_FIELD}
228
+ }
229
+ }
230
+ `;
231
+ };
232
+
233
+ /**
234
+ * ############################################
235
+ * Restore from bin Mutation
236
+ */
237
+
238
+ export const createRestoreFromBinMutation = model => {
239
+ return gql`
240
+ mutation CmsEntriesRestore${model.singularApiName}FromBin($revision: ID!) {
241
+ content: restore${model.singularApiName}FromBin(revision: $revision) {
242
+ data {
243
+ ${createEntrySystemFields(model)}
244
+ ${createFieldsList({
245
+ model,
246
+ fields: model.fields
247
+ })}
248
+ }
249
+ error ${ERROR_FIELD}
250
+ }
251
+ }
252
+ `;
253
+ };
254
+
255
+ /**
256
+ * ############################################
257
+ * Create Mutation
258
+ */
259
+
260
+ export const createCreateMutation = model => {
261
+ const createFields = createFieldsList({
262
+ model,
263
+ fields: model.fields
264
+ });
265
+ return gql`
266
+ mutation CmsEntriesCreate${model.singularApiName}($data: ${model.singularApiName}Input!, $options: CreateCmsEntryOptionsInput) {
267
+ content: create${model.singularApiName}(data: $data, options: $options) {
268
+ data {
269
+ ${createEntrySystemFields(model)}
270
+ ${createFields}
271
+ }
272
+ error ${ERROR_FIELD}
273
+ }
274
+ }
275
+ `;
276
+ };
277
+
278
+ /**
279
+ * ############################################
280
+ * Create From Mutation
281
+ */
282
+
283
+ export const createCreateFromMutation = model => {
284
+ return gql`
285
+ mutation CmsCreate${model.singularApiName}From($revision: ID!, $data: ${model.singularApiName}Input, $options: CreateRevisionCmsEntryOptionsInput) {
286
+ content: create${model.singularApiName}From(revision: $revision, data: $data, options: $options) {
287
+ data {
288
+ ${createEntrySystemFields(model)}
289
+ ${createFieldsList({
290
+ model,
291
+ fields: model.fields
292
+ })}
293
+ }
294
+ error ${ERROR_FIELD}
295
+ }
296
+ }`;
297
+ };
298
+
299
+ /**
300
+ * ############################################
301
+ * Update Mutation
302
+ */
303
+
304
+ export const createUpdateMutation = model => {
305
+ return gql`
306
+ mutation CmsUpdate${model.singularApiName}($revision: ID!, $data: ${model.singularApiName}Input!, $options: UpdateCmsEntryOptionsInput) {
307
+ content: update${model.singularApiName}(revision: $revision, data: $data, options: $options) {
308
+ data {
309
+ ${createEntrySystemFields(model)}
310
+ ${createFieldsList({
311
+ model,
312
+ fields: model.fields
313
+ })}
314
+ }
315
+ error ${ERROR_FIELD}
316
+ }
317
+ }
318
+ `;
319
+ };
320
+
321
+ /**
322
+ * ############################################
323
+ * Update Singleton Mutation
324
+ */
325
+
326
+ export const createUpdateSingletonMutation = model => {
327
+ return gql`
328
+ mutation CmsUpdate${model.singularApiName}($data: ${model.singularApiName}Input!, $options: UpdateCmsEntryOptionsInput) {
329
+ content: update${model.singularApiName}(data: $data, options: $options) {
330
+ data {
331
+ ${createEntrySystemFields(model)}
332
+ ${createFieldsList({
333
+ model,
334
+ fields: model.fields
335
+ })}
336
+ }
337
+ error ${ERROR_FIELD}
338
+ }
339
+ }
340
+ `;
341
+ };
342
+
343
+ /**
344
+ * ############################################
345
+ * Publish Mutation
346
+ */
347
+
348
+ export const createPublishMutation = model => {
349
+ return gql`
350
+ mutation CmsPublish${model.singularApiName}($revision: ID!) {
351
+ content: publish${model.singularApiName}(revision: $revision) {
352
+ data {
353
+ ${createEntrySystemFields(model)}
354
+ ${createFieldsList({
355
+ model,
356
+ fields: model.fields
357
+ })}
358
+ }
359
+ error ${ERROR_FIELD}
360
+ }
361
+ }`;
362
+ };
363
+
364
+ /**
365
+ * ############################################
366
+ * Unpublish Mutation
367
+ */
368
+
369
+ export const createUnpublishMutation = model => {
370
+ return gql`
371
+ mutation CmsUnpublish${model.singularApiName}($revision: ID!) {
372
+ content: unpublish${model.singularApiName}(revision: $revision) {
373
+ data {
374
+ ${createEntrySystemFields(model)}
375
+ ${createFieldsList({
376
+ model,
377
+ fields: model.fields
378
+ })}
379
+ }
380
+ error ${ERROR_FIELD}
381
+ }
382
+ }`;
383
+ };
384
+
385
+ /**
386
+ * ############################################
387
+ * Bulk Action Mutation
388
+ */
389
+
390
+ export const createBulkActionMutation = model => {
391
+ return gql`
392
+ mutation CmsBulkAction${model.singularApiName}($action: BulkAction${model.singularApiName}Name!, $where: ${model.singularApiName}ListWhereInput, $search: String, $data: JSON) {
393
+ content: bulkAction${model.singularApiName}(action: $action, where: $where, search: $search, data: $data) {
394
+ data {
395
+ id
396
+ }
397
+ error ${ERROR_FIELD}
398
+ }
399
+ }`;
400
+ };
401
+
402
+ //# sourceMappingURL=entries.graphql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["gql","createFieldsList","getModelTitleFieldId","CMS_MODEL_SINGLETON_TAG","CONTENT_META_FIELDS","createEntrySystemFields","model","isSingletonModel","tags","includes","optionalFields","ERROR_FIELD","createReadQuery","singularApiName","fields","createReadSingletonQuery","createRevisionsQuery","createListQueryDataSelection","createListQuery","deleted","queryName","pluralApiName","createDeleteMutation","createRestoreFromBinMutation","createCreateMutation","createFields","createCreateFromMutation","createUpdateMutation","createUpdateSingletonMutation","createPublishMutation","createUnpublishMutation","createBulkActionMutation"],"sources":["entries.graphql.ts"],"sourcesContent":["import gql from \"graphql-tag\";\nimport type {\n CmsContentEntryRevision,\n CmsContentEntry,\n CmsEditorContentModel,\n CmsErrorResponse,\n CmsMetaResponse,\n CmsModelField,\n CmsModel\n} from \"~/types\";\nimport { createFieldsList } from \"./createFieldsList\";\nimport { getModelTitleFieldId } from \"./getModelTitleFieldId\";\nimport type { FormValidationOptions } from \"@webiny/form\";\nimport { CMS_MODEL_SINGLETON_TAG } from \"./constants\";\n\nconst CONTENT_META_FIELDS = /* GraphQL */ `\n title\n description\n image\n version\n locked\n status\n`;\n\nconst createEntrySystemFields = (model: CmsModel) => {\n const isSingletonModel = model.tags.includes(CMS_MODEL_SINGLETON_TAG);\n\n let optionalFields = \"\";\n if (!isSingletonModel) {\n optionalFields = `\n wbyAco_location {\n folderId\n }\n meta {\n ${CONTENT_META_FIELDS}\n }\n `;\n }\n\n return /* GraphQL */ `\n id\n entryId\n createdOn\n savedOn\n modifiedOn,\n deletedOn\n firstPublishedOn\n lastPublishedOn\n createdBy {\n id\n type\n displayName\n }\n savedBy {\n id\n type\n displayName\n }\n modifiedBy {\n id\n type\n displayName\n }\n deletedBy {\n id\n type\n displayName\n }\n firstPublishedBy {\n id\n type\n displayName\n }\n lastPublishedBy {\n id\n type\n displayName\n }\n revisionCreatedOn\n revisionSavedOn\n revisionModifiedOn\n revisionDeletedOn\n revisionFirstPublishedOn\n revisionLastPublishedOn\n revisionCreatedBy {\n id\n type\n displayName\n }\n revisionSavedBy {\n id\n type\n displayName\n }\n revisionModifiedBy {\n id\n type\n displayName\n }\n revisionDeletedBy {\n id\n type\n displayName\n }\n revisionFirstPublishedBy {\n id\n type\n displayName\n }\n revisionLastPublishedBy {\n id\n type\n displayName\n }\n ${optionalFields}\n `;\n};\n\nconst ERROR_FIELD = /* GraphQL */ `\n {\n message\n code\n data\n }\n`;\n\n/**\n * ############################################\n * Get CMS Entry Query\n */\nexport interface CmsEntryGetQueryResponse {\n content: {\n data: CmsContentEntry;\n error: CmsErrorResponse | null;\n };\n}\n\nexport interface CmsEntryGetQueryVariables {\n revision?: string;\n entryId?: string;\n}\n\nexport const createReadQuery = (model: CmsEditorContentModel) => {\n /**\n * This query now accepts both revision or entryId as we can load exact revision or latest (if entryId was sent).\n */\n return gql`\n query CmsEntriesGet${model.singularApiName}($revision: ID, $entryId: ID) {\n content: get${model.singularApiName}(revision: $revision, entryId: $entryId) {\n data {\n ${createEntrySystemFields(model)}\n ${createFieldsList({ model, fields: model.fields })}\n }\n error ${ERROR_FIELD}\n }\n }\n `;\n};\n\n/**\n * ############################################\n * Get CMS Singleton Entry Query\n */\nexport interface CmsEntryGetSingletonQueryResponse {\n content: {\n data: CmsContentEntry;\n error: CmsErrorResponse | null;\n };\n}\n\nexport const createReadSingletonQuery = (model: CmsEditorContentModel) => {\n return gql`\n query CmsEntryGetSingleton${model.singularApiName} {\n content: get${model.singularApiName} {\n data {\n ${createEntrySystemFields(model)}\n ${createFieldsList({ model, fields: model.fields })}\n }\n error ${ERROR_FIELD}\n }\n }\n `;\n};\n\n/**\n * ############################################\n * List CMS Entry Revisions Query\n */\nexport interface CmsEntriesListRevisionsQueryResponse {\n revisions: {\n data: CmsContentEntryRevision[];\n error: CmsErrorResponse | null;\n meta: CmsMetaResponse;\n };\n}\n\nexport interface CmsEntriesListRevisionsQueryVariables {\n id: string;\n}\n\nexport const createRevisionsQuery = (model: CmsEditorContentModel) => {\n return gql`\n query CmsEntriesGet${model.singularApiName}Revisions($id: ID!) {\n revisions: get${model.singularApiName}Revisions(id: $id) {\n data {\n ${createEntrySystemFields(model)}\n }\n error ${ERROR_FIELD}\n }\n }\n `;\n};\n\n/**\n * ############################################\n * List CMS Entries Query\n */\nexport interface CmsEntriesListQueryResponse {\n content: {\n data: CmsContentEntry[];\n error: CmsErrorResponse | null;\n meta: CmsMetaResponse;\n };\n}\n\nexport interface CmsEntriesListQueryVariables {\n // TODO @ts-refactor better list types\n where?: {\n [key: string]: any;\n };\n sort?: string[];\n limit?: number;\n after?: string;\n}\n\nexport const createListQueryDataSelection = (\n model: CmsEditorContentModel,\n fields?: CmsModelField[]\n) => {\n return `\n ${createEntrySystemFields(model)}\n ${fields ? createFieldsList({ model, fields }) : \"\"}\n ${!fields ? getModelTitleFieldId(model) : \"\"}\n `;\n};\n\nexport const createListQuery = (\n model: CmsEditorContentModel,\n fields?: CmsModelField[],\n deleted?: boolean\n) => {\n const queryName = deleted ? `Deleted${model.pluralApiName}` : model.pluralApiName;\n\n return gql`\n query CmsEntriesList${queryName}($where: ${model.singularApiName}ListWhereInput, $sort: [${\n model.singularApiName\n }ListSorter], $limit: Int, $after: String, $search: String) {\n content: list${queryName}(\n where: $where\n sort: $sort\n limit: $limit\n after: $after\n search: $search\n ) {\n data {\n ${createListQueryDataSelection(model, fields)}\n }\n meta {\n cursor\n hasMoreItems\n totalCount\n }\n error ${ERROR_FIELD}\n }\n }\n `;\n};\n\n/**\n * ############################################\n * Delete Mutation\n */\nexport interface CmsEntryDeleteMutationResponse {\n content: {\n data: CmsContentEntry | null;\n error: CmsErrorResponse | null;\n };\n}\n\nexport interface CmsEntryDeleteMutationVariables {\n revision: string;\n permanently?: boolean;\n}\n\nexport const createDeleteMutation = (model: CmsEditorContentModel) => {\n return gql`\n mutation CmsEntriesDelete${model.singularApiName}($revision: ID!, $permanently: Boolean) {\n content: delete${model.singularApiName}(revision: $revision, options: {permanently: $permanently}) {\n data\n error ${ERROR_FIELD}\n }\n }\n `;\n};\n\n/**\n * ############################################\n * Restore from bin Mutation\n */\nexport interface CmsEntryRestoreFromBinMutationResponse {\n content: {\n data: CmsContentEntry | null;\n error: CmsErrorResponse | null;\n };\n}\n\nexport interface CmsEntryRestoreFromBinMutationVariables {\n revision: string;\n}\n\nexport const createRestoreFromBinMutation = (model: CmsEditorContentModel) => {\n return gql`\n mutation CmsEntriesRestore${model.singularApiName}FromBin($revision: ID!) {\n content: restore${model.singularApiName}FromBin(revision: $revision) {\n data {\n ${createEntrySystemFields(model)}\n ${createFieldsList({ model, fields: model.fields })}\n }\n error ${ERROR_FIELD}\n }\n }\n `;\n};\n\n/**\n * ############################################\n * Create Mutation\n */\nexport interface CmsEntryCreateMutationResponse {\n content: {\n data: CmsContentEntry | null;\n error: CmsErrorResponse | null;\n };\n}\n\nexport interface CmsEntryCreateMutationVariables {\n /**\n * We have any here because we do not know which fields does entry have\n */\n data: Record<string, any>;\n options?: FormValidationOptions;\n}\n\nexport const createCreateMutation = (model: CmsEditorContentModel) => {\n const createFields = createFieldsList({ model, fields: model.fields });\n\n return gql`\n mutation CmsEntriesCreate${model.singularApiName}($data: ${\n model.singularApiName\n }Input!, $options: CreateCmsEntryOptionsInput) {\n content: create${model.singularApiName}(data: $data, options: $options) {\n data {\n ${createEntrySystemFields(model)}\n ${createFields}\n }\n error ${ERROR_FIELD}\n }\n }\n `;\n};\n\n/**\n * ############################################\n * Create From Mutation\n */\nexport interface CmsEntryCreateFromMutationResponse {\n content: {\n data?: CmsContentEntry;\n error?: CmsErrorResponse;\n };\n}\n\nexport interface CmsEntryCreateFromMutationVariables {\n revision: string;\n /**\n * We have any here because we do not know which fields does entry have\n */\n data?: Record<string, any>;\n options?: FormValidationOptions;\n}\n\nexport const createCreateFromMutation = (model: CmsEditorContentModel) => {\n return gql`\n mutation CmsCreate${model.singularApiName}From($revision: ID!, $data: ${\n model.singularApiName\n }Input, $options: CreateRevisionCmsEntryOptionsInput) {\n content: create${\n model.singularApiName\n }From(revision: $revision, data: $data, options: $options) {\n data {\n ${createEntrySystemFields(model)}\n ${createFieldsList({ model, fields: model.fields })}\n }\n error ${ERROR_FIELD}\n }\n }`;\n};\n\n/**\n * ############################################\n * Update Mutation\n */\nexport interface CmsEntryUpdateMutationResponse {\n content: {\n data?: CmsContentEntry;\n error?: CmsErrorResponse;\n };\n}\n\nexport interface CmsEntryUpdateMutationVariables {\n revision: string;\n /**\n * We have any here because we do not know which fields does entry have\n */\n data: Record<string, any>;\n options?: FormValidationOptions;\n}\n\nexport const createUpdateMutation = (model: CmsEditorContentModel) => {\n return gql`\n mutation CmsUpdate${model.singularApiName}($revision: ID!, $data: ${\n model.singularApiName\n }Input!, $options: UpdateCmsEntryOptionsInput) {\n content: update${\n model.singularApiName\n }(revision: $revision, data: $data, options: $options) {\n data {\n ${createEntrySystemFields(model)}\n ${createFieldsList({ model, fields: model.fields })}\n }\n error ${ERROR_FIELD}\n }\n }\n `;\n};\n\n/**\n * ############################################\n * Update Singleton Mutation\n */\nexport interface CmsEntryUpdateSingletonMutationResponse {\n content: {\n data?: CmsContentEntry;\n error?: CmsErrorResponse;\n };\n}\n\nexport interface CmsEntryUpdateSingletonMutationVariables {\n /**\n * We have any here because we do not know which fields does entry have\n */\n data: Record<string, any>;\n options?: FormValidationOptions;\n}\n\nexport const createUpdateSingletonMutation = (model: CmsEditorContentModel) => {\n return gql`\n mutation CmsUpdate${model.singularApiName}($data: ${\n model.singularApiName\n }Input!, $options: UpdateCmsEntryOptionsInput) {\n content: update${model.singularApiName}(data: $data, options: $options) {\n data {\n ${createEntrySystemFields(model)}\n ${createFieldsList({ model, fields: model.fields })}\n }\n error ${ERROR_FIELD}\n }\n }\n `;\n};\n\n/**\n * ############################################\n * Publish Mutation\n */\nexport interface CmsEntryPublishMutationResponse {\n content: {\n data?: CmsContentEntry;\n error?: CmsErrorResponse;\n };\n}\n\nexport interface CmsEntryPublishMutationVariables {\n revision: string;\n}\n\nexport const createPublishMutation = (model: CmsEditorContentModel) => {\n return gql`\n mutation CmsPublish${model.singularApiName}($revision: ID!) {\n content: publish${model.singularApiName}(revision: $revision) {\n data {\n ${createEntrySystemFields(model)}\n ${createFieldsList({ model, fields: model.fields })}\n }\n error ${ERROR_FIELD}\n }\n }`;\n};\n\n/**\n * ############################################\n * Unpublish Mutation\n */\nexport interface CmsEntryUnpublishMutationResponse {\n content: {\n data?: CmsContentEntry;\n error?: CmsErrorResponse;\n };\n}\n\nexport interface CmsEntryUnpublishMutationVariables {\n revision: string;\n}\n\nexport const createUnpublishMutation = (model: CmsEditorContentModel) => {\n return gql`\n mutation CmsUnpublish${model.singularApiName}($revision: ID!) {\n content: unpublish${model.singularApiName}(revision: $revision) {\n data {\n ${createEntrySystemFields(model)}\n ${createFieldsList({ model, fields: model.fields })}\n }\n error ${ERROR_FIELD}\n }\n }`;\n};\n\n/**\n * ############################################\n * Bulk Action Mutation\n */\nexport interface CmsEntryBulkActionMutationResponse {\n content: {\n data?: {\n id: string;\n };\n error?: CmsErrorResponse;\n };\n}\n\nexport interface CmsEntryBulkActionMutationVariables {\n action: string;\n where?: {\n [key: string]: any;\n };\n search?: string;\n data?: {\n [key: string]: any;\n };\n}\n\nexport const createBulkActionMutation = (model: CmsEditorContentModel) => {\n return gql`\n mutation CmsBulkAction${model.singularApiName}($action: BulkAction${model.singularApiName}Name!, $where: ${model.singularApiName}ListWhereInput, $search: String, $data: JSON) {\n content: bulkAction${model.singularApiName}(action: $action, where: $where, search: $search, data: $data) {\n data {\n id\n }\n error ${ERROR_FIELD}\n }\n }`;\n};\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,aAAa;AAU7B,SAASC,gBAAgB;AACzB,SAASC,oBAAoB;AAE7B,SAASC,uBAAuB;AAEhC,MAAMC,mBAAmB,GAAG,aAAc;AAC1C;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,MAAMC,uBAAuB,GAAIC,KAAe,IAAK;EACjD,MAAMC,gBAAgB,GAAGD,KAAK,CAACE,IAAI,CAACC,QAAQ,CAACN,uBAAuB,CAAC;EAErE,IAAIO,cAAc,GAAG,EAAE;EACvB,IAAI,CAACH,gBAAgB,EAAE;IACnBG,cAAc,GAAG;AACzB;AACA;AACA;AACA;AACA,kBAAkBN,mBAAmB;AACrC;AACA,SAAS;EACL;EAEA,OAAO,aAAc;AACzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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AAK,CAACO,eAAe,kBAAkBP,KAAK,CAACO,eAAe;AACxI,iCAAiCP,KAAK,CAACO,eAAe;AACtD;AACA;AACA;AACA,wBAAwBF,WAAW;AACnC;AACA,UAAU;AACV,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ import type { CmsEditorContentModel } from "./types";
2
+ export declare const getModelTitleFieldId: (model: CmsEditorContentModel) => string;
@@ -0,0 +1,8 @@
1
+ export const getModelTitleFieldId = model => {
2
+ if (!model.titleFieldId || model.titleFieldId === "id") {
3
+ return "";
4
+ }
5
+ return model.titleFieldId;
6
+ };
7
+
8
+ //# sourceMappingURL=getModelTitleFieldId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getModelTitleFieldId","model","titleFieldId"],"sources":["getModelTitleFieldId.ts"],"sourcesContent":["import type { CmsEditorContentModel } from \"~/types\";\n\nexport const getModelTitleFieldId = (model: CmsEditorContentModel): string => {\n if (!model.titleFieldId || model.titleFieldId === \"id\") {\n return \"\";\n }\n return model.titleFieldId;\n};\n"],"mappings":"AAEA,OAAO,MAAMA,oBAAoB,GAAIC,KAA4B,IAAa;EAC1E,IAAI,CAACA,KAAK,CAACC,YAAY,IAAID,KAAK,CAACC,YAAY,KAAK,IAAI,EAAE;IACpD,OAAO,EAAE;EACb;EACA,OAAOD,KAAK,CAACC,YAAY;AAC7B,CAAC","ignoreList":[]}
package/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export * from "./Fields";
2
+ export * from "./ModelFieldProvider";
3
+ export * from "./ModelProvider";
4
+ export * from "./entries.graphql";
5
+ export * from "./getModelTitleFieldId";
6
+ export * from "./createFieldsList";
7
+ export * from "./createValidationContainer";
8
+ export * from "./createValidators";
9
+ export * from "./prepareFormData";
10
+ export * from "./constants";
package/index.js ADDED
@@ -0,0 +1,12 @@
1
+ export * from "./Fields";
2
+ export * from "./ModelFieldProvider";
3
+ export * from "./ModelProvider";
4
+ export * from "./entries.graphql";
5
+ export * from "./getModelTitleFieldId";
6
+ export * from "./createFieldsList";
7
+ export * from "./createValidationContainer";
8
+ export * from "./createValidators";
9
+ export * from "./prepareFormData";
10
+ export * from "./constants";
11
+
12
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./Fields\";\nexport * from \"./ModelFieldProvider\";\nexport * from \"./ModelProvider\";\nexport * from \"./entries.graphql\";\nexport * from \"./getModelTitleFieldId\";\nexport * from \"./createFieldsList\";\nexport * from \"./createValidationContainer\";\nexport * from \"./createValidators\";\nexport * from \"./prepareFormData\";\nexport * from \"./constants\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@webiny/app-headless-cms-common",
3
+ "version": "0.0.0-unstable.06b2ede40f",
4
+ "main": "index.js",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/webiny/webiny-js.git"
8
+ },
9
+ "contributors": [
10
+ "Pavel Denisjuk <pavel@webiny.com>",
11
+ "Sven Al Hamad <sven@webiny.com>",
12
+ "Adrian Smijulj <adrian@webiny.com>"
13
+ ],
14
+ "license": "MIT",
15
+ "dependencies": {
16
+ "@emotion/react": "11.10.8",
17
+ "@emotion/styled": "11.10.6",
18
+ "@fortawesome/fontawesome-svg-core": "1.3.0",
19
+ "@webiny/admin-ui": "0.0.0-unstable.06b2ede40f",
20
+ "@webiny/app": "0.0.0-unstable.06b2ede40f",
21
+ "@webiny/app-admin": "0.0.0-unstable.06b2ede40f",
22
+ "@webiny/app-security": "0.0.0-unstable.06b2ede40f",
23
+ "@webiny/form": "0.0.0-unstable.06b2ede40f",
24
+ "@webiny/plugins": "0.0.0-unstable.06b2ede40f",
25
+ "@webiny/react-composition": "0.0.0-unstable.06b2ede40f",
26
+ "@webiny/validation": "0.0.0-unstable.06b2ede40f",
27
+ "dnd-core": "16.0.1",
28
+ "graphql": "15.9.0",
29
+ "graphql-tag": "2.12.6",
30
+ "lodash": "4.17.21",
31
+ "prop-types": "15.8.1",
32
+ "react": "18.2.0"
33
+ },
34
+ "devDependencies": {
35
+ "@emotion/babel-plugin": "11.11.0",
36
+ "@types/react": "18.2.79",
37
+ "@webiny/cli": "0.0.0-unstable.06b2ede40f",
38
+ "@webiny/project-utils": "0.0.0-unstable.06b2ede40f",
39
+ "babel-plugin-module-resolver": "5.0.2",
40
+ "rimraf": "6.0.1",
41
+ "typescript": "5.3.3"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public",
45
+ "directory": "dist"
46
+ },
47
+ "scripts": {
48
+ "build": "node ../cli/bin.js run build",
49
+ "watch": "node ../cli/bin.js run watch"
50
+ },
51
+ "gitHead": "06b2ede40fc2212a70eeafd74afd50b56fb0ce82"
52
+ }
@@ -0,0 +1,2 @@
1
+ import type { CmsModelField } from "./types";
2
+ export declare const prepareFormData: <T extends Record<string, any>>(input: T, fields: CmsModelField[]) => T;
@@ -0,0 +1,71 @@
1
+ import { plugins } from "@webiny/plugins";
2
+ /**
3
+ * This method builds transformer plugins only once.
4
+ * Really no need in building more than once because at this point all plugins are registered.
5
+ */
6
+ let availableTransformerPlugins = undefined;
7
+ const getAvailableTransformerPlugins = () => {
8
+ if (availableTransformerPlugins) {
9
+ return availableTransformerPlugins;
10
+ }
11
+ availableTransformerPlugins = plugins.byType("cms-field-value-transformer").reduce((transformers, pl) => {
12
+ const fieldTypes = Array.isArray(pl.fieldType) ? pl.fieldType : [pl.fieldType];
13
+ for (const fieldType of fieldTypes) {
14
+ if (transformers[fieldType]) {
15
+ console.warn(`Transformer for field type "${fieldType}" is already defined. There cannot be more than one transformer.`);
16
+ continue;
17
+ }
18
+ transformers[fieldType] = pl;
19
+ }
20
+ return transformers;
21
+ }, {});
22
+ return availableTransformerPlugins;
23
+ };
24
+ let transformationRunner;
25
+ const createTransformationRunner = () => {
26
+ if (transformationRunner) {
27
+ return transformationRunner;
28
+ }
29
+ const availablePlugins = getAvailableTransformerPlugins();
30
+ transformationRunner = (field, value) => {
31
+ const transformer = availablePlugins[field.type];
32
+ if (!transformer) {
33
+ return value;
34
+ }
35
+ return transformer.transform(value, field);
36
+ };
37
+ return transformationRunner;
38
+ };
39
+ export const prepareFormData = (input, fields) => {
40
+ const runTransformation = createTransformationRunner();
41
+ return fields.reduce((output, field) => {
42
+ const inputValue = input[field.fieldId];
43
+ const fieldId = field.fieldId;
44
+ if (field.multipleValues) {
45
+ const values = Array.isArray(inputValue) ? inputValue : undefined;
46
+ if (!values) {
47
+ return output;
48
+ }
49
+ /**
50
+ * We need to skip sending the values if there is only one item in the array, and it is a null or undefined value.
51
+ *
52
+ * In case there are more items in the array, and they are null / undefined,
53
+ * we must not do anything because it means the user added new items into the array,
54
+ * and they want to have it like that - or is a mistake by user - in that case they will then remove the extra item(s).
55
+ */
56
+ //
57
+ else if (values.length === 1 && (values[0] === null || values[0] === undefined)) {
58
+ return output;
59
+ }
60
+ output[fieldId] = values.map(value => runTransformation(field, value));
61
+ return output;
62
+ }
63
+ /**
64
+ * Regular values, single values.
65
+ */
66
+ output[fieldId] = runTransformation(field, inputValue);
67
+ return output;
68
+ }, {});
69
+ };
70
+
71
+ //# sourceMappingURL=prepareFormData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["plugins","availableTransformerPlugins","undefined","getAvailableTransformerPlugins","byType","reduce","transformers","pl","fieldTypes","Array","isArray","fieldType","console","warn","transformationRunner","createTransformationRunner","availablePlugins","field","value","transformer","type","transform","prepareFormData","input","fields","runTransformation","output","inputValue","fieldId","multipleValues","values","length","map"],"sources":["prepareFormData.ts"],"sourcesContent":["import type { CmsFieldValueTransformer, CmsModelField } from \"~/types\";\nimport { plugins } from \"@webiny/plugins\";\n\ninterface AvailableFieldTransformers {\n [fieldType: string]: CmsFieldValueTransformer;\n}\n\n/**\n * This method builds transformer plugins only once.\n * Really no need in building more than once because at this point all plugins are registered.\n */\nlet availableTransformerPlugins: AvailableFieldTransformers | undefined = undefined;\nconst getAvailableTransformerPlugins = (): AvailableFieldTransformers => {\n if (availableTransformerPlugins) {\n return availableTransformerPlugins;\n }\n availableTransformerPlugins = plugins\n .byType<CmsFieldValueTransformer>(\"cms-field-value-transformer\")\n .reduce<AvailableFieldTransformers>((transformers, pl) => {\n const fieldTypes = Array.isArray(pl.fieldType) ? pl.fieldType : [pl.fieldType];\n for (const fieldType of fieldTypes) {\n if (transformers[fieldType]) {\n console.warn(\n `Transformer for field type \"${fieldType}\" is already defined. There cannot be more than one transformer.`\n );\n continue;\n }\n transformers[fieldType] = pl;\n }\n return transformers;\n }, {});\n\n return availableTransformerPlugins;\n};\n\ninterface TransformationRunnerCallable {\n (field: CmsModelField, value: any): any;\n}\n\nlet transformationRunner: TransformationRunnerCallable;\nconst createTransformationRunner = (): TransformationRunnerCallable => {\n if (transformationRunner) {\n return transformationRunner;\n }\n const availablePlugins = getAvailableTransformerPlugins();\n\n transformationRunner = (field, value) => {\n const transformer = availablePlugins[field.type];\n if (!transformer) {\n return value;\n }\n return transformer.transform(value, field);\n };\n return transformationRunner;\n};\n\nexport const prepareFormData = <T extends Record<string, any>>(\n input: T,\n fields: CmsModelField[]\n): T => {\n const runTransformation = createTransformationRunner();\n\n return fields.reduce<Record<keyof T, any>>((output, field) => {\n const inputValue = input[field.fieldId];\n\n const fieldId: keyof T = field.fieldId;\n\n if (field.multipleValues) {\n const values = Array.isArray(inputValue) ? inputValue : undefined;\n if (!values) {\n return output;\n }\n /**\n * We need to skip sending the values if there is only one item in the array, and it is a null or undefined value.\n *\n * In case there are more items in the array, and they are null / undefined,\n * we must not do anything because it means the user added new items into the array,\n * and they want to have it like that - or is a mistake by user - in that case they will then remove the extra item(s).\n */\n //\n else if (values.length === 1 && (values[0] === null || values[0] === undefined)) {\n return output;\n }\n\n output[fieldId] = values.map(value => runTransformation(field, value));\n\n return output;\n }\n /**\n * Regular values, single values.\n */\n output[fieldId] = runTransformation(field, inputValue);\n\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