@webiny/api-headless-cms 0.0.0-unstable.5e7233243f → 0.0.0-unstable.60e968001a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/context.d.ts +5 -2
- package/context.js +63 -8
- package/context.js.map +1 -1
- package/crud/contentEntry/afterDelete.d.ts +2 -2
- package/crud/contentEntry/afterDelete.js +2 -2
- package/crud/contentEntry/afterDelete.js.map +1 -1
- package/crud/contentEntry/beforeCreate.d.ts +2 -2
- package/crud/contentEntry/beforeCreate.js +2 -2
- package/crud/contentEntry/beforeCreate.js.map +1 -1
- package/crud/contentEntry/beforeUpdate.d.ts +2 -2
- package/crud/contentEntry/beforeUpdate.js +2 -2
- package/crud/contentEntry/beforeUpdate.js.map +1 -1
- package/crud/contentEntry/entryDataValidation.js +3 -7
- package/crud/contentEntry/entryDataValidation.js.map +1 -1
- package/crud/contentEntry/markLockedFields.js +10 -11
- package/crud/contentEntry/markLockedFields.js.map +1 -1
- package/crud/contentEntry/referenceFieldsMapping.js +11 -13
- package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
- package/crud/contentEntry/searchableFields.d.ts +9 -0
- package/crud/contentEntry/searchableFields.js +83 -0
- package/crud/contentEntry/searchableFields.js.map +1 -0
- package/crud/contentEntry.crud.d.ts +0 -2
- package/crud/contentEntry.crud.js +253 -270
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/afterCreate.d.ts +3 -3
- package/crud/contentModel/afterCreate.js +5 -5
- package/crud/contentModel/afterCreate.js.map +1 -1
- package/crud/contentModel/afterCreateFrom.d.ts +3 -3
- package/crud/contentModel/afterCreateFrom.js +5 -5
- package/crud/contentModel/afterCreateFrom.js.map +1 -1
- package/crud/contentModel/afterDelete.d.ts +3 -3
- package/crud/contentModel/afterDelete.js +5 -5
- package/crud/contentModel/afterDelete.js.map +1 -1
- package/crud/contentModel/afterUpdate.d.ts +3 -3
- package/crud/contentModel/afterUpdate.js +5 -5
- package/crud/contentModel/afterUpdate.js.map +1 -1
- package/crud/contentModel/beforeCreate.d.ts +4 -4
- package/crud/contentModel/beforeCreate.js +10 -10
- package/crud/contentModel/beforeCreate.js.map +1 -1
- package/crud/contentModel/beforeDelete.d.ts +3 -3
- package/crud/contentModel/beforeDelete.js +6 -6
- package/crud/contentModel/beforeDelete.js.map +1 -1
- package/crud/contentModel/beforeUpdate.d.ts +3 -3
- package/crud/contentModel/beforeUpdate.js +5 -5
- package/crud/contentModel/beforeUpdate.js.map +1 -1
- package/crud/contentModel/createFieldStorageId.js +5 -1
- package/crud/contentModel/createFieldStorageId.js.map +1 -1
- package/crud/contentModel/models.js +12 -0
- package/crud/contentModel/models.js.map +1 -1
- package/crud/contentModel/validateModel.js +1 -1
- package/crud/contentModel/validateModelFields.js +47 -42
- package/crud/contentModel/validateModelFields.js.map +1 -1
- package/crud/contentModel/validation.d.ts +477 -0
- package/crud/contentModel/validation.js +109 -0
- package/crud/contentModel/validation.js.map +1 -0
- package/crud/contentModel.crud.js +287 -211
- package/crud/contentModel.crud.js.map +1 -1
- package/crud/contentModelGroup/beforeCreate.d.ts +2 -2
- package/crud/contentModelGroup/beforeCreate.js +3 -3
- package/crud/contentModelGroup/beforeCreate.js.map +1 -1
- package/crud/contentModelGroup/beforeDelete.d.ts +2 -2
- package/crud/contentModelGroup/beforeDelete.js +3 -3
- package/crud/contentModelGroup/beforeDelete.js.map +1 -1
- package/crud/contentModelGroup/beforeUpdate.d.ts +2 -2
- package/crud/contentModelGroup/beforeUpdate.js +2 -2
- package/crud/contentModelGroup/beforeUpdate.js.map +1 -1
- package/crud/contentModelGroup/validation.d.ts +30 -0
- package/crud/contentModelGroup/validation.js +43 -0
- package/crud/contentModelGroup/validation.js.map +1 -0
- package/crud/contentModelGroup.crud.js +102 -82
- package/crud/contentModelGroup.crud.js.map +1 -1
- package/crud/settings.crud.js +3 -8
- package/crud/settings.crud.js.map +1 -1
- package/crud/system.crud.js +63 -51
- package/crud/system.crud.js.map +1 -1
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +1 -1
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.d.ts +11 -0
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +239 -0
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -0
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +17 -19
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/index.d.ts +2 -1
- package/fieldConverters/index.js +3 -1
- package/fieldConverters/index.js.map +1 -1
- package/graphql/buildSchemaPlugins.d.ts +2 -2
- package/graphql/buildSchemaPlugins.js.map +1 -1
- package/graphql/graphQLHandlerFactory.js +59 -29
- package/graphql/graphQLHandlerFactory.js.map +1 -1
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +49 -38
- package/graphql/index.js.map +1 -1
- package/graphql/schema/baseContentSchema.d.ts +2 -2
- package/graphql/schema/baseContentSchema.js +8 -12
- package/graphql/schema/baseContentSchema.js.map +1 -1
- package/graphql/schema/contentEntries.d.ts +2 -2
- package/graphql/schema/contentEntries.js +6 -6
- package/graphql/schema/contentEntries.js.map +1 -1
- package/graphql/schema/contentModelGroups.d.ts +2 -2
- package/graphql/schema/contentModelGroups.js +3 -3
- package/graphql/schema/contentModelGroups.js.map +1 -1
- package/graphql/schema/contentModels.d.ts +2 -2
- package/graphql/schema/contentModels.js +42 -4
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createFieldResolvers.d.ts +1 -1
- package/graphql/schema/createFieldResolvers.js +26 -16
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphql/schema/createManageResolvers.js +4 -18
- package/graphql/schema/createManageResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.d.ts +2 -0
- package/graphql/schema/createManageSDL.js +11 -12
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/createPreviewResolvers.js +3 -7
- package/graphql/schema/createPreviewResolvers.js.map +1 -1
- package/graphql/schema/createReadResolvers.js +8 -7
- package/graphql/schema/createReadResolvers.js.map +1 -1
- package/graphql/schema/createReadSDL.d.ts +2 -0
- package/graphql/schema/createReadSDL.js +11 -5
- package/graphql/schema/createReadSDL.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGet.js +5 -9
- package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/preview/resolveGet.js +3 -7
- package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/read/resolveGet.js +3 -7
- package/graphql/schema/resolvers/read/resolveGet.js.map +1 -1
- package/graphql/schema/schemaPlugins.d.ts +2 -2
- package/graphql/schema/schemaPlugins.js +11 -8
- package/graphql/schema/schemaPlugins.js.map +1 -1
- package/graphql/system.js +79 -82
- package/graphql/system.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +2 -0
- package/graphqlFields/dynamicZone/dynamicZoneField.js +234 -0
- package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.d.ts +3 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js +79 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js.map +1 -0
- package/graphqlFields/dynamicZone/index.d.ts +2 -0
- package/graphqlFields/dynamicZone/index.js +21 -0
- package/graphqlFields/dynamicZone/index.js.map +1 -0
- package/graphqlFields/index.d.ts +1 -1
- package/graphqlFields/index.js +3 -1
- package/graphqlFields/index.js.map +1 -1
- package/graphqlFields/number.js +4 -0
- package/graphqlFields/number.js.map +1 -1
- package/graphqlFields/object.js +123 -73
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +38 -56
- package/graphqlFields/ref.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +4 -8
- package/index.js.map +1 -1
- package/modelManager/DefaultCmsModelManager.d.ts +7 -7
- package/modelManager/DefaultCmsModelManager.js +1 -1
- package/package.json +30 -31
- package/parameters/header.js +1 -1
- package/parameters/manual.js +7 -8
- package/parameters/manual.js.map +1 -1
- package/parameters/path.js +1 -1
- package/plugins/CmsGraphQLSchemaPlugin.d.ts +5 -0
- package/plugins/CmsGraphQLSchemaPlugin.js +17 -0
- package/plugins/CmsGraphQLSchemaPlugin.js.map +1 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.d.ts +20 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.js +38 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.js.map +1 -0
- package/plugins/CmsGroupPlugin.js +1 -1
- package/plugins/CmsModelFieldConverterPlugin.d.ts +2 -2
- package/plugins/CmsModelFieldConverterPlugin.js +1 -1
- package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
- package/plugins/CmsModelPlugin.d.ts +6 -2
- package/plugins/CmsModelPlugin.js +18 -13
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/plugins/CmsParametersPlugin.js +1 -1
- package/plugins/StorageTransformPlugin.d.ts +11 -11
- package/plugins/StorageTransformPlugin.js +1 -1
- package/plugins/StorageTransformPlugin.js.map +1 -1
- package/plugins/index.d.ts +2 -0
- package/plugins/index.js +26 -0
- package/plugins/index.js.map +1 -1
- package/storage/object.js +7 -8
- package/storage/object.js.map +1 -1
- package/types.d.ts +469 -180
- package/types.js +55 -9
- package/types.js.map +1 -1
- package/upgrades/5.33.0/index.js +5 -9
- package/upgrades/5.33.0/index.js.map +1 -1
- package/utils/converters/Converter.js +1 -1
- package/utils/converters/ConverterCollection.d.ts +7 -0
- package/utils/converters/ConverterCollection.js +36 -8
- package/utils/converters/ConverterCollection.js.map +1 -1
- package/utils/converters/valueKeyStorageConverter.js +3 -7
- package/utils/converters/valueKeyStorageConverter.js.map +1 -1
- package/utils/createTypeFromFields.d.ts +15 -0
- package/utils/createTypeFromFields.js +75 -0
- package/utils/createTypeFromFields.js.map +1 -0
- package/utils/createTypeName.js +4 -2
- package/utils/createTypeName.js.map +1 -1
- package/utils/entryStorage.js +17 -18
- package/utils/entryStorage.js.map +1 -1
- package/utils/filterModelFields.js +5 -9
- package/utils/filterModelFields.js.map +1 -1
- package/utils/getBaseFieldType.d.ts +4 -0
- package/utils/getBaseFieldType.js +12 -0
- package/utils/getBaseFieldType.js.map +1 -0
- package/utils/permissions.js +1 -5
- package/utils/permissions.js.map +1 -1
- package/utils/pluralizedTypeName.js +1 -1
- package/utils/renderFields.js +3 -1
- package/utils/renderFields.js.map +1 -1
- package/utils/renderGetFilterFields.js +8 -3
- package/utils/renderGetFilterFields.js.map +1 -1
- package/utils/renderInputFields.js +3 -1
- package/utils/renderInputFields.js.map +1 -1
- package/utils/renderListFilterFields.js +12 -2
- package/utils/renderListFilterFields.js.map +1 -1
- package/utils/renderSortEnum.d.ts +7 -4
- package/utils/renderSortEnum.js +23 -4
- package/utils/renderSortEnum.js.map +1 -1
- package/utils/toSlug.js +1 -1
- package/validators/dynamicZone.d.ts +2 -0
- package/validators/dynamicZone.js +24 -0
- package/validators/dynamicZone.js.map +1 -0
- package/validators/index.js +3 -1
- package/validators/index.js.map +1 -1
- package/validators/unique.js +1 -1
- package/crud/index.d.ts +0 -6
- package/crud/index.js +0 -89
- package/crud/index.js.map +0 -1
- package/graphql/schema/resolvers/manage/resolveRequestChanges.d.ts +0 -7
- package/graphql/schema/resolvers/manage/resolveRequestChanges.js +0 -21
- package/graphql/schema/resolvers/manage/resolveRequestChanges.js.map +0 -1
- package/graphql/schema/resolvers/manage/resolveRequestReview.d.ts +0 -7
- package/graphql/schema/resolvers/manage/resolveRequestReview.js +0 -21
- package/graphql/schema/resolvers/manage/resolveRequestReview.js.map +0 -1
package/graphqlFields/ref.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.createRefField = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
12
|
var _createTypeName = require("../utils/createTypeName");
|
|
13
13
|
|
|
@@ -15,12 +15,8 @@ var _utils = require("@webiny/utils");
|
|
|
15
15
|
|
|
16
16
|
var _helpers = require("./helpers");
|
|
17
17
|
|
|
18
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
21
|
-
|
|
22
18
|
const createUnionTypeName = (model, field) => {
|
|
23
|
-
return `${(0, _createTypeName.createReadTypeName)(model.modelId)}${(0, _createTypeName.createReadTypeName)(field.fieldId)}`;
|
|
19
|
+
return `${(0, _createTypeName.createReadTypeName)(model.modelId)}_${(0, _createTypeName.createReadTypeName)(field.fieldId)}`;
|
|
24
20
|
};
|
|
25
21
|
|
|
26
22
|
const createListFilters = ({
|
|
@@ -48,7 +44,7 @@ const createFilteringTypeDef = () => {
|
|
|
48
44
|
|
|
49
45
|
const appendTypename = (entries, typename) => {
|
|
50
46
|
return entries.map(item => {
|
|
51
|
-
return
|
|
47
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, item), {}, {
|
|
52
48
|
__typename: typename
|
|
53
49
|
});
|
|
54
50
|
});
|
|
@@ -85,7 +81,13 @@ const createRefField = () => {
|
|
|
85
81
|
|
|
86
82
|
const models = ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.models) || [];
|
|
87
83
|
const gqlType = models.length > 1 ? createUnionTypeName(model, field) : (0, _createTypeName.createReadTypeName)(models[0].modelId);
|
|
88
|
-
|
|
84
|
+
const typeDefs = models.length > 1 ? `union ${gqlType} = ${getFieldModels(field).map(({
|
|
85
|
+
modelId
|
|
86
|
+
}) => (0, _createTypeName.createReadTypeName)(modelId)).join(" | ")}` : "";
|
|
87
|
+
return {
|
|
88
|
+
fields: field.fieldId + `(populate: Boolean = true): ${field.multipleValues ? `[${gqlType}!]` : gqlType}`,
|
|
89
|
+
typeDefs
|
|
90
|
+
};
|
|
89
91
|
},
|
|
90
92
|
|
|
91
93
|
/**
|
|
@@ -106,7 +108,7 @@ const createRefField = () => {
|
|
|
106
108
|
modelIdToTypeName.set(item.modelId, (0, _createTypeName.createReadTypeName)(item.modelId));
|
|
107
109
|
}
|
|
108
110
|
|
|
109
|
-
return async (parent,
|
|
111
|
+
return async (parent, args, context) => {
|
|
110
112
|
const {
|
|
111
113
|
cms
|
|
112
114
|
} = context; // Get field value for this entry
|
|
@@ -117,6 +119,10 @@ const createRefField = () => {
|
|
|
117
119
|
return null;
|
|
118
120
|
}
|
|
119
121
|
|
|
122
|
+
if (args.populate === false) {
|
|
123
|
+
return initialValue;
|
|
124
|
+
}
|
|
125
|
+
|
|
120
126
|
if (field.multipleValues) {
|
|
121
127
|
/**
|
|
122
128
|
* We cast because value really can be array and single value.
|
|
@@ -176,43 +182,15 @@ const createRefField = () => {
|
|
|
176
182
|
return null;
|
|
177
183
|
}
|
|
178
184
|
|
|
179
|
-
return
|
|
185
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, revisions[0]), {}, {
|
|
180
186
|
__typename: modelIdToTypeName.get(value.modelId)
|
|
181
187
|
});
|
|
182
188
|
};
|
|
183
189
|
},
|
|
184
190
|
|
|
185
|
-
createSchema({
|
|
186
|
-
models
|
|
187
|
-
}) {
|
|
188
|
-
const unionFields = [];
|
|
189
|
-
|
|
190
|
-
for (const model of models) {
|
|
191
|
-
// Generate a dedicated union type for every `ref` field which has more than 1 content model assigned.
|
|
192
|
-
model.fields.filter(field => {
|
|
193
|
-
var _field$settings3;
|
|
194
|
-
|
|
195
|
-
return field.type === "ref" && (((_field$settings3 = field.settings) === null || _field$settings3 === void 0 ? void 0 : _field$settings3.models) || []).length > 1;
|
|
196
|
-
}).forEach(field => unionFields.push({
|
|
197
|
-
model,
|
|
198
|
-
field,
|
|
199
|
-
typeName: createUnionTypeName(model, field)
|
|
200
|
-
}));
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const unionFieldsTypeDef = unionFields.map(({
|
|
204
|
-
field,
|
|
205
|
-
typeName
|
|
206
|
-
}) => `union ${typeName} = ${getFieldModels(field).map(({
|
|
207
|
-
modelId
|
|
208
|
-
}) => (0, _createTypeName.createReadTypeName)(modelId)).join(" | ")}`).join("\n");
|
|
209
|
-
const filteringTypeDef = `
|
|
210
|
-
${createFilteringTypeDef()}
|
|
211
|
-
|
|
212
|
-
${unionFieldsTypeDef}
|
|
213
|
-
`;
|
|
191
|
+
createSchema() {
|
|
214
192
|
return {
|
|
215
|
-
typeDefs:
|
|
193
|
+
typeDefs: createFilteringTypeDef(),
|
|
216
194
|
resolvers: {}
|
|
217
195
|
};
|
|
218
196
|
},
|
|
@@ -222,23 +200,27 @@ const createRefField = () => {
|
|
|
222
200
|
manage: {
|
|
223
201
|
createSchema() {
|
|
224
202
|
/**
|
|
225
|
-
* entryId in RefFieldInput is deprecated but cannot mark it as
|
|
203
|
+
* `entryId` in `RefFieldInput` is deprecated, but we cannot mark it as such in GraphQL.
|
|
204
|
+
* `entryId` is extracted at runtime from the `id` which contains both the `entryId` and revision number.
|
|
205
|
+
* See: `packages/api-headless-cms/src/crud/contentEntry/referenceFieldsMapping.ts`
|
|
226
206
|
*/
|
|
227
207
|
return {
|
|
228
|
-
typeDefs:
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
208
|
+
typeDefs:
|
|
209
|
+
/* GraphQL */
|
|
210
|
+
`
|
|
211
|
+
type RefField {
|
|
212
|
+
modelId: String!
|
|
213
|
+
entryId: ID!
|
|
214
|
+
id: ID!
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
input RefFieldInput {
|
|
218
|
+
modelId: String!
|
|
219
|
+
id: ID!
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
${createFilteringTypeDef()}
|
|
223
|
+
`,
|
|
242
224
|
resolvers: {
|
|
243
225
|
RefField: {
|
|
244
226
|
entryId: parent => {
|
package/graphqlFields/ref.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createUnionTypeName","model","field","createReadTypeName","modelId","fieldId","createListFilters","createFilteringTypeDef","appendTypename","entries","typename","map","item","__typename","getFieldModels","settings","Array","isArray","models","modelIdToTypeName","Map","createRefField","name","type","fieldType","isSortable","isSearchable","read","createTypeField","gqlType","length","multipleValues","createResolver","params","set","parent","_","context","cms","initialValue","value","entriesByModel","reduce","collection","ref","includes","entryId","push","getters","Object","keys","idList","getModelManager","READ","getPublishedByIds","getLatestByIds","get","Promise","all","then","results","result","concat","revisions","createSchema","unionFields","fields","filter","forEach","typeName","unionFieldsTypeDef","join","filteringTypeDef","typeDefs","resolvers","manage","RefField","id","parseIdentifier","createInputField","createGraphQLInputField"],"sources":["ref.ts"],"sourcesContent":["import {\n CmsEntry,\n CmsContext,\n CmsModelFieldToGraphQLPlugin,\n CmsModel,\n CmsModelField\n} from \"~/types\";\nimport { createReadTypeName } from \"~/utils/createTypeName\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { createGraphQLInputField } from \"./helpers\";\n\ninterface RefFieldValue {\n id?: string;\n entryId: string;\n modelId: string;\n}\n\ninterface UnionField {\n model: CmsModel;\n field: CmsModelField;\n typeName: string;\n}\n\nconst createUnionTypeName = (model: CmsModel, field: CmsModelField) => {\n return `${createReadTypeName(model.modelId)}${createReadTypeName(field.fieldId)}`;\n};\n\ninterface CreateListFilterParams {\n field: CmsModelField;\n}\nconst createListFilters = ({ field }: CreateListFilterParams) => {\n return `\n ${field.fieldId}: RefFieldWhereInput\n `;\n};\n\nconst createFilteringTypeDef = () => {\n return `\n input RefFieldWhereInput {\n id: String\n id_not: String\n id_in: [String!]\n id_not_in: [String]\n entryId: String\n entryId_not: String\n entryId_in: [String!]\n entryId_not_in: [String!]\n }\n `;\n};\n\nconst appendTypename = (entries: CmsEntry[], typename: string): CmsEntry[] => {\n return entries.map(item => {\n return {\n ...item,\n __typename: typename\n };\n });\n};\n/**\n * We cast settings.models as object to have modelId because internally we know that it is so.\n * Internal stuff so we are sure that settings.models contains what we require.\n */\nconst getFieldModels = (field: CmsModelField): Pick<CmsModel, \"modelId\">[] => {\n if (!field.settings || Array.isArray(field.settings.models) === false) {\n return [];\n }\n return field.settings.models as Pick<CmsModel, \"modelId\">[];\n};\n\nconst modelIdToTypeName = new Map();\n\nexport const createRefField = (): CmsModelFieldToGraphQLPlugin => {\n return {\n name: \"cms-model-field-to-graphql-ref\",\n type: \"cms-model-field-to-graphql\",\n fieldType: \"ref\",\n isSortable: false,\n isSearchable: true,\n read: {\n createTypeField({ model, field }) {\n const models = field.settings?.models || [];\n const gqlType =\n models.length > 1\n ? createUnionTypeName(model, field)\n : createReadTypeName(models[0].modelId);\n\n return field.fieldId + `: ${field.multipleValues ? `[${gqlType}]` : gqlType}`;\n },\n /**\n * TS is complaining about mixed types for createResolver.\n * TODO @ts-refactor @pavel Maybe we should have a single createResolver method?\n */\n // @ts-ignore\n createResolver(params) {\n const { field } = params;\n // Create a map of model types and corresponding modelIds so resolvers don't need to perform the lookup.\n const models = field.settings?.models || [];\n for (const item of models) {\n modelIdToTypeName.set(item.modelId, createReadTypeName(item.modelId));\n }\n\n return async (parent, _, context: CmsContext) => {\n const { cms } = context;\n\n // Get field value for this entry\n const initialValue = parent[field.fieldId] as RefFieldValue | RefFieldValue[];\n\n if (!initialValue) {\n return null;\n }\n\n if (field.multipleValues) {\n /**\n * We cast because value really can be array and single value.\n * At this point, we are 99% sure that it is an array (+ we check for it)\n */\n const value = initialValue as RefFieldValue[];\n if (Array.isArray(value) === false || value.length === 0) {\n return [];\n }\n\n const entriesByModel = value.reduce((collection, ref) => {\n if (!collection[ref.modelId]) {\n collection[ref.modelId] = [];\n } else if (collection[ref.modelId].includes(ref.entryId) === true) {\n return collection;\n }\n\n collection[ref.modelId].push(ref.entryId);\n\n return collection;\n }, {} as Record<string, string[]>);\n\n const getters = Object.keys(entriesByModel).map(async modelId => {\n const idList = entriesByModel[modelId];\n // Get model manager, to get access to CRUD methods\n const model = await cms.getModelManager(modelId);\n\n let entries: CmsEntry[];\n // `read` API works with `published` data\n if (cms.READ) {\n entries = await model.getPublishedByIds(idList);\n }\n // `preview` and `manage` with `latest` data\n else {\n entries = await model.getLatestByIds(idList);\n }\n\n return appendTypename(entries, modelIdToTypeName.get(modelId));\n });\n\n return await Promise.all(getters).then((results: any[]) =>\n results.reduce((result, item) => result.concat(item), [])\n );\n }\n\n const value = initialValue as RefFieldValue;\n\n // Get model manager, to get access to CRUD methods\n const model = await cms.getModelManager(value.modelId);\n\n let revisions: CmsEntry[];\n // `read` API works with `published` data\n if (cms.READ) {\n revisions = await model.getPublishedByIds([value.entryId]);\n }\n // `preview` API works with `latest` data\n else {\n revisions = await model.getLatestByIds([value.entryId]);\n }\n\n /**\n * If there are no revisions we must return null.\n */\n if (!revisions || revisions.length === 0) {\n return null;\n }\n return {\n ...revisions[0],\n __typename: modelIdToTypeName.get(value.modelId)\n };\n };\n },\n createSchema({ models }) {\n const unionFields: UnionField[] = [];\n for (const model of models) {\n // Generate a dedicated union type for every `ref` field which has more than 1 content model assigned.\n model.fields\n .filter(\n field =>\n field.type === \"ref\" && (field.settings?.models || []).length > 1\n )\n .forEach(field =>\n unionFields.push({\n model,\n field,\n typeName: createUnionTypeName(model, field)\n })\n );\n }\n const unionFieldsTypeDef = unionFields\n .map(\n ({ field, typeName }) =>\n `union ${typeName} = ${getFieldModels(field)\n .map(({ modelId }) => createReadTypeName(modelId))\n .join(\" | \")}`\n )\n .join(\"\\n\");\n\n const filteringTypeDef = `\n ${createFilteringTypeDef()}\n \n ${unionFieldsTypeDef}\n `;\n\n return {\n typeDefs: filteringTypeDef,\n resolvers: {}\n };\n },\n createListFilters\n },\n manage: {\n createSchema() {\n /**\n * entryId in RefFieldInput is deprecated but cannot mark it as GraphQL does not allow marking input fields as deprecated\n */\n return {\n typeDefs: `\n type RefField {\n modelId: String!\n entryId: ID!\n id: ID!\n }\n \n input RefFieldInput {\n modelId: String!\n id: ID!\n }\n \n ${createFilteringTypeDef()}\n `,\n resolvers: {\n RefField: {\n entryId: (parent: RefFieldValue) => {\n const { id } = parseIdentifier(parent.entryId || parent.id);\n return id;\n },\n id: (parent: RefFieldValue) => {\n return parent.id || parent.entryId;\n }\n }\n }\n };\n },\n createTypeField({ field }) {\n if (field.multipleValues) {\n return `${field.fieldId}: [RefField!]`;\n }\n return `${field.fieldId}: RefField`;\n },\n createInputField({ field }) {\n return createGraphQLInputField(field, \"RefFieldInput\");\n },\n createListFilters\n }\n };\n};\n"],"mappings":";;;;;;;;;;;AAOA;;AACA;;AACA;;;;;;AAcA,MAAMA,mBAAmB,GAAG,CAACC,KAAD,EAAkBC,KAAlB,KAA2C;EACnE,OAAQ,GAAE,IAAAC,kCAAA,EAAmBF,KAAK,CAACG,OAAzB,CAAkC,GAAE,IAAAD,kCAAA,EAAmBD,KAAK,CAACG,OAAzB,CAAkC,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AwB9E,KAAxB,EAA+B,eAA/B,CAAP;MACH,CAzCG;;MA0CJI;IA1CI;EAtJL,CAAP;AAmMH,CApMM"}
|
|
1
|
+
{"version":3,"names":["createUnionTypeName","model","field","createReadTypeName","modelId","fieldId","createListFilters","createFilteringTypeDef","appendTypename","entries","typename","map","item","__typename","getFieldModels","settings","Array","isArray","models","modelIdToTypeName","Map","createRefField","name","type","fieldType","isSortable","isSearchable","read","createTypeField","gqlType","length","typeDefs","join","fields","multipleValues","createResolver","params","set","parent","args","context","cms","initialValue","populate","value","entriesByModel","reduce","collection","ref","includes","entryId","push","getters","Object","keys","idList","getModelManager","READ","getPublishedByIds","getLatestByIds","get","Promise","all","then","results","result","concat","revisions","createSchema","resolvers","manage","RefField","id","parseIdentifier","createInputField","createGraphQLInputField"],"sources":["ref.ts"],"sourcesContent":["import {\n CmsEntry,\n CmsContext,\n CmsModelFieldToGraphQLPlugin,\n CmsModel,\n CmsModelField\n} from \"~/types\";\nimport { createReadTypeName } from \"~/utils/createTypeName\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { createGraphQLInputField } from \"./helpers\";\n\ninterface RefFieldValue {\n /**\n * `id` is optional for backwards compatibility with records created before this property was introduced.\n */\n id?: string;\n entryId: string;\n modelId: string;\n}\n\nconst createUnionTypeName = (model: CmsModel, field: CmsModelField) => {\n return `${createReadTypeName(model.modelId)}_${createReadTypeName(field.fieldId)}`;\n};\n\ninterface CreateListFilterParams {\n field: CmsModelField;\n}\nconst createListFilters = ({ field }: CreateListFilterParams) => {\n return `\n ${field.fieldId}: RefFieldWhereInput\n `;\n};\n\nconst createFilteringTypeDef = () => {\n return `\n input RefFieldWhereInput {\n id: String\n id_not: String\n id_in: [String!]\n id_not_in: [String]\n entryId: String\n entryId_not: String\n entryId_in: [String!]\n entryId_not_in: [String!]\n }\n `;\n};\n\nconst appendTypename = (entries: CmsEntry[], typename: string): CmsEntry[] => {\n return entries.map(item => {\n return {\n ...item,\n __typename: typename\n };\n });\n};\n/**\n * We cast settings.models as object to have modelId because internally we know that it is so.\n * Internal stuff so we are sure that settings.models contains what we require.\n */\nconst getFieldModels = (field: CmsModelField): Pick<CmsModel, \"modelId\">[] => {\n if (!field.settings || Array.isArray(field.settings.models) === false) {\n return [];\n }\n return field.settings.models as Pick<CmsModel, \"modelId\">[];\n};\n\nconst modelIdToTypeName = new Map();\n\nexport const createRefField = (): CmsModelFieldToGraphQLPlugin => {\n return {\n name: \"cms-model-field-to-graphql-ref\",\n type: \"cms-model-field-to-graphql\",\n fieldType: \"ref\",\n isSortable: false,\n isSearchable: true,\n read: {\n createTypeField({ model, field }) {\n const models = field.settings?.models || [];\n const gqlType =\n models.length > 1\n ? createUnionTypeName(model, field)\n : createReadTypeName(models[0].modelId);\n\n const typeDefs =\n models.length > 1\n ? `union ${gqlType} = ${getFieldModels(field)\n .map(({ modelId }) => createReadTypeName(modelId))\n .join(\" | \")}`\n : \"\";\n\n return {\n fields:\n field.fieldId +\n `(populate: Boolean = true): ${\n field.multipleValues ? `[${gqlType}!]` : gqlType\n }`,\n typeDefs\n };\n },\n /**\n * TS is complaining about mixed types for createResolver.\n * TODO @ts-refactor @pavel Maybe we should have a single createResolver method?\n */\n // @ts-ignore\n createResolver(params) {\n const { field } = params;\n // Create a map of model types and corresponding modelIds so resolvers don't need to perform the lookup.\n const models = field.settings?.models || [];\n for (const item of models) {\n modelIdToTypeName.set(item.modelId, createReadTypeName(item.modelId));\n }\n\n return async (parent, args, context: CmsContext) => {\n const { cms } = context;\n\n // Get field value for this entry\n const initialValue = parent[field.fieldId] as RefFieldValue | RefFieldValue[];\n\n if (!initialValue) {\n return null;\n }\n if (args.populate === false) {\n return initialValue;\n }\n\n if (field.multipleValues) {\n /**\n * We cast because value really can be array and single value.\n * At this point, we are 99% sure that it is an array (+ we check for it)\n */\n const value = initialValue as RefFieldValue[];\n if (Array.isArray(value) === false || value.length === 0) {\n return [];\n }\n\n const entriesByModel = value.reduce((collection, ref) => {\n if (!collection[ref.modelId]) {\n collection[ref.modelId] = [];\n } else if (collection[ref.modelId].includes(ref.entryId) === true) {\n return collection;\n }\n\n collection[ref.modelId].push(ref.entryId);\n\n return collection;\n }, {} as Record<string, string[]>);\n\n const getters = Object.keys(entriesByModel).map(async modelId => {\n const idList = entriesByModel[modelId];\n // Get model manager, to get access to CRUD methods\n const model = await cms.getModelManager(modelId);\n\n let entries: CmsEntry[];\n // `read` API works with `published` data\n if (cms.READ) {\n entries = await model.getPublishedByIds(idList);\n }\n // `preview` and `manage` with `latest` data\n else {\n entries = await model.getLatestByIds(idList);\n }\n\n return appendTypename(entries, modelIdToTypeName.get(modelId));\n });\n\n return await Promise.all(getters).then((results: any[]) =>\n results.reduce((result, item) => result.concat(item), [])\n );\n }\n\n const value = initialValue as RefFieldValue;\n\n // Get model manager, to get access to CRUD methods\n const model = await cms.getModelManager(value.modelId);\n\n let revisions: CmsEntry[];\n // `read` API works with `published` data\n if (cms.READ) {\n revisions = await model.getPublishedByIds([value.entryId]);\n }\n // `preview` API works with `latest` data\n else {\n revisions = await model.getLatestByIds([value.entryId]);\n }\n\n /**\n * If there are no revisions we must return null.\n */\n if (!revisions || revisions.length === 0) {\n return null;\n }\n return {\n ...revisions[0],\n __typename: modelIdToTypeName.get(value.modelId)\n };\n };\n },\n createSchema() {\n return {\n typeDefs: createFilteringTypeDef(),\n resolvers: {}\n };\n },\n createListFilters\n },\n manage: {\n createSchema() {\n /**\n * `entryId` in `RefFieldInput` is deprecated, but we cannot mark it as such in GraphQL.\n * `entryId` is extracted at runtime from the `id` which contains both the `entryId` and revision number.\n * See: `packages/api-headless-cms/src/crud/contentEntry/referenceFieldsMapping.ts`\n */\n return {\n typeDefs: /* GraphQL */ `\n type RefField {\n modelId: String!\n entryId: ID!\n id: ID!\n }\n\n input RefFieldInput {\n modelId: String!\n id: ID!\n }\n\n ${createFilteringTypeDef()}\n `,\n resolvers: {\n RefField: {\n entryId: (parent: RefFieldValue) => {\n const { id } = parseIdentifier(parent.entryId || parent.id);\n return id;\n },\n id: (parent: RefFieldValue) => {\n return parent.id || parent.entryId;\n }\n }\n }\n };\n },\n createTypeField({ field }) {\n if (field.multipleValues) {\n return `${field.fieldId}: [RefField!]`;\n }\n return `${field.fieldId}: RefField`;\n },\n createInputField({ field }) {\n return createGraphQLInputField(field, \"RefFieldInput\");\n },\n createListFilters\n }\n };\n};\n"],"mappings":";;;;;;;;;;;AAOA;;AACA;;AACA;;AAWA,MAAMA,mBAAmB,GAAG,CAACC,KAAD,EAAkBC,KAAlB,KAA2C;EACnE,OAAQ,GAAE,IAAAC,kCAAA,EAAmBF,KAAK,CAACG,OAAzB,CAAkC,IAAG,IAAAD,kCAAA,EAAmBD,KAAK,CAACG,OAAzB,CAAkC,EAAjF;AACH,CAFD;;AAOA,MAAMC,iBAAiB,GAAG,CAAC;EAAEJ;AAAF,CAAD,KAAuC;EAC7D,OAAQ;AACZ,UAAUA,KAAK,CAACG,OAAQ;AACxB,KAFI;AAGH,CAJD;;AAMA,MAAME,sBAAsB,GAAG,MAAM;EACjC,OAAQ;AACZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAXI;AAYH,CAbD;;AAeA,MAAMC,cAAc,GAAG,CAACC,OAAD,EAAsBC,QAAtB,KAAuD;EAC1E,OAAOD,OAAO,CAACE,GAAR,CAAYC,IAAI,IAAI;IACvB,mEACOA,IADP;MAEIC,UAAU,EAAEH;IAFhB;EAIH,CALM,CAAP;AAMH,CAPD;AAQA;AACA;AACA;AACA;;;AACA,MAAMI,cAAc,GAAIZ,KAAD,IAAuD;EAC1E,IAAI,CAACA,KAAK,CAACa,QAAP,IAAmBC,KAAK,CAACC,OAAN,CAAcf,KAAK,CAACa,QAAN,CAAeG,MAA7B,MAAyC,KAAhE,EAAuE;IACnE,OAAO,EAAP;EACH;;EACD,OAAOhB,KAAK,CAACa,QAAN,CAAeG,MAAtB;AACH,CALD;;AAOA,MAAMC,iBAAiB,GAAG,IAAIC,GAAJ,EAA1B;;AAEO,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CAAP;AAuLH,CAxLM"}
|
package/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { CreateGraphQLParams } from "./graphql";
|
|
2
|
-
import { CrudParams } from "./
|
|
2
|
+
import { CrudParams } from "./context";
|
|
3
3
|
import { entryFieldFromStorageTransform, entryFromStorageTransform, entryToStorageTransform } from "./utils/entryStorage";
|
|
4
4
|
export declare type CreateHeadlessCmsGraphQLParams = CreateGraphQLParams;
|
|
5
|
-
export declare const createHeadlessCmsGraphQL: (params?: CreateHeadlessCmsGraphQLParams) => (import("./plugins").CmsParametersPlugin |
|
|
5
|
+
export declare const createHeadlessCmsGraphQL: (params?: CreateHeadlessCmsGraphQLParams) => (import("./plugins").CmsParametersPlugin | import("@webiny/api").ContextPlugin<import("./types").CmsContext> | import("@webiny/plugins/types").PluginCollection | import("@webiny/handler-graphql").GraphQLSchemaPlugin<import("./types").CmsContext>[])[];
|
|
6
6
|
export declare type ContentContextParams = CrudParams;
|
|
7
|
-
export declare const createHeadlessCmsContext: (params: ContentContextParams) => (import("./types").
|
|
7
|
+
export declare const createHeadlessCmsContext: (params: ContentContextParams) => (import("./types").ModelManagerPlugin | import("./plugins").StorageTransformPlugin<any, any, import("./types").CmsModelField> | import("@webiny/api").ContextPlugin<import("./types").CmsContext> | import("@webiny/api-upgrade").UpgradePlugin<import("./types").CmsContext>[] | import("./plugins").StorageTransformPlugin<any, any, import("./types").CmsModelDynamicZoneField> | import("./types").CmsModelFieldToGraphQLPlugin<any>[] | (import("./types").CmsModelFieldValidatorPlugin | import("./types").CmsModelFieldPatternValidatorPlugin[])[] | (import("./fieldConverters/CmsModelObjectFieldConverterPlugin").CmsModelObjectFieldConverterPlugin | import("./fieldConverters/CmsModelDefaultFieldConverterPlugin").CmsModelDefaultFieldConverterPlugin | import("./fieldConverters/CmsModelDynamicZoneFieldConverterPlugin").CmsModelDynamicZoneFieldConverterPlugin)[])[];
|
|
8
8
|
export * from "./graphqlFields";
|
|
9
9
|
export * from "./plugins";
|
|
10
10
|
export { entryToStorageTransform, entryFieldFromStorageTransform, entryFromStorageTransform };
|
package/index.js
CHANGED
|
@@ -36,8 +36,6 @@ var _upgrades = require("./upgrades");
|
|
|
36
36
|
|
|
37
37
|
var _modelManager = require("./modelManager");
|
|
38
38
|
|
|
39
|
-
var _crud = require("./crud");
|
|
40
|
-
|
|
41
39
|
var _graphqlFields = require("./graphqlFields");
|
|
42
40
|
|
|
43
41
|
Object.keys(_graphqlFields).forEach(function (key) {
|
|
@@ -58,6 +56,8 @@ var _default = require("./storage/default");
|
|
|
58
56
|
|
|
59
57
|
var _object = require("./storage/object");
|
|
60
58
|
|
|
59
|
+
var _dynamicZoneStorage = require("./graphqlFields/dynamicZone/dynamicZoneStorage");
|
|
60
|
+
|
|
61
61
|
var _parameters = require("./parameters");
|
|
62
62
|
|
|
63
63
|
var _context = require("./context");
|
|
@@ -89,7 +89,7 @@ const createHeadlessCmsGraphQL = (params = {}) => {
|
|
|
89
89
|
/**
|
|
90
90
|
* At this point we can create, or not create, CMS GraphQL Schema.
|
|
91
91
|
*/
|
|
92
|
-
(0, _graphql.createGraphQL)(params)];
|
|
92
|
+
...(0, _graphql.createGraphQL)(params)];
|
|
93
93
|
};
|
|
94
94
|
|
|
95
95
|
exports.createHeadlessCmsGraphQL = createHeadlessCmsGraphQL;
|
|
@@ -99,11 +99,7 @@ const createHeadlessCmsContext = params => {
|
|
|
99
99
|
/**
|
|
100
100
|
* Context for all Lambdas - everything is loaded now.
|
|
101
101
|
*/
|
|
102
|
-
(0, _context.createContextPlugin)(), (0, _modelManager.createDefaultModelManager)(),
|
|
103
|
-
/**
|
|
104
|
-
*
|
|
105
|
-
*/
|
|
106
|
-
(0, _crud.createCrud)(params), (0, _graphqlFields.createGraphQLFields)(), (0, _fieldConverters.createFieldConverters)(), (0, _validators.createValidators)(), (0, _default.createDefaultStorageTransform)(), (0, _object.createObjectStorageTransform)(), (0, _upgrades.createUpgrades)()];
|
|
102
|
+
(0, _context.createContextPlugin)(params), (0, _modelManager.createDefaultModelManager)(), (0, _graphqlFields.createGraphQLFields)(), (0, _fieldConverters.createFieldConverters)(), (0, _validators.createValidators)(), (0, _default.createDefaultStorageTransform)(), (0, _object.createObjectStorageTransform)(), (0, _dynamicZoneStorage.createDynamicZoneStorageTransform)(), (0, _upgrades.createUpgrades)()];
|
|
107
103
|
};
|
|
108
104
|
|
|
109
105
|
exports.createHeadlessCmsContext = createHeadlessCmsContext;
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createHeadlessCmsGraphQL","params","createPathParameterPlugin","createHeaderParameterPlugin","createContextParameterPlugin","baseCreateGraphQL","createHeadlessCmsContext","createContextPlugin","createDefaultModelManager","
|
|
1
|
+
{"version":3,"names":["createHeadlessCmsGraphQL","params","createPathParameterPlugin","createHeaderParameterPlugin","createContextParameterPlugin","baseCreateGraphQL","createHeadlessCmsContext","createContextPlugin","createDefaultModelManager","createGraphQLFields","createFieldConverters","createValidators","createDefaultStorageTransform","createObjectStorageTransform","createDynamicZoneStorageTransform","createUpgrades"],"sources":["index.ts"],"sourcesContent":["import { createGraphQL as baseCreateGraphQL, CreateGraphQLParams } from \"~/graphql\";\nimport { createUpgrades } from \"~/upgrades\";\nimport { createDefaultModelManager } from \"~/modelManager\";\nimport { createGraphQLFields } from \"~/graphqlFields\";\nimport { createValidators } from \"~/validators\";\nimport { createDefaultStorageTransform } from \"~/storage/default\";\nimport { createObjectStorageTransform } from \"~/storage/object\";\nimport { createDynamicZoneStorageTransform } from \"~/graphqlFields/dynamicZone/dynamicZoneStorage\";\nimport {\n createContextParameterPlugin,\n createHeaderParameterPlugin,\n createPathParameterPlugin\n} from \"~/parameters\";\nimport { createContextPlugin, CrudParams } from \"~/context\";\nimport {\n entryFieldFromStorageTransform,\n entryFromStorageTransform,\n entryToStorageTransform\n} from \"./utils/entryStorage\";\nimport { createFieldConverters } from \"~/fieldConverters\";\n\nexport type CreateHeadlessCmsGraphQLParams = CreateGraphQLParams;\nexport const createHeadlessCmsGraphQL = (params: CreateHeadlessCmsGraphQLParams = {}) => {\n return [\n /**\n * PathParameter plugins are used to determine the type of the cms endpoint\n */\n createPathParameterPlugin(),\n createHeaderParameterPlugin(),\n createContextParameterPlugin(),\n /**\n * At this point we can create, or not create, CMS GraphQL Schema.\n */\n ...baseCreateGraphQL(params)\n ];\n};\n\nexport type ContentContextParams = CrudParams;\nexport const createHeadlessCmsContext = (params: ContentContextParams) => {\n return [\n /**\n * Context for all Lambdas - everything is loaded now.\n */\n createContextPlugin(params),\n createDefaultModelManager(),\n createGraphQLFields(),\n createFieldConverters(),\n createValidators(),\n createDefaultStorageTransform(),\n createObjectStorageTransform(),\n createDynamicZoneStorageTransform(),\n createUpgrades()\n ];\n};\nexport * from \"~/graphqlFields\";\nexport * from \"~/plugins\";\nexport { entryToStorageTransform, entryFieldFromStorageTransform, entryFromStorageTransform };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAmDA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAlDA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAKA;;AAoCA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAjCO,MAAMA,wBAAwB,GAAG,CAACC,MAAsC,GAAG,EAA1C,KAAiD;EACrF,OAAO;EACH;AACR;AACA;EACQ,IAAAC,qCAAA,GAJG,EAKH,IAAAC,uCAAA,GALG,EAMH,IAAAC,wCAAA,GANG;EAOH;AACR;AACA;EACQ,GAAG,IAAAC,sBAAA,EAAkBJ,MAAlB,CAVA,CAAP;AAYH,CAbM;;;;AAgBA,MAAMK,wBAAwB,GAAIL,MAAD,IAAkC;EACtE,OAAO;EACH;AACR;AACA;EACQ,IAAAM,4BAAA,EAAoBN,MAApB,CAJG,EAKH,IAAAO,uCAAA,GALG,EAMH,IAAAC,kCAAA,GANG,EAOH,IAAAC,sCAAA,GAPG,EAQH,IAAAC,4BAAA,GARG,EASH,IAAAC,sCAAA,GATG,EAUH,IAAAC,oCAAA,GAVG,EAWH,IAAAC,qDAAA,GAXG,EAYH,IAAAC,wBAAA,GAZG,CAAP;AAcH,CAfM"}
|
|
@@ -3,12 +3,12 @@ export declare class DefaultCmsModelManager implements CmsModelManager {
|
|
|
3
3
|
private readonly _context;
|
|
4
4
|
private readonly _model;
|
|
5
5
|
constructor(context: CmsContext, model: CmsModel);
|
|
6
|
-
create(data: CreateCmsEntryInput): Promise<import("../types").CmsEntry
|
|
6
|
+
create(data: CreateCmsEntryInput): Promise<import("../types").CmsEntry<import("~/types").CmsEntryValues>>;
|
|
7
7
|
delete(id: string): Promise<void>;
|
|
8
|
-
get(id: string): Promise<import("../types").CmsEntry
|
|
9
|
-
listPublished(params: CmsEntryListParams): Promise<[import("../types").CmsEntry[], import("../types").CmsEntryMeta]>;
|
|
10
|
-
listLatest(params: CmsEntryListParams): Promise<[import("../types").CmsEntry[], import("../types").CmsEntryMeta]>;
|
|
11
|
-
getPublishedByIds(ids: string[]): Promise<import("../types").CmsEntry[]>;
|
|
12
|
-
getLatestByIds(ids: string[]): Promise<import("../types").CmsEntry[]>;
|
|
13
|
-
update(id: string, data: UpdateCmsEntryInput): Promise<import("../types").CmsEntry
|
|
8
|
+
get(id: string): Promise<import("../types").CmsEntry<import("~/types").CmsEntryValues>>;
|
|
9
|
+
listPublished(params: CmsEntryListParams): Promise<[import("../types").CmsEntry<import("~/types").CmsEntryValues>[], import("../types").CmsEntryMeta]>;
|
|
10
|
+
listLatest(params: CmsEntryListParams): Promise<[import("../types").CmsEntry<import("~/types").CmsEntryValues>[], import("../types").CmsEntryMeta]>;
|
|
11
|
+
getPublishedByIds(ids: string[]): Promise<import("../types").CmsEntry<import("~/types").CmsEntryValues>[]>;
|
|
12
|
+
getLatestByIds(ids: string[]): Promise<import("../types").CmsEntry<import("~/types").CmsEntryValues>[]>;
|
|
13
|
+
update(id: string, data: UpdateCmsEntryInput): Promise<import("../types").CmsEntry<import("~/types").CmsEntryValues>>;
|
|
14
14
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-headless-cms",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.60e968001a",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms:base"
|
|
@@ -18,26 +18,25 @@
|
|
|
18
18
|
],
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@babel/runtime": "7.
|
|
22
|
-
"@commodo/fields": "1.1.2-beta.20",
|
|
21
|
+
"@babel/runtime": "7.19.0",
|
|
23
22
|
"@graphql-tools/schema": "7.1.5",
|
|
24
|
-
"@webiny/api": "0.0.0-unstable.
|
|
25
|
-
"@webiny/api-file-manager": "0.0.0-unstable.
|
|
26
|
-
"@webiny/api-i18n": "0.0.0-unstable.
|
|
27
|
-
"@webiny/api-i18n-ddb": "0.0.0-unstable.
|
|
28
|
-
"@webiny/api-security": "0.0.0-unstable.
|
|
29
|
-
"@webiny/api-tenancy": "0.0.0-unstable.
|
|
30
|
-
"@webiny/api-upgrade": "0.0.0-unstable.
|
|
31
|
-
"@webiny/error": "0.0.0-unstable.
|
|
32
|
-
"@webiny/handler": "0.0.0-unstable.
|
|
33
|
-
"@webiny/handler-aws": "0.0.0-unstable.
|
|
34
|
-
"@webiny/handler-db": "0.0.0-unstable.
|
|
35
|
-
"@webiny/handler-graphql": "0.0.0-unstable.
|
|
36
|
-
"@webiny/plugins": "0.0.0-unstable.
|
|
37
|
-
"@webiny/pubsub": "0.0.0-unstable.
|
|
38
|
-
"@webiny/utils": "0.0.0-unstable.
|
|
39
|
-
"@webiny/validation": "0.0.0-unstable.
|
|
40
|
-
"
|
|
23
|
+
"@webiny/api": "0.0.0-unstable.60e968001a",
|
|
24
|
+
"@webiny/api-file-manager": "0.0.0-unstable.60e968001a",
|
|
25
|
+
"@webiny/api-i18n": "0.0.0-unstable.60e968001a",
|
|
26
|
+
"@webiny/api-i18n-ddb": "0.0.0-unstable.60e968001a",
|
|
27
|
+
"@webiny/api-security": "0.0.0-unstable.60e968001a",
|
|
28
|
+
"@webiny/api-tenancy": "0.0.0-unstable.60e968001a",
|
|
29
|
+
"@webiny/api-upgrade": "0.0.0-unstable.60e968001a",
|
|
30
|
+
"@webiny/error": "0.0.0-unstable.60e968001a",
|
|
31
|
+
"@webiny/handler": "0.0.0-unstable.60e968001a",
|
|
32
|
+
"@webiny/handler-aws": "0.0.0-unstable.60e968001a",
|
|
33
|
+
"@webiny/handler-db": "0.0.0-unstable.60e968001a",
|
|
34
|
+
"@webiny/handler-graphql": "0.0.0-unstable.60e968001a",
|
|
35
|
+
"@webiny/plugins": "0.0.0-unstable.60e968001a",
|
|
36
|
+
"@webiny/pubsub": "0.0.0-unstable.60e968001a",
|
|
37
|
+
"@webiny/utils": "0.0.0-unstable.60e968001a",
|
|
38
|
+
"@webiny/validation": "0.0.0-unstable.60e968001a",
|
|
39
|
+
"code-frame": "5.0.0",
|
|
41
40
|
"dataloader": "2.1.0",
|
|
42
41
|
"dot-prop": "6.0.1",
|
|
43
42
|
"graphql-tag": "2.12.6",
|
|
@@ -46,18 +45,18 @@
|
|
|
46
45
|
"p-reduce": "2.1.0",
|
|
47
46
|
"pluralize": "8.0.0",
|
|
48
47
|
"semver": "6.3.0",
|
|
49
|
-
"slugify": "1.6.5"
|
|
48
|
+
"slugify": "1.6.5",
|
|
49
|
+
"zod": "3.20.2"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@babel/cli": "^7.
|
|
53
|
-
"@babel/core": "^7.
|
|
54
|
-
"@babel/preset-env": "^7.
|
|
55
|
-
"@
|
|
56
|
-
"@webiny/api-
|
|
57
|
-
"@webiny/api-
|
|
58
|
-
"@webiny/
|
|
59
|
-
"@webiny/
|
|
60
|
-
"@webiny/project-utils": "^0.0.0-unstable.5e7233243f",
|
|
52
|
+
"@babel/cli": "^7.19.3",
|
|
53
|
+
"@babel/core": "^7.19.3",
|
|
54
|
+
"@babel/preset-env": "^7.19.4",
|
|
55
|
+
"@webiny/api-security-so-ddb": "^0.0.0-unstable.60e968001a",
|
|
56
|
+
"@webiny/api-tenancy-so-ddb": "^0.0.0-unstable.60e968001a",
|
|
57
|
+
"@webiny/api-wcp": "^0.0.0-unstable.60e968001a",
|
|
58
|
+
"@webiny/cli": "^0.0.0-unstable.60e968001a",
|
|
59
|
+
"@webiny/project-utils": "^0.0.0-unstable.60e968001a",
|
|
61
60
|
"apollo-graphql": "^0.9.5",
|
|
62
61
|
"get-yarn-workspaces": "^1.0.2",
|
|
63
62
|
"graphql": "^15.7.2",
|
|
@@ -77,5 +76,5 @@
|
|
|
77
76
|
"build": "yarn webiny run build",
|
|
78
77
|
"watch": "yarn webiny run watch"
|
|
79
78
|
},
|
|
80
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "60e968001a7897edd990fe7d7eecf7dd0a1c2977"
|
|
81
80
|
}
|
package/parameters/header.js
CHANGED
package/parameters/manual.js
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.createManualPlugin = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
12
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
13
|
|
|
14
14
|
var _CmsParametersPlugin = require("../plugins/CmsParametersPlugin");
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
/**
|
|
17
|
+
* This would be used for custom Lambdas when there is no path or header information about the endpoint type and locale.
|
|
18
|
+
*/
|
|
20
19
|
const createManualPlugin = params => {
|
|
21
20
|
return new _CmsParametersPlugin.CmsParametersPlugin(async () => {
|
|
22
21
|
const {
|
|
@@ -30,9 +29,9 @@ const createManualPlugin = params => {
|
|
|
30
29
|
if (!type && !locale) {
|
|
31
30
|
return null;
|
|
32
31
|
} else if (!type) {
|
|
33
|
-
throw new _error.default(`There is defined "locale" CMS parameter but no "endpointType".`, "MALFORMED_ENDPOINT_TYPE",
|
|
32
|
+
throw new _error.default(`There is defined "locale" CMS parameter but no "endpointType".`, "MALFORMED_ENDPOINT_TYPE", (0, _objectSpread2.default)({}, params));
|
|
34
33
|
} else if (!locale) {
|
|
35
|
-
throw new _error.default(`There is defined "endpointType" CMS parameter but no "locale".`, "MALFORMED_LOCALE_TYPE",
|
|
34
|
+
throw new _error.default(`There is defined "endpointType" CMS parameter but no "locale".`, "MALFORMED_LOCALE_TYPE", (0, _objectSpread2.default)({}, params));
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
return {
|
package/parameters/manual.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createManualPlugin","params","CmsParametersPlugin","endpointType","type","locale","WebinyError"],"sources":["manual.ts"],"sourcesContent":["/**\n * This would be used for custom Lambdas when there is no path or header information about the endpoint type and locale.\n */\nimport WebinyError from \"@webiny/error\";\nimport {\n CmsParametersPlugin,\n CmsParametersPluginResponseLocale,\n CmsParametersPluginResponseType\n} from \"~/plugins/CmsParametersPlugin\";\n\nexport interface ManualPluginParams {\n endpointType?: CmsParametersPluginResponseType;\n locale?: CmsParametersPluginResponseLocale;\n}\n\nexport const createManualPlugin = (params: ManualPluginParams): CmsParametersPlugin => {\n return new CmsParametersPlugin(async () => {\n const { endpointType: type, locale } = params;\n /**\n * if both of parameters are not existing, just skip this plugin.\n */\n if (!type && !locale) {\n return null;\n } else if (!type) {\n throw new WebinyError(\n `There is defined \"locale\" CMS parameter but no \"endpointType\".`,\n \"MALFORMED_ENDPOINT_TYPE\",\n {\n ...params\n }\n );\n } else if (!locale) {\n throw new WebinyError(\n `There is defined \"endpointType\" CMS parameter but no \"locale\".`,\n \"MALFORMED_LOCALE_TYPE\",\n {\n ...params\n }\n );\n }\n\n return {\n type,\n locale\n };\n });\n};\n"],"mappings":";;;;;;;;;;;AAGA;;AACA
|
|
1
|
+
{"version":3,"names":["createManualPlugin","params","CmsParametersPlugin","endpointType","type","locale","WebinyError"],"sources":["manual.ts"],"sourcesContent":["/**\n * This would be used for custom Lambdas when there is no path or header information about the endpoint type and locale.\n */\nimport WebinyError from \"@webiny/error\";\nimport {\n CmsParametersPlugin,\n CmsParametersPluginResponseLocale,\n CmsParametersPluginResponseType\n} from \"~/plugins/CmsParametersPlugin\";\n\nexport interface ManualPluginParams {\n endpointType?: CmsParametersPluginResponseType;\n locale?: CmsParametersPluginResponseLocale;\n}\n\nexport const createManualPlugin = (params: ManualPluginParams): CmsParametersPlugin => {\n return new CmsParametersPlugin(async () => {\n const { endpointType: type, locale } = params;\n /**\n * if both of parameters are not existing, just skip this plugin.\n */\n if (!type && !locale) {\n return null;\n } else if (!type) {\n throw new WebinyError(\n `There is defined \"locale\" CMS parameter but no \"endpointType\".`,\n \"MALFORMED_ENDPOINT_TYPE\",\n {\n ...params\n }\n );\n } else if (!locale) {\n throw new WebinyError(\n `There is defined \"endpointType\" CMS parameter but no \"locale\".`,\n \"MALFORMED_LOCALE_TYPE\",\n {\n ...params\n }\n );\n }\n\n return {\n type,\n locale\n };\n });\n};\n"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;AAaO,MAAMA,kBAAkB,GAAIC,MAAD,IAAqD;EACnF,OAAO,IAAIC,wCAAJ,CAAwB,YAAY;IACvC,MAAM;MAAEC,YAAY,EAAEC,IAAhB;MAAsBC;IAAtB,IAAiCJ,MAAvC;IACA;AACR;AACA;;IACQ,IAAI,CAACG,IAAD,IAAS,CAACC,MAAd,EAAsB;MAClB,OAAO,IAAP;IACH,CAFD,MAEO,IAAI,CAACD,IAAL,EAAW;MACd,MAAM,IAAIE,cAAJ,CACD,gEADC,EAEF,yBAFE,kCAIKL,MAJL,EAAN;IAOH,CARM,MAQA,IAAI,CAACI,MAAL,EAAa;MAChB,MAAM,IAAIC,cAAJ,CACD,gEADC,EAEF,uBAFE,kCAIKL,MAJL,EAAN;IAOH;;IAED,OAAO;MACHG,IADG;MAEHC;IAFG,CAAP;EAIH,CA7BM,CAAP;AA8BH,CA/BM"}
|
package/parameters/path.js
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.CmsGraphQLSchemaPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
13
|
+
|
|
14
|
+
class CmsGraphQLSchemaPlugin extends _handlerGraphql.GraphQLSchemaPlugin {}
|
|
15
|
+
|
|
16
|
+
exports.CmsGraphQLSchemaPlugin = CmsGraphQLSchemaPlugin;
|
|
17
|
+
(0, _defineProperty2.default)(CmsGraphQLSchemaPlugin, "type", "cms.graphql.schema");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["CmsGraphQLSchemaPlugin","GraphQLSchemaPlugin"],"sources":["CmsGraphQLSchemaPlugin.ts"],"sourcesContent":["import { GraphQLSchemaPlugin } from \"@webiny/handler-graphql\";\nimport { CmsContext } from \"~/types\";\n\nexport class CmsGraphQLSchemaPlugin<T = CmsContext> extends GraphQLSchemaPlugin<T> {\n public static override type = \"cms.graphql.schema\";\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAGO,MAAMA,sBAAN,SAAqDC,mCAArD,CAA4E;;;8BAAtED,sB,UACqB,oB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
import { CmsModel } from "../types";
|
|
3
|
+
interface CmsGraphQLSchemaSorterPluginCallableParams {
|
|
4
|
+
model: CmsModel;
|
|
5
|
+
sorters: string[];
|
|
6
|
+
}
|
|
7
|
+
interface CmsGraphQLSchemaSorterPluginCallable {
|
|
8
|
+
(params: CmsGraphQLSchemaSorterPluginCallableParams): string[];
|
|
9
|
+
}
|
|
10
|
+
export declare class CmsGraphQLSchemaSorterPlugin extends Plugin {
|
|
11
|
+
static readonly type: string;
|
|
12
|
+
private readonly cb;
|
|
13
|
+
constructor(cb: CmsGraphQLSchemaSorterPluginCallable);
|
|
14
|
+
/**
|
|
15
|
+
* Method must return new sorting array. Or existing one if no changes are made.
|
|
16
|
+
*/
|
|
17
|
+
createSorter(params: CmsGraphQLSchemaSorterPluginCallableParams): string[];
|
|
18
|
+
}
|
|
19
|
+
export declare const createCmsGraphQLSchemaSorterPlugin: (cb: CmsGraphQLSchemaSorterPluginCallable) => CmsGraphQLSchemaSorterPlugin;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createCmsGraphQLSchemaSorterPlugin = exports.CmsGraphQLSchemaSorterPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _plugins = require("@webiny/plugins");
|
|
13
|
+
|
|
14
|
+
class CmsGraphQLSchemaSorterPlugin extends _plugins.Plugin {
|
|
15
|
+
constructor(cb) {
|
|
16
|
+
super();
|
|
17
|
+
(0, _defineProperty2.default)(this, "cb", void 0);
|
|
18
|
+
this.cb = cb;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Method must return new sorting array. Or existing one if no changes are made.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
createSorter(params) {
|
|
26
|
+
return this.cb(params);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
exports.CmsGraphQLSchemaSorterPlugin = CmsGraphQLSchemaSorterPlugin;
|
|
32
|
+
(0, _defineProperty2.default)(CmsGraphQLSchemaSorterPlugin, "type", "cms.graphql.schema.sorter");
|
|
33
|
+
|
|
34
|
+
const createCmsGraphQLSchemaSorterPlugin = cb => {
|
|
35
|
+
return new CmsGraphQLSchemaSorterPlugin(cb);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.createCmsGraphQLSchemaSorterPlugin = createCmsGraphQLSchemaSorterPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["CmsGraphQLSchemaSorterPlugin","Plugin","constructor","cb","createSorter","params","createCmsGraphQLSchemaSorterPlugin"],"sources":["CmsGraphQLSchemaSorterPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { CmsModel } from \"~/types\";\n\ninterface CmsGraphQLSchemaSorterPluginCallableParams {\n model: CmsModel;\n sorters: string[];\n}\ninterface CmsGraphQLSchemaSorterPluginCallable {\n (params: CmsGraphQLSchemaSorterPluginCallableParams): string[];\n}\nexport class CmsGraphQLSchemaSorterPlugin extends Plugin {\n public static override readonly type: string = \"cms.graphql.schema.sorter\";\n\n private readonly cb: CmsGraphQLSchemaSorterPluginCallable;\n public constructor(cb: CmsGraphQLSchemaSorterPluginCallable) {\n super();\n\n this.cb = cb;\n }\n /**\n * Method must return new sorting array. Or existing one if no changes are made.\n */\n public createSorter(params: CmsGraphQLSchemaSorterPluginCallableParams): string[] {\n return this.cb(params);\n }\n}\n\nexport const createCmsGraphQLSchemaSorterPlugin = (\n cb: CmsGraphQLSchemaSorterPluginCallable\n): CmsGraphQLSchemaSorterPlugin => {\n return new CmsGraphQLSchemaSorterPlugin(cb);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAUO,MAAMA,4BAAN,SAA2CC,eAA3C,CAAkD;EAI9CC,WAAW,CAACC,EAAD,EAA2C;IACzD;IADyD;IAGzD,KAAKA,EAAL,GAAUA,EAAV;EACH;EACD;AACJ;AACA;;;EACWC,YAAY,CAACC,MAAD,EAA+D;IAC9E,OAAO,KAAKF,EAAL,CAAQE,MAAR,CAAP;EACH;;AAdoD;;;8BAA5CL,4B,UACsC,2B;;AAgB5C,MAAMM,kCAAkC,GAC3CH,EAD8C,IAEf;EAC/B,OAAO,IAAIH,4BAAJ,CAAiCG,EAAjC,CAAP;AACH,CAJM"}
|