@webiny/api-headless-cms 0.0.0-unstable.6e5425ee89 → 0.0.0-unstable.7f63ea0744
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 +53 -4
- package/context.js.map +1 -1
- package/crud/contentEntry/markLockedFields.js +4 -2
- package/crud/contentEntry/markLockedFields.js.map +1 -1
- package/crud/contentEntry/referenceFieldsMapping.js +7 -5
- package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
- package/crud/contentEntry/searchableFields.d.ts +9 -0
- package/crud/contentEntry/searchableFields.js +72 -0
- package/crud/contentEntry/searchableFields.js.map +1 -0
- package/crud/contentEntry.crud.js +99 -42
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/beforeCreate.d.ts +2 -3
- package/crud/contentModel/beforeCreate.js +4 -5
- package/crud/contentModel/beforeCreate.js.map +1 -1
- package/crud/contentModel/beforeUpdate.d.ts +2 -4
- package/crud/contentModel/beforeUpdate.js +2 -2
- package/crud/contentModel/beforeUpdate.js.map +1 -1
- package/crud/contentModel/createFieldStorageId.js +4 -1
- package/crud/contentModel/createFieldStorageId.js.map +1 -1
- package/crud/contentModel/validateModel.d.ts +3 -4
- package/crud/contentModel/validateModel.js +6 -3
- package/crud/contentModel/validateModel.js.map +1 -1
- package/crud/contentModel/validateModelFields.d.ts +3 -4
- package/crud/contentModel/validateModelFields.js +100 -38
- package/crud/contentModel/validateModelFields.js.map +1 -1
- package/crud/contentModel/validation.d.ts +477 -0
- package/crud/contentModel/validation.js +97 -0
- package/crud/contentModel/validation.js.map +1 -0
- package/crud/contentModel.crud.js +212 -177
- package/crud/contentModel.crud.js.map +1 -1
- package/crud/contentModelGroup/validation.d.ts +30 -0
- package/crud/contentModelGroup/validation.js +34 -0
- package/crud/contentModelGroup/validation.js.map +1 -0
- package/crud/contentModelGroup.crud.js +47 -52
- package/crud/contentModelGroup.crud.js.map +1 -1
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.d.ts +11 -0
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +203 -0
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -0
- package/fieldConverters/index.d.ts +2 -1
- package/fieldConverters/index.js +2 -1
- package/fieldConverters/index.js.map +1 -1
- package/graphql/buildSchemaPlugins.d.ts +8 -3
- package/graphql/buildSchemaPlugins.js +3 -7
- package/graphql/buildSchemaPlugins.js.map +1 -1
- package/graphql/createExecutableSchema.d.ts +7 -0
- package/graphql/createExecutableSchema.js +29 -0
- package/graphql/createExecutableSchema.js.map +1 -0
- package/graphql/generateSchema.d.ts +8 -0
- package/graphql/generateSchema.js +31 -0
- package/graphql/generateSchema.js.map +1 -0
- package/graphql/graphQLHandlerFactory.js +91 -50
- package/graphql/graphQLHandlerFactory.js.map +1 -1
- package/graphql/index.d.ts +1 -3
- package/graphql/index.js +2 -39
- package/graphql/index.js.map +1 -1
- package/graphql/schema/baseContentSchema.d.ts +6 -2
- package/graphql/schema/baseContentSchema.js +6 -4
- package/graphql/schema/baseContentSchema.js.map +1 -1
- package/graphql/schema/baseSchema.d.ts +3 -0
- package/graphql/schema/baseSchema.js +53 -0
- package/graphql/schema/baseSchema.js.map +1 -0
- package/graphql/schema/contentEntries.d.ts +6 -2
- package/graphql/schema/contentEntries.js +37 -23
- package/graphql/schema/contentEntries.js.map +1 -1
- package/graphql/schema/contentModelGroups.d.ts +6 -2
- package/graphql/schema/contentModelGroups.js +7 -3
- package/graphql/schema/contentModelGroups.js.map +1 -1
- package/graphql/schema/contentModels.d.ts +6 -2
- package/graphql/schema/contentModels.js +40 -7
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createFieldResolvers.d.ts +1 -1
- package/graphql/schema/createFieldResolvers.js +17 -6
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.d.ts +2 -0
- package/graphql/schema/createManageSDL.js +10 -6
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/createReadResolvers.js +5 -0
- 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/schemaPlugins.d.ts +8 -3
- package/graphql/schema/schemaPlugins.js +58 -46
- package/graphql/schema/schemaPlugins.js.map +1 -1
- package/graphql/system.js +69 -72
- package/graphql/system.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +2 -0
- package/graphqlFields/dynamicZone/dynamicZoneField.js +208 -0
- package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.d.ts +3 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js +63 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js.map +1 -0
- package/graphqlFields/dynamicZone/index.d.ts +2 -0
- package/graphqlFields/dynamicZone/index.js +19 -0
- package/graphqlFields/dynamicZone/index.js.map +1 -0
- package/graphqlFields/index.d.ts +1 -1
- package/graphqlFields/index.js +2 -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 +112 -68
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +31 -45
- package/graphqlFields/ref.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +3 -7
- package/index.js.map +1 -1
- package/package.json +28 -28
- package/plugins/CmsGraphQLSchemaPlugin.d.ts +5 -0
- package/plugins/CmsGraphQLSchemaPlugin.js +12 -0
- package/plugins/CmsGraphQLSchemaPlugin.js.map +1 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.d.ts +20 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.js +28 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.js.map +1 -0
- package/plugins/CmsModelFieldConverterPlugin.d.ts +2 -2
- package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
- package/plugins/StorageTransformPlugin.d.ts +11 -11
- package/plugins/StorageTransformPlugin.js.map +1 -1
- package/plugins/index.d.ts +2 -0
- package/plugins/index.js +22 -0
- package/plugins/index.js.map +1 -1
- package/storage/object.js +4 -2
- package/storage/object.js.map +1 -1
- package/types.d.ts +241 -57
- package/types.js +62 -7
- package/types.js.map +1 -1
- package/utils/converters/ConverterCollection.js +5 -2
- package/utils/converters/ConverterCollection.js.map +1 -1
- package/utils/createTypeFromFields.d.ts +15 -0
- package/utils/createTypeFromFields.js +64 -0
- package/utils/createTypeFromFields.js.map +1 -0
- package/utils/createTypeName.js +2 -1
- package/utils/createTypeName.js.map +1 -1
- package/utils/entryStorage.js +14 -11
- package/utils/entryStorage.js.map +1 -1
- package/utils/getBaseFieldType.d.ts +4 -0
- package/utils/getBaseFieldType.js +10 -0
- package/utils/getBaseFieldType.js.map +1 -0
- package/utils/getSchemaFromFieldPlugins.d.ts +4 -7
- package/utils/getSchemaFromFieldPlugins.js +22 -14
- package/utils/getSchemaFromFieldPlugins.js.map +1 -1
- package/utils/renderFields.js +2 -1
- package/utils/renderFields.js.map +1 -1
- package/utils/renderGetFilterFields.js +6 -3
- package/utils/renderGetFilterFields.js.map +1 -1
- package/utils/renderInputFields.js +2 -1
- package/utils/renderInputFields.js.map +1 -1
- package/utils/renderListFilterFields.js +4 -2
- package/utils/renderListFilterFields.js.map +1 -1
- package/utils/renderSortEnum.d.ts +7 -4
- package/utils/renderSortEnum.js +21 -4
- package/utils/renderSortEnum.js.map +1 -1
- package/validators/dynamicZone.d.ts +2 -0
- package/validators/dynamicZone.js +20 -0
- package/validators/dynamicZone.js.map +1 -0
- package/validators/index.js +2 -1
- package/validators/index.js.map +1 -1
- package/crud/contentModel/createFieldModels.d.ts +0 -2
- package/crud/contentModel/createFieldModels.js +0 -20
- package/crud/contentModel/createFieldModels.js.map +0 -1
- package/crud/contentModel/fieldIdValidation.d.ts +0 -1
- package/crud/contentModel/fieldIdValidation.js +0 -20
- package/crud/contentModel/fieldIdValidation.js.map +0 -1
- package/crud/contentModel/idValidation.d.ts +0 -1
- package/crud/contentModel/idValidation.js +0 -17
- package/crud/contentModel/idValidation.js.map +0 -1
- package/crud/contentModel/models.d.ts +0 -4
- package/crud/contentModel/models.js +0 -173
- package/crud/contentModel/models.js.map +0 -1
- package/crud/index.d.ts +0 -6
- package/crud/index.js +0 -69
- 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/utils/filterModelFields.d.ts +0 -16
- package/utils/filterModelFields.js +0 -71
- package/utils/filterModelFields.js.map +0 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createTypeFromFields = void 0;
|
|
7
|
+
var _createTypeName = require("./createTypeName");
|
|
8
|
+
var _renderFields = require("./renderFields");
|
|
9
|
+
var _renderInputFields = require("./renderInputFields");
|
|
10
|
+
const createTypeFromFields = params => {
|
|
11
|
+
const {
|
|
12
|
+
typeOfType,
|
|
13
|
+
model,
|
|
14
|
+
type,
|
|
15
|
+
typeNamePrefix,
|
|
16
|
+
fields,
|
|
17
|
+
fieldTypePlugins
|
|
18
|
+
} = params;
|
|
19
|
+
const typeSuffix = typeOfType === "input" ? "Input" : "";
|
|
20
|
+
const mTypeName = (0, _createTypeName.createTypeName)(model.modelId);
|
|
21
|
+
const typeFields = [];
|
|
22
|
+
const nestedTypes = [];
|
|
23
|
+
|
|
24
|
+
// Once the loop below starts, we'll be executing a recursive "object" type generation.
|
|
25
|
+
// The main trick here is that nested objects don't know who the parent is, and will generate
|
|
26
|
+
// type names using the "model", as if they're at the top level:
|
|
27
|
+
// Every time the types are returned, we need to replace the model name in the generated type name
|
|
28
|
+
// with the actual prefix which includes parent field name type.
|
|
29
|
+
const replace = new RegExp(`${mTypeName}_`, "g");
|
|
30
|
+
for (const f of fields) {
|
|
31
|
+
const result = typeOfType === "type" ? (0, _renderFields.renderField)({
|
|
32
|
+
field: f,
|
|
33
|
+
type,
|
|
34
|
+
model,
|
|
35
|
+
fieldTypePlugins
|
|
36
|
+
}) : (0, _renderInputFields.renderInputField)({
|
|
37
|
+
field: f,
|
|
38
|
+
model,
|
|
39
|
+
fieldTypePlugins
|
|
40
|
+
});
|
|
41
|
+
if (!result) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const {
|
|
45
|
+
fields,
|
|
46
|
+
typeDefs
|
|
47
|
+
} = result;
|
|
48
|
+
typeFields.push(fields.replace(replace, `${typeNamePrefix}_`));
|
|
49
|
+
if (typeDefs) {
|
|
50
|
+
nestedTypes.push(typeDefs.replace(replace, `${typeNamePrefix}_`));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
fieldType: `${typeNamePrefix}${typeSuffix}`,
|
|
55
|
+
typeDefs: /* GraphQL */`
|
|
56
|
+
${nestedTypes.join("\n")}
|
|
57
|
+
|
|
58
|
+
${typeOfType} ${typeNamePrefix}${typeSuffix} {
|
|
59
|
+
${typeFields.join("\n")}
|
|
60
|
+
}
|
|
61
|
+
`
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
exports.createTypeFromFields = createTypeFromFields;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createTypeFromFields","params","typeOfType","model","type","typeNamePrefix","fields","fieldTypePlugins","typeSuffix","mTypeName","createTypeName","modelId","typeFields","nestedTypes","replace","RegExp","f","result","renderField","field","renderInputField","typeDefs","push","fieldType","join"],"sources":["createTypeFromFields.ts"],"sourcesContent":["import { createTypeName } from \"~/utils/createTypeName\";\nimport { renderField } from \"~/utils/renderFields\";\nimport { renderInputField } from \"~/utils/renderInputFields\";\nimport { ApiEndpoint, CmsFieldTypePlugins, CmsModel, CmsModelField } from \"~/types\";\n\ninterface TypeFromFieldParams {\n typeOfType: \"type\" | \"input\";\n model: CmsModel;\n type: ApiEndpoint;\n typeNamePrefix: string;\n fields: CmsModelField[];\n fieldTypePlugins: CmsFieldTypePlugins;\n}\n\ninterface TypeFromFieldResponse {\n fieldType: string;\n typeDefs: string;\n}\n\nexport const createTypeFromFields = (params: TypeFromFieldParams): TypeFromFieldResponse | null => {\n const { typeOfType, model, type, typeNamePrefix, fields, fieldTypePlugins } = params;\n const typeSuffix = typeOfType === \"input\" ? \"Input\" : \"\";\n const mTypeName = createTypeName(model.modelId);\n\n const typeFields = [];\n const nestedTypes = [];\n\n // Once the loop below starts, we'll be executing a recursive \"object\" type generation.\n // The main trick here is that nested objects don't know who the parent is, and will generate\n // type names using the \"model\", as if they're at the top level:\n // Every time the types are returned, we need to replace the model name in the generated type name\n // with the actual prefix which includes parent field name type.\n const replace = new RegExp(`${mTypeName}_`, \"g\");\n\n for (const f of fields) {\n const result =\n typeOfType === \"type\"\n ? renderField({ field: f, type, model, fieldTypePlugins })\n : renderInputField({ field: f, model, fieldTypePlugins });\n\n if (!result) {\n continue;\n }\n\n const { fields, typeDefs } = result;\n\n typeFields.push(fields.replace(replace, `${typeNamePrefix}_`));\n if (typeDefs) {\n nestedTypes.push(typeDefs.replace(replace, `${typeNamePrefix}_`));\n }\n }\n\n return {\n fieldType: `${typeNamePrefix}${typeSuffix}`,\n typeDefs: /* GraphQL */ `\n ${nestedTypes.join(\"\\n\")}\n\n ${typeOfType} ${typeNamePrefix}${typeSuffix} {\n ${typeFields.join(\"\\n\")}\n }\n `\n };\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;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,CAAE;AACrC;AACA,cAActB,UAAW,IAAGG,cAAe,GAAEG,UAAW;AACxD,kBAAkBI,UAAU,CAACY,IAAI,CAAC,IAAI,CAAE;AACxC;AACA;EACI,CAAC;AACL,CAAC;AAAC"}
|
package/utils/createTypeName.js
CHANGED
|
@@ -6,8 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.createTypeName = exports.createReadTypeName = exports.createManageTypeName = void 0;
|
|
8
8
|
var _upperFirst = _interopRequireDefault(require("lodash/upperFirst"));
|
|
9
|
+
var _camelCase = _interopRequireDefault(require("lodash/camelCase"));
|
|
9
10
|
const createTypeName = modelId => {
|
|
10
|
-
return (0, _upperFirst.default)(modelId);
|
|
11
|
+
return (0, _upperFirst.default)((0, _camelCase.default)(modelId));
|
|
11
12
|
};
|
|
12
13
|
exports.createTypeName = createTypeName;
|
|
13
14
|
const createReadTypeName = baseTypeName => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createTypeName","modelId","upperFirst","createReadTypeName","baseTypeName","createManageTypeName"],"sources":["createTypeName.ts"],"sourcesContent":["import upperFirst from \"lodash/upperFirst\";\n\nexport const createTypeName = (modelId: string): string => {\n return upperFirst(modelId);\n};\n\nexport const createReadTypeName = (baseTypeName: string): string => {\n return createTypeName(baseTypeName);\n};\n\nexport const createManageTypeName = (baseTypeName: string): string => {\n return createTypeName(baseTypeName);\n};\n"],"mappings":";;;;;;;AAAA;AAEO,MAAMA,cAAc,GAAIC,OAAe,IAAa;EACvD,OAAO,IAAAC,mBAAU,
|
|
1
|
+
{"version":3,"names":["createTypeName","modelId","upperFirst","camelCase","createReadTypeName","baseTypeName","createManageTypeName"],"sources":["createTypeName.ts"],"sourcesContent":["import upperFirst from \"lodash/upperFirst\";\nimport camelCase from \"lodash/camelCase\";\n\nexport const createTypeName = (modelId: string): string => {\n return upperFirst(camelCase(modelId));\n};\n\nexport const createReadTypeName = (baseTypeName: string): string => {\n return createTypeName(baseTypeName);\n};\n\nexport const createManageTypeName = (baseTypeName: string): string => {\n return createTypeName(baseTypeName);\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAEO,MAAMA,cAAc,GAAIC,OAAe,IAAa;EACvD,OAAO,IAAAC,mBAAU,EAAC,IAAAC,kBAAS,EAACF,OAAO,CAAC,CAAC;AACzC,CAAC;AAAC;AAEK,MAAMG,kBAAkB,GAAIC,YAAoB,IAAa;EAChE,OAAOL,cAAc,CAACK,YAAY,CAAC;AACvC,CAAC;AAAC;AAEK,MAAMC,oBAAoB,GAAID,YAAoB,IAAa;EAClE,OAAOL,cAAc,CAACK,YAAY,CAAC;AACvC,CAAC;AAAC"}
|
package/utils/entryStorage.js
CHANGED
|
@@ -8,24 +8,25 @@ exports.entryToStorageTransform = exports.entryFromStorageTransform = exports.en
|
|
|
8
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
10
10
|
var _StorageTransformPlugin = require("../plugins/StorageTransformPlugin");
|
|
11
|
+
var _getBaseFieldType = require("./getBaseFieldType");
|
|
11
12
|
const getStoragePluginFactory = context => {
|
|
12
13
|
let defaultStoragePlugin;
|
|
13
14
|
const plugins = context.plugins.byType(_StorageTransformPlugin.StorageTransformPlugin.type)
|
|
14
15
|
// we reverse plugins because we want to get latest added only
|
|
15
16
|
.reverse().reduce((collection, plugin) => {
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Check if it's a default plugin and set it - always override the previous one.
|
|
19
|
+
*/
|
|
20
|
+
if (plugin.fieldType === "*") {
|
|
18
21
|
defaultStoragePlugin = plugin;
|
|
19
22
|
return collection;
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
26
|
+
* We will just set the plugin for given type.
|
|
27
|
+
* The last one will override existing one - so users can override our default ones.
|
|
25
28
|
*/
|
|
26
|
-
|
|
27
|
-
collection[plugin.fieldType] = plugin;
|
|
28
|
-
}
|
|
29
|
+
collection[plugin.fieldType] = plugin;
|
|
29
30
|
return collection;
|
|
30
31
|
}, {});
|
|
31
32
|
return fieldType => {
|
|
@@ -40,10 +41,11 @@ const entryStorageTransform = async (context, model, operation, entry) => {
|
|
|
40
41
|
const getStoragePlugin = getStoragePluginFactory(context);
|
|
41
42
|
const transformedValues = {};
|
|
42
43
|
for (const field of model.fields) {
|
|
43
|
-
const
|
|
44
|
+
const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
|
|
45
|
+
const plugin = getStoragePlugin(baseType);
|
|
44
46
|
// TODO: remove this once plugins are converted into classes
|
|
45
47
|
if (typeof plugin[operation] !== "function") {
|
|
46
|
-
throw new _error.default(`Missing "${operation}" function in storage plugin "${plugin.name}" for field type "${
|
|
48
|
+
throw new _error.default(`Missing "${operation}" function in storage plugin "${plugin.name}" for field type "${baseType}"`);
|
|
47
49
|
}
|
|
48
50
|
transformedValues[field.fieldId] = await plugin[operation]({
|
|
49
51
|
plugins: context.plugins,
|
|
@@ -84,11 +86,12 @@ const entryFieldFromStorageTransform = async params => {
|
|
|
84
86
|
value
|
|
85
87
|
} = params;
|
|
86
88
|
const getStoragePlugin = getStoragePluginFactory(context);
|
|
87
|
-
const
|
|
89
|
+
const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
|
|
90
|
+
const plugin = getStoragePlugin(baseType);
|
|
88
91
|
|
|
89
92
|
// TODO: remove this once plugins are converted into classes
|
|
90
93
|
if (typeof plugin.fromStorage !== "function") {
|
|
91
|
-
throw new _error.default(`Missing "fromStorage" function in storage plugin "${plugin.name}" for field type "${
|
|
94
|
+
throw new _error.default(`Missing "fromStorage" function in storage plugin "${plugin.name}" for field type "${baseType}"`);
|
|
92
95
|
}
|
|
93
96
|
return plugin.fromStorage({
|
|
94
97
|
plugins: context.plugins,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getStoragePluginFactory","context","defaultStoragePlugin","plugins","byType","StorageTransformPlugin","type","reverse","reduce","collection","plugin","fieldType","entryStorageTransform","model","operation","entry","getStoragePlugin","transformedValues","field","fields","WebinyError","name","fieldId","value","values","entryToStorageTransform","entryFromStorageTransform","entryFieldFromStorageTransform","params","fromStorage"],"sources":["entryStorage.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { StorageTransformPlugin } from \"~/plugins/StorageTransformPlugin\";\nimport { CmsEntry, CmsModel, CmsModelField, CmsContext } from \"~/types\";\n\ninterface GetStoragePluginFactory {\n (context: CmsContext): (fieldType: string) => StorageTransformPlugin<any>;\n}\n\nconst getStoragePluginFactory: GetStoragePluginFactory = context => {\n let defaultStoragePlugin: StorageTransformPlugin;\n\n const plugins = context.plugins\n .byType<StorageTransformPlugin>(StorageTransformPlugin.type)\n // we reverse plugins because we want to get latest added only\n .reverse()\n .reduce((collection, plugin) => {\n
|
|
1
|
+
{"version":3,"names":["getStoragePluginFactory","context","defaultStoragePlugin","plugins","byType","StorageTransformPlugin","type","reverse","reduce","collection","plugin","fieldType","entryStorageTransform","model","operation","entry","getStoragePlugin","transformedValues","field","fields","baseType","getBaseFieldType","WebinyError","name","fieldId","value","values","entryToStorageTransform","entryFromStorageTransform","entryFieldFromStorageTransform","params","fromStorage"],"sources":["entryStorage.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { StorageTransformPlugin } from \"~/plugins/StorageTransformPlugin\";\nimport { CmsEntry, CmsModel, CmsModelField, CmsContext } from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\n\ninterface GetStoragePluginFactory {\n (context: CmsContext): (fieldType: string) => StorageTransformPlugin<any>;\n}\n\nconst getStoragePluginFactory: GetStoragePluginFactory = context => {\n let defaultStoragePlugin: StorageTransformPlugin;\n\n const plugins = context.plugins\n .byType<StorageTransformPlugin>(StorageTransformPlugin.type)\n // we reverse plugins because we want to get latest added only\n .reverse()\n .reduce((collection, plugin) => {\n /**\n * Check if it's a default plugin and set it - always override the previous one.\n */\n if (plugin.fieldType === \"*\") {\n defaultStoragePlugin = plugin;\n return collection;\n }\n\n /**\n * We will just set the plugin for given type.\n * The last one will override existing one - so users can override our default ones.\n */\n collection[plugin.fieldType] = plugin;\n\n return collection;\n }, {} as Record<string, StorageTransformPlugin>);\n\n return (fieldType: string) => {\n return plugins[fieldType] || defaultStoragePlugin;\n };\n};\n\n/**\n * This should be used when transforming the whole entry.\n */\nconst entryStorageTransform = async (\n context: CmsContext,\n model: CmsModel,\n operation: \"toStorage\" | \"fromStorage\",\n entry: CmsEntry\n): Promise<CmsEntry> => {\n const getStoragePlugin = getStoragePluginFactory(context);\n\n const transformedValues: Record<string, any> = {};\n for (const field of model.fields) {\n const baseType = getBaseFieldType(field);\n const plugin = getStoragePlugin(baseType);\n // TODO: remove this once plugins are converted into classes\n if (typeof plugin[operation] !== \"function\") {\n throw new WebinyError(\n `Missing \"${operation}\" function in storage plugin \"${plugin.name}\" for field type \"${baseType}\"`\n );\n }\n\n transformedValues[field.fieldId] = await plugin[operation]({\n plugins: context.plugins,\n model,\n field,\n value: entry.values[field.fieldId],\n getStoragePlugin\n });\n }\n\n return { ...entry, values: transformedValues };\n};\n\n/**\n * A function that is used in crud to transform entry into the storage type.\n */\nexport const entryToStorageTransform = async (\n context: CmsContext,\n model: CmsModel,\n entry: CmsEntry\n): Promise<CmsEntry> => {\n return entryStorageTransform(context, model, \"toStorage\", entry);\n};\n\n/**\n * A function that is used to transform the whole entry from storage into its native form.\n */\nexport const entryFromStorageTransform = async (\n context: CmsContext,\n model: CmsModel,\n entry: CmsEntry\n): Promise<CmsEntry> => {\n return entryStorageTransform(context, model, \"fromStorage\", entry);\n};\n\ninterface EntryFieldFromStorageTransformParams {\n context: CmsContext;\n model: CmsModel;\n field: CmsModelField;\n value: any;\n}\n/*\n * A function that is used to transform a single field from storage\n */\nexport const entryFieldFromStorageTransform = async <T = any>(\n params: EntryFieldFromStorageTransformParams\n): Promise<T> => {\n const { context, model, field, value } = params;\n const getStoragePlugin = getStoragePluginFactory(context);\n\n const baseType = getBaseFieldType(field);\n const plugin = getStoragePlugin(baseType);\n\n // TODO: remove this once plugins are converted into classes\n if (typeof plugin.fromStorage !== \"function\") {\n throw new WebinyError(\n `Missing \"fromStorage\" function in storage plugin \"${plugin.name}\" for field type \"${baseType}\"`\n );\n }\n\n return plugin.fromStorage({\n plugins: context.plugins,\n model,\n field,\n value,\n getStoragePlugin\n });\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AAEA;AAMA,MAAMA,uBAAgD,GAAGC,OAAO,IAAI;EAChE,IAAIC,oBAA4C;EAEhD,MAAMC,OAAO,GAAGF,OAAO,CAACE,OAAO,CAC1BC,MAAM,CAAyBC,8CAAsB,CAACC,IAAI;EAC3D;EAAA,CACCC,OAAO,EAAE,CACTC,MAAM,CAAC,CAACC,UAAU,EAAEC,MAAM,KAAK;IAC5B;AACZ;AACA;IACY,IAAIA,MAAM,CAACC,SAAS,KAAK,GAAG,EAAE;MAC1BT,oBAAoB,GAAGQ,MAAM;MAC7B,OAAOD,UAAU;IACrB;;IAEA;AACZ;AACA;AACA;IACYA,UAAU,CAACC,MAAM,CAACC,SAAS,CAAC,GAAGD,MAAM;IAErC,OAAOD,UAAU;EACrB,CAAC,EAAE,CAAC,CAAC,CAA2C;EAEpD,OAAQE,SAAiB,IAAK;IAC1B,OAAOR,OAAO,CAACQ,SAAS,CAAC,IAAIT,oBAAoB;EACrD,CAAC;AACL,CAAC;;AAED;AACA;AACA;AACA,MAAMU,qBAAqB,GAAG,OAC1BX,OAAmB,EACnBY,KAAe,EACfC,SAAsC,EACtCC,KAAe,KACK;EACpB,MAAMC,gBAAgB,GAAGhB,uBAAuB,CAACC,OAAO,CAAC;EAEzD,MAAMgB,iBAAsC,GAAG,CAAC,CAAC;EACjD,KAAK,MAAMC,KAAK,IAAIL,KAAK,CAACM,MAAM,EAAE;IAC9B,MAAMC,QAAQ,GAAG,IAAAC,kCAAgB,EAACH,KA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,CAAC;;EAEzC;EACA,IAAI,OAAOV,MAAM,CAACqB,WAAW,KAAK,UAAU,EAAE;IAC1C,MAAM,IAAIT,cAAW,CAChB,qDAAoDZ,MAAM,CAACa,IAAK,qBAAoBH,QAAS,GAAE,CACnG;EACL;EAEA,OAAOV,MAAM,CAACqB,WAAW,CAAC;IACtB5B,OAAO,EAAEF,OAAO,CAACE,OAAO;IACxBU,KAAK;IACLK,KAAK;IACLO,KAAK;IACLT;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getBaseFieldType","field","type","split"],"sources":["getBaseFieldType.ts"],"sourcesContent":["import { CmsModelField } from \"~/types\";\n\nexport const getBaseFieldType = (field: { type: CmsModelField[\"type\"] }) => {\n return field.type.split(\":\")[0];\n};\n"],"mappings":";;;;;;AAEO,MAAMA,gBAAgB,GAAIC,KAAsC,IAAK;EACxE,OAAOA,KAAK,CAACC,IAAI,CAACC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACnC,CAAC;AAAC"}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { CmsModel,
|
|
2
|
-
import {
|
|
3
|
-
interface
|
|
1
|
+
import { CmsModel, CmsFieldTypePlugins, ApiEndpoint } from "../types";
|
|
2
|
+
import { CmsGraphQLSchemaPlugin } from "../plugins";
|
|
3
|
+
interface Params {
|
|
4
4
|
models: CmsModel[];
|
|
5
5
|
fieldTypePlugins: CmsFieldTypePlugins;
|
|
6
6
|
type: ApiEndpoint;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
(params: RenderTypesFromFieldPluginsParams): GraphQLSchemaDefinition<CmsContext>[];
|
|
10
|
-
}
|
|
11
|
-
export declare const getSchemaFromFieldPlugins: RenderTypesFromFieldPlugins;
|
|
8
|
+
export declare const createGraphQLSchemaPluginFromFieldPlugins: (params: Params) => CmsGraphQLSchemaPlugin<import("../types").CmsContext>[];
|
|
12
9
|
export {};
|
|
@@ -3,29 +3,37 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.createGraphQLSchemaPluginFromFieldPlugins = void 0;
|
|
7
|
+
var _plugins = require("../plugins");
|
|
7
8
|
const TYPE_MAP = {
|
|
8
9
|
preview: "read",
|
|
9
10
|
read: "read",
|
|
10
11
|
manage: "manage"
|
|
11
12
|
};
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
const createGraphQLSchemaPluginFromFieldPlugins = params => {
|
|
14
|
+
const {
|
|
15
|
+
models,
|
|
16
|
+
fieldTypePlugins,
|
|
17
|
+
type
|
|
18
|
+
} = params;
|
|
19
|
+
const plugins = [];
|
|
20
|
+
for (const key in fieldTypePlugins) {
|
|
21
|
+
const fieldTypePlugin = fieldTypePlugins[key];
|
|
22
|
+
if (!TYPE_MAP[type] || !fieldTypePlugin[TYPE_MAP[type]]) {
|
|
23
|
+
continue;
|
|
20
24
|
}
|
|
21
|
-
const createSchema =
|
|
25
|
+
const createSchema = fieldTypePlugin[TYPE_MAP[type]].createSchema;
|
|
22
26
|
// Render gql types generated by field type plugins
|
|
23
27
|
if (!createSchema) {
|
|
24
|
-
|
|
28
|
+
continue;
|
|
25
29
|
}
|
|
26
|
-
|
|
30
|
+
const schema = createSchema({
|
|
27
31
|
models
|
|
28
32
|
});
|
|
29
|
-
|
|
33
|
+
const plugin = new _plugins.CmsGraphQLSchemaPlugin(schema);
|
|
34
|
+
plugin.name = `headless-cms.graphql.schema.${type}.field.${fieldTypePlugin.fieldType}`;
|
|
35
|
+
plugins.push(plugin);
|
|
36
|
+
}
|
|
37
|
+
return plugins;
|
|
30
38
|
};
|
|
31
|
-
exports.
|
|
39
|
+
exports.createGraphQLSchemaPluginFromFieldPlugins = createGraphQLSchemaPluginFromFieldPlugins;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TYPE_MAP","preview","read","manage","
|
|
1
|
+
{"version":3,"names":["TYPE_MAP","preview","read","manage","createGraphQLSchemaPluginFromFieldPlugins","params","models","fieldTypePlugins","type","plugins","key","fieldTypePlugin","createSchema","schema","plugin","CmsGraphQLSchemaPlugin","name","fieldType","push"],"sources":["getSchemaFromFieldPlugins.ts"],"sourcesContent":["import { CmsModel, CmsFieldTypePlugins, ApiEndpoint } from \"~/types\";\nimport { CmsGraphQLSchemaPlugin } from \"~/plugins\";\n\nconst TYPE_MAP: Record<string, \"manage\" | \"read\"> = {\n preview: \"read\",\n read: \"read\",\n manage: \"manage\"\n};\n\ninterface Params {\n models: CmsModel[];\n fieldTypePlugins: CmsFieldTypePlugins;\n type: ApiEndpoint;\n}\nexport const createGraphQLSchemaPluginFromFieldPlugins = (params: Params) => {\n const { models, fieldTypePlugins, type } = params;\n\n const plugins: CmsGraphQLSchemaPlugin[] = [];\n for (const key in fieldTypePlugins) {\n const fieldTypePlugin = fieldTypePlugins[key];\n if (!TYPE_MAP[type] || !fieldTypePlugin[TYPE_MAP[type]]) {\n continue;\n }\n const createSchema = fieldTypePlugin[TYPE_MAP[type]].createSchema;\n // Render gql types generated by field type plugins\n if (!createSchema) {\n continue;\n }\n const schema = createSchema({ models });\n\n const plugin = new CmsGraphQLSchemaPlugin(schema);\n plugin.name = `headless-cms.graphql.schema.${type}.field.${fieldTypePlugin.fieldType}`;\n plugins.push(plugin);\n }\n return plugins;\n};\n"],"mappings":";;;;;;AACA;AAEA,MAAMA,QAA2C,GAAG;EAChDC,OAAO,EAAE,MAAM;EACfC,IAAI,EAAE,MAAM;EACZC,MAAM,EAAE;AACZ,CAAC;AAOM,MAAMC,yCAAyC,GAAIC,MAAc,IAAK;EACzE,MAAM;IAAEC,MAAM;IAAEC,gBAAgB;IAAEC;EAAK,CAAC,GAAGH,MAAM;EAEjD,MAAMI,OAAiC,GAAG,EAAE;EAC5C,KAAK,MAAMC,GAAG,IAAIH,gBAAgB,EAAE;IAChC,MAAMI,eAAe,GAAGJ,gBAAgB,CAACG,GAAG,CAAC;IAC7C,IAAI,CAACV,QAAQ,CAACQ,IAAI,CAAC,IAAI,CAACG,eAAe,CAACX,QAAQ,CAACQ,IAAI,CAAC,CAAC,EAAE;MACrD;IACJ;IACA,MAAMI,YAAY,GAAGD,eAAe,CAACX,QAAQ,CAACQ,IAAI,CAAC,CAAC,CAACI,YAAY;IACjE;IACA,IAAI,CAACA,YAAY,EAAE;MACf;IACJ;IACA,MAAMC,MAAM,GAAGD,YAAY,CAAC;MAAEN;IAAO,CAAC,CAAC;IAEvC,MAAMQ,MAAM,GAAG,IAAIC,+BAAsB,CAACF,MAAM,CAAC;IACjDC,MAAM,CAACE,IAAI,GAAI,+BAA8BR,IAAK,UAASG,eAAe,CAACM,SAAU,EAAC;IACtFR,OAAO,CAACS,IAAI,CAACJ,MAAM,CAAC;EACxB;EACA,OAAOL,OAAO;AAClB,CAAC;AAAC"}
|
package/utils/renderFields.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.renderFields = exports.renderField = void 0;
|
|
7
|
+
var _getBaseFieldType = require("./getBaseFieldType");
|
|
7
8
|
const renderFields = ({
|
|
8
9
|
model,
|
|
9
10
|
type,
|
|
@@ -23,7 +24,7 @@ const renderField = ({
|
|
|
23
24
|
field,
|
|
24
25
|
fieldTypePlugins
|
|
25
26
|
}) => {
|
|
26
|
-
const plugin = fieldTypePlugins[field
|
|
27
|
+
const plugin = fieldTypePlugins[(0, _getBaseFieldType.getBaseFieldType)(field)];
|
|
27
28
|
if (!plugin) {
|
|
28
29
|
// Let's not render the field if it does not exist in the field plugins.
|
|
29
30
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["renderFields","model","type","fieldTypePlugins","fields","map","field","renderField","filter","Boolean","plugin","defs","createTypeField"],"sources":["renderFields.ts"],"sourcesContent":["import {\n ApiEndpoint,\n CmsFieldTypePlugins,\n CmsModel,\n CmsModelField,\n CmsModelFieldDefinition,\n CmsModelFieldToGraphQLPlugin\n} from \"~/types\";\n\ninterface RenderFieldsParams {\n model: CmsModel;\n type: ApiEndpoint;\n fieldTypePlugins: CmsFieldTypePlugins;\n}\ninterface RenderFields {\n (params: RenderFieldsParams): CmsModelFieldDefinition[];\n}\n\nexport const renderFields: RenderFields = ({\n model,\n type,\n fieldTypePlugins\n}): CmsModelFieldDefinition[] => {\n return model.fields\n .map(field => renderField({ model, type, field, fieldTypePlugins }))\n .filter(Boolean) as CmsModelFieldDefinition[];\n};\n\ninterface RenderFieldParams extends RenderFieldsParams {\n field: CmsModelField;\n}\n\nexport const renderField = ({\n model,\n type,\n field,\n fieldTypePlugins\n}: RenderFieldParams): CmsModelFieldDefinition | null => {\n const plugin: CmsModelFieldToGraphQLPlugin = fieldTypePlugins[field
|
|
1
|
+
{"version":3,"names":["renderFields","model","type","fieldTypePlugins","fields","map","field","renderField","filter","Boolean","plugin","getBaseFieldType","defs","createTypeField"],"sources":["renderFields.ts"],"sourcesContent":["import {\n ApiEndpoint,\n CmsFieldTypePlugins,\n CmsModel,\n CmsModelField,\n CmsModelFieldDefinition,\n CmsModelFieldToGraphQLPlugin\n} from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\n\ninterface RenderFieldsParams {\n model: CmsModel;\n type: ApiEndpoint;\n fieldTypePlugins: CmsFieldTypePlugins;\n}\ninterface RenderFields {\n (params: RenderFieldsParams): CmsModelFieldDefinition[];\n}\n\nexport const renderFields: RenderFields = ({\n model,\n type,\n fieldTypePlugins\n}): CmsModelFieldDefinition[] => {\n return model.fields\n .map(field => renderField({ model, type, field, fieldTypePlugins }))\n .filter(Boolean) as CmsModelFieldDefinition[];\n};\n\ninterface RenderFieldParams extends RenderFieldsParams {\n field: CmsModelField;\n}\n\nexport const renderField = ({\n model,\n type,\n field,\n fieldTypePlugins\n}: RenderFieldParams): CmsModelFieldDefinition | null => {\n const plugin: CmsModelFieldToGraphQLPlugin = fieldTypePlugins[getBaseFieldType(field)];\n if (!plugin) {\n // Let's not render the field if it does not exist in the field plugins.\n return null;\n }\n const defs = plugin[type].createTypeField({\n model,\n field,\n fieldTypePlugins\n });\n\n if (!defs) {\n return null;\n } else if (typeof defs === \"string\") {\n return {\n fields: defs\n };\n }\n\n return defs;\n};\n"],"mappings":";;;;;;AAQA;AAWO,MAAMA,YAA0B,GAAG,CAAC;EACvCC,KAAK;EACLC,IAAI;EACJC;AACJ,CAAC,KAAgC;EAC7B,OAAOF,KAAK,CAACG,MAAM,CACdC,GAAG,CAACC,KAAK,IAAIC,WAAW,CAAC;IAAEN,KAAK;IAAEC,IAAI;IAAEI,KAAK;IAAEH;EAAiB,CAAC,CAAC,CAAC,CACnEK,MAAM,CAACC,OAAO,CAAC;AACxB,CAAC;AAAC;AAMK,MAAMF,WAAW,GAAG,CAAC;EACxBN,KAAK;EACLC,IAAI;EACJI,KAAK;EACLH;AACe,CAAC,KAAqC;EACrD,MAAMO,MAAoC,GAAGP,gBAAgB,CAAC,IAAAQ,kCAAgB,EAACL,KAAK,CAAC,CAAC;EACtF,IAAI,CAACI,MAAM,EAAE;IACT;IACA,OAAO,IAAI;EACf;EACA,MAAME,IAAI,GAAGF,MAAM,CAACR,IAAI,CAAC,CAACW,eAAe,CAAC;IACtCZ,KAAK;IACLK,KAAK;IACLH;EACJ,CAAC,CAAC;EAEF,IAAI,CAACS,IAAI,EAAE;IACP,OAAO,IAAI;EACf,CAAC,MAAM,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;IACjC,OAAO;MACHR,MAAM,EAAEQ;IACZ,CAAC;EACL;EAEA,OAAOA,IAAI;AACf,CAAC;AAAC"}
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.renderGetFilterFields = void 0;
|
|
7
|
+
var _getBaseFieldType = require("./getBaseFieldType");
|
|
7
8
|
const getCreateFilters = (plugins, fieldType) => {
|
|
8
9
|
if (!plugins[fieldType] || !plugins[fieldType].read.createGetFilters) {
|
|
9
10
|
return null;
|
|
@@ -20,10 +21,11 @@ const renderGetFilterFields = ({
|
|
|
20
21
|
// want to be careful when accessing the field plugin here too. It is still possible to have a content model
|
|
21
22
|
// that contains a field, for which we don't have a plugin registered on the backend. For example, user
|
|
22
23
|
// could've just removed the plugin from the backend.
|
|
23
|
-
|
|
24
|
+
const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
|
|
25
|
+
if (!fieldTypePlugins[baseType]) {
|
|
24
26
|
return false;
|
|
25
27
|
}
|
|
26
|
-
return fieldTypePlugins[
|
|
28
|
+
return fieldTypePlugins[baseType].isSearchable;
|
|
27
29
|
}).map(f => f.fieldId);
|
|
28
30
|
const filters = ["id: ID", "entryId: String"];
|
|
29
31
|
for (const fieldId of fieldIdList) {
|
|
@@ -31,7 +33,8 @@ const renderGetFilterFields = ({
|
|
|
31
33
|
if (!field) {
|
|
32
34
|
continue;
|
|
33
35
|
}
|
|
34
|
-
const
|
|
36
|
+
const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
|
|
37
|
+
const createGetFilters = getCreateFilters(fieldTypePlugins, baseType);
|
|
35
38
|
if (typeof createGetFilters !== "function") {
|
|
36
39
|
continue;
|
|
37
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getCreateFilters","plugins","fieldType","read","createGetFilters","renderGetFilterFields","model","fieldTypePlugins","fieldIdList","fields","filter","field","
|
|
1
|
+
{"version":3,"names":["getCreateFilters","plugins","fieldType","read","createGetFilters","renderGetFilterFields","model","fieldTypePlugins","fieldIdList","fields","filter","field","baseType","getBaseFieldType","isSearchable","map","f","fieldId","filters","find","item","push","Boolean","join"],"sources":["renderGetFilterFields.ts"],"sourcesContent":["import { CmsFieldTypePlugins, CmsModel, CmsModelFieldToGraphQLPlugin } from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\n\ninterface RenderGetFilterFieldsParams {\n model: CmsModel;\n fieldTypePlugins: CmsFieldTypePlugins;\n}\ninterface RenderGetFilterFields {\n (params: RenderGetFilterFieldsParams): string;\n}\n\nconst getCreateFilters = (\n plugins: CmsFieldTypePlugins,\n fieldType: string\n): CmsModelFieldToGraphQLPlugin[\"read\"][\"createGetFilters\"] | null => {\n if (!plugins[fieldType] || !plugins[fieldType].read.createGetFilters) {\n return null;\n }\n return plugins[fieldType].read.createGetFilters;\n};\n\nexport const renderGetFilterFields: RenderGetFilterFields = ({ model, fieldTypePlugins }) => {\n const fieldIdList = model.fields\n .filter(field => {\n // Every time a client updates content model's fields, we check the type of each field. If a field plugin\n // for a particular \"field.type\" doesn't exist on the backend yet, we throw an error. But still, we also\n // want to be careful when accessing the field plugin here too. It is still possible to have a content model\n // that contains a field, for which we don't have a plugin registered on the backend. For example, user\n // could've just removed the plugin from the backend.\n const baseType = getBaseFieldType(field);\n if (!fieldTypePlugins[baseType]) {\n return false;\n }\n return fieldTypePlugins[baseType].isSearchable;\n })\n .map(f => f.fieldId);\n\n const filters: string[] = [\"id: ID\", \"entryId: String\"];\n\n for (const fieldId of fieldIdList) {\n const field = model.fields.find(item => item.fieldId === fieldId);\n if (!field) {\n continue;\n }\n const baseType = getBaseFieldType(field);\n const createGetFilters = getCreateFilters(fieldTypePlugins, baseType);\n if (typeof createGetFilters !== \"function\") {\n continue;\n }\n filters.push(createGetFilters({ model, field }));\n }\n\n return filters.filter(Boolean).join(\"\\n\");\n};\n"],"mappings":";;;;;;AACA;AAUA,MAAMA,gBAAgB,GAAG,CACrBC,OAA4B,EAC5BC,SAAiB,KACiD;EAClE,IAAI,CAACD,OAAO,CAACC,SAAS,CAAC,IAAI,CAACD,OAAO,CAACC,SAAS,CAAC,CAACC,IAAI,CAACC,gBAAgB,EAAE;IAClE,OAAO,IAAI;EACf;EACA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
|
});
|
|
6
6
|
exports.renderInputFields = exports.renderInputField = void 0;
|
|
7
|
+
var _getBaseFieldType = require("./getBaseFieldType");
|
|
7
8
|
const renderInputFields = ({
|
|
8
9
|
model,
|
|
9
10
|
fieldTypePlugins
|
|
@@ -25,7 +26,7 @@ const renderInputField = ({
|
|
|
25
26
|
// want to be careful when accessing the field plugin here too. It is still possible to have a content model
|
|
26
27
|
// that contains a field, for which we don't have a plugin registered on the backend. For example, user
|
|
27
28
|
// could've just removed the plugin from the backend.
|
|
28
|
-
const plugin = fieldTypePlugins[field
|
|
29
|
+
const plugin = fieldTypePlugins[(0, _getBaseFieldType.getBaseFieldType)(field)];
|
|
29
30
|
if (!plugin) {
|
|
30
31
|
// Let's not render the field if it does not exist in the field plugins.
|
|
31
32
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["renderInputFields","model","fieldTypePlugins","fields","map","field","renderInputField","filter","Boolean","plugin","
|
|
1
|
+
{"version":3,"names":["renderInputFields","model","fieldTypePlugins","fields","map","field","renderInputField","filter","Boolean","plugin","getBaseFieldType","def","manage","createInputField"],"sources":["renderInputFields.ts"],"sourcesContent":["import {\n CmsFieldTypePlugins,\n CmsModel,\n CmsModelField,\n CmsModelFieldDefinition,\n CmsModelFieldToGraphQLPlugin\n} from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\n\ninterface RenderInputFieldsParams {\n model: CmsModel;\n fieldTypePlugins: CmsFieldTypePlugins;\n}\ninterface RenderInputFieldParams extends RenderInputFieldsParams {\n field: CmsModelField;\n}\ninterface RenderInputFields {\n (params: RenderInputFieldsParams): CmsModelFieldDefinition[];\n}\n\nexport const renderInputFields: RenderInputFields = ({\n model,\n fieldTypePlugins\n}): CmsModelFieldDefinition[] => {\n return model.fields\n .map(field => renderInputField({ model, field, fieldTypePlugins }))\n .filter(Boolean) as CmsModelFieldDefinition[];\n};\n\nexport const renderInputField = ({\n model,\n field,\n fieldTypePlugins\n}: RenderInputFieldParams): CmsModelFieldDefinition | null => {\n // Every time a client updates content model's fields, we check the type of each field. If a field plugin\n // for a particular \"field.type\" doesn't exist on the backend yet, we throw an error. But still, we also\n // want to be careful when accessing the field plugin here too. It is still possible to have a content model\n // that contains a field, for which we don't have a plugin registered on the backend. For example, user\n // could've just removed the plugin from the backend.\n const plugin: CmsModelFieldToGraphQLPlugin = fieldTypePlugins[getBaseFieldType(field)];\n\n if (!plugin) {\n // Let's not render the field if it does not exist in the field plugins.\n return null;\n }\n\n const def = plugin.manage.createInputField({\n model,\n field,\n fieldTypePlugins\n });\n if (typeof def === \"string\") {\n return {\n fields: def\n };\n }\n\n return def;\n};\n"],"mappings":";;;;;;AAOA;AAaO,MAAMA,iBAAoC,GAAG,CAAC;EACjDC,KAAK;EACLC;AACJ,CAAC,KAAgC;EAC7B,OAAOD,KAAK,CAACE,MAAM,CACdC,GAAG,CAACC,KAAK,IAAIC,gBAAgB,CAAC;IAAEL,KAAK;IAAEI,KAAK;IAAEH;EAAiB,CAAC,CAAC,CAAC,CAClEK,MAAM,CAACC,OAAO,CAAC;AACxB,CAAC;AAAC;AAEK,MAAMF,gBAAgB,GAAG,CAAC;EAC7BL,KAAK;EACLI,KAAK;EACLH;AACoB,CAAC,KAAqC;EAC1D;EACA;EACA;EACA;EACA;EACA,MAAMO,MAAoC,GAAGP,gBAAgB,CAAC,IAAAQ,kCAAgB,EAACL,KAAK,CAAC,CAAC;EAEtF,IAAI,CAACI,MAAM,EAAE;IACT;IACA,OAAO,IAAI;EACf;EAEA,MAAME,GAAG,GAAGF,MAAM,CAACG,MAAM,CAACC,gBAAgB,CAAC;IACvCZ,KAAK;IACLI,KAAK;IACLH;EACJ,CAAC,CAAC;EACF,IAAI,OAAOS,GAAG,KAAK,QAAQ,EAAE;IACzB,OAAO;MACHR,MAAM,EAAEQ;IACZ,CAAC;EACL;EAEA,OAAOA,GAAG;AACd,CAAC;AAAC"}
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.renderListFilterFields = void 0;
|
|
7
|
+
var _getBaseFieldType = require("./getBaseFieldType");
|
|
7
8
|
/**
|
|
8
9
|
* We cast as read type, because input and output of read and manage are same. This way we ease things.
|
|
9
10
|
* Internal stuff so it should be ok.
|
|
@@ -37,13 +38,14 @@ const renderListFilterFields = params => {
|
|
|
37
38
|
// that contains a field, for which we don't have a plugin registered on the backend. For example, user
|
|
38
39
|
// could've just removed the plugin from the backend.
|
|
39
40
|
|
|
40
|
-
const createListFilters = getCreateListFilters(fieldTypePlugins, field
|
|
41
|
+
const createListFilters = getCreateListFilters(fieldTypePlugins, (0, _getBaseFieldType.getBaseFieldType)(field), type);
|
|
41
42
|
if (typeof createListFilters !== "function") {
|
|
42
43
|
continue;
|
|
43
44
|
}
|
|
44
45
|
fields.push(createListFilters({
|
|
45
46
|
model,
|
|
46
|
-
field
|
|
47
|
+
field,
|
|
48
|
+
plugins: fieldTypePlugins
|
|
47
49
|
}));
|
|
48
50
|
}
|
|
49
51
|
return fields.filter(Boolean).join("\n");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getCreateListFilters","plugins","fieldType","type","createListFilters","renderListFilterFields","params","model","fieldTypePlugins","fields","join","push","field","filter","Boolean"],"sources":["renderListFilterFields.ts"],"sourcesContent":["import { ApiEndpoint, CmsFieldTypePlugins, CmsModel, CmsModelFieldToGraphQLPlugin } from \"~/types\";\n\ninterface RenderListFilterFieldsParams {\n model: CmsModel;\n type: ApiEndpoint;\n fieldTypePlugins: CmsFieldTypePlugins;\n}\ninterface RenderListFilterFields {\n (params: RenderListFilterFieldsParams): string;\n}\n\ntype CreateListFiltersType =\n | CmsModelFieldToGraphQLPlugin[\"read\"][\"createListFilters\"]\n | CmsModelFieldToGraphQLPlugin[\"manage\"][\"createListFilters\"];\n/**\n * We cast as read type, because input and output of read and manage are same. This way we ease things.\n * Internal stuff so it should be ok.\n * TODO note that if changing read/manage types, change this as well.\n */\nconst getCreateListFilters = (\n plugins: CmsFieldTypePlugins,\n fieldType: string,\n type: ApiEndpoint\n): CreateListFiltersType | null => {\n if (!plugins[fieldType]) {\n return null;\n } else if (!plugins[fieldType][type]) {\n return null;\n }\n return plugins[fieldType][type].createListFilters;\n};\n\nexport const renderListFilterFields: RenderListFilterFields = (params): string => {\n const { model, type, fieldTypePlugins } = params;\n const fields: string[] = [\n [\n \"id: ID\",\n \"id_not: ID\",\n \"id_in: [ID!]\",\n \"id_not_in: [ID!]\",\n \"entryId: String\",\n \"entryId_not: String\",\n \"entryId_in: [String!]\",\n \"entryId_not_in: [String!]\",\n \"createdOn: DateTime\",\n \"createdOn_gt: DateTime\",\n \"createdOn_gte: DateTime\",\n \"createdOn_lt: DateTime\",\n \"createdOn_lte: DateTime\",\n \"createdOn_between: [DateTime!]\",\n \"createdOn_not_between: [DateTime!]\",\n \"savedOn: DateTime\",\n \"savedOn_gt: DateTime\",\n \"savedOn_gte: DateTime\",\n \"savedOn_lt: DateTime\",\n \"savedOn_lte: DateTime\",\n \"savedOn_between: [DateTime!]\",\n \"savedOn_not_between: [DateTime!]\",\n \"createdBy: String\",\n \"createdBy_not: String\",\n \"createdBy_in: [String!]\",\n \"createdBy_not_in: [String!]\",\n \"ownedBy: String\",\n \"ownedBy_not: String\",\n \"ownedBy_in: [String!]\",\n \"ownedBy_not_in: [String!]\"\n ].join(\"\\n\")\n ];\n /**\n * We can find different statuses only in the manage API endpoint.\n */\n if (type === \"manage\") {\n fields.push(\n ...[\n \"status: String\",\n \"status_not: String\",\n \"status_in: [String!]\",\n \"status_not_in: [String!]\"\n ]\n );\n }\n\n for (const field of model.fields) {\n // Every time a client updates content model's fields, we check the type of each field. If a field plugin\n // for a particular \"field.type\" doesn't exist on the backend yet, we throw an error. But still, we also\n // want to be careful when accessing the field plugin here too. It is still possible to have a content model\n // that contains a field, for which we don't have a plugin registered on the backend. For example, user\n // could've just removed the plugin from the backend.\n\n const createListFilters = getCreateListFilters(fieldTypePlugins
|
|
1
|
+
{"version":3,"names":["getCreateListFilters","plugins","fieldType","type","createListFilters","renderListFilterFields","params","model","fieldTypePlugins","fields","join","push","field","getBaseFieldType","filter","Boolean"],"sources":["renderListFilterFields.ts"],"sourcesContent":["import { ApiEndpoint, CmsFieldTypePlugins, CmsModel, CmsModelFieldToGraphQLPlugin } from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\n\ninterface RenderListFilterFieldsParams {\n model: CmsModel;\n type: ApiEndpoint;\n fieldTypePlugins: CmsFieldTypePlugins;\n}\ninterface RenderListFilterFields {\n (params: RenderListFilterFieldsParams): string;\n}\n\ntype CreateListFiltersType =\n | CmsModelFieldToGraphQLPlugin[\"read\"][\"createListFilters\"]\n | CmsModelFieldToGraphQLPlugin[\"manage\"][\"createListFilters\"];\n/**\n * We cast as read type, because input and output of read and manage are same. This way we ease things.\n * Internal stuff so it should be ok.\n * TODO note that if changing read/manage types, change this as well.\n */\nconst getCreateListFilters = (\n plugins: CmsFieldTypePlugins,\n fieldType: string,\n type: ApiEndpoint\n): CreateListFiltersType | null => {\n if (!plugins[fieldType]) {\n return null;\n } else if (!plugins[fieldType][type]) {\n return null;\n }\n return plugins[fieldType][type].createListFilters;\n};\n\nexport const renderListFilterFields: RenderListFilterFields = (params): string => {\n const { model, type, fieldTypePlugins } = params;\n const fields: string[] = [\n [\n \"id: ID\",\n \"id_not: ID\",\n \"id_in: [ID!]\",\n \"id_not_in: [ID!]\",\n \"entryId: String\",\n \"entryId_not: String\",\n \"entryId_in: [String!]\",\n \"entryId_not_in: [String!]\",\n \"createdOn: DateTime\",\n \"createdOn_gt: DateTime\",\n \"createdOn_gte: DateTime\",\n \"createdOn_lt: DateTime\",\n \"createdOn_lte: DateTime\",\n \"createdOn_between: [DateTime!]\",\n \"createdOn_not_between: [DateTime!]\",\n \"savedOn: DateTime\",\n \"savedOn_gt: DateTime\",\n \"savedOn_gte: DateTime\",\n \"savedOn_lt: DateTime\",\n \"savedOn_lte: DateTime\",\n \"savedOn_between: [DateTime!]\",\n \"savedOn_not_between: [DateTime!]\",\n \"createdBy: String\",\n \"createdBy_not: String\",\n \"createdBy_in: [String!]\",\n \"createdBy_not_in: [String!]\",\n \"ownedBy: String\",\n \"ownedBy_not: String\",\n \"ownedBy_in: [String!]\",\n \"ownedBy_not_in: [String!]\"\n ].join(\"\\n\")\n ];\n /**\n * We can find different statuses only in the manage API endpoint.\n */\n if (type === \"manage\") {\n fields.push(\n ...[\n \"status: String\",\n \"status_not: String\",\n \"status_in: [String!]\",\n \"status_not_in: [String!]\"\n ]\n );\n }\n\n for (const field of model.fields) {\n // Every time a client updates content model's fields, we check the type of each field. If a field plugin\n // for a particular \"field.type\" doesn't exist on the backend yet, we throw an error. But still, we also\n // want to be careful when accessing the field plugin here too. It is still possible to have a content model\n // that contains a field, for which we don't have a plugin registered on the backend. For example, user\n // could've just removed the plugin from the backend.\n\n const createListFilters = getCreateListFilters(\n fieldTypePlugins,\n getBaseFieldType(field),\n type\n );\n if (typeof createListFilters !== \"function\") {\n continue;\n }\n fields.push(createListFilters({ model, field, plugins: fieldTypePlugins }));\n }\n\n return fields.filter(Boolean).join(\"\\n\");\n};\n"],"mappings":";;;;;;AACA;AAcA;AACA;AACA;AACA;AACA;AACA,MAAMA,oBAAoB,GAAG,CACzBC,OAA4B,EAC5BC,SAAiB,EACjBC,IAAiB,KACc;EAC/B,IAAI,CAACF,OAAO,CAACC,SAAS,CAAC,EAAE;IACrB,OAAO,IAAI;EACf,CAAC,MAAM,IAAI,CAACD,OAAO,CAACC,SAAS,CAAC,CAACC,IAAI,CAAC,EAAE;IAClC,OAAO,IAAI;EACf;EACA,OAAOF,OAAO,CAACC,SAAS,CAAC,CAACC,IAAI,CAAC,CAACC,iBAAiB;AACrD,CAAC;AAEM,MAAMC,sBAA8C,GAAIC,MAAM,IAAa;EAC9E,MAAM;IAAEC,KAAK;IAAEJ,IAAI;IAAEK;EAAiB,CAAC,GAAGF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+
import { CmsGraphQLSchemaSorterPlugin } from "../plugins/CmsGraphQLSchemaSorterPlugin";
|
|
3
|
+
interface RenderSortEnumParams {
|
|
4
|
+
model: CmsModel;
|
|
5
|
+
fieldTypePlugins: CmsFieldTypePlugins;
|
|
6
|
+
sorterPlugins: CmsGraphQLSchemaSorterPlugin[];
|
|
7
|
+
}
|
|
2
8
|
interface RenderSortEnum {
|
|
3
|
-
(params:
|
|
4
|
-
model: CmsModel;
|
|
5
|
-
fieldTypePlugins: CmsFieldTypePlugins;
|
|
6
|
-
}): string;
|
|
9
|
+
(params: RenderSortEnumParams): string;
|
|
7
10
|
}
|
|
8
11
|
export declare const renderSortEnum: RenderSortEnum;
|
|
9
12
|
export {};
|
package/utils/renderSortEnum.js
CHANGED
|
@@ -4,15 +4,27 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.renderSortEnum = void 0;
|
|
7
|
+
var _getBaseFieldType = require("./getBaseFieldType");
|
|
7
8
|
const renderSortEnum = ({
|
|
8
9
|
model,
|
|
9
|
-
fieldTypePlugins
|
|
10
|
+
fieldTypePlugins,
|
|
11
|
+
sorterPlugins
|
|
10
12
|
}) => {
|
|
11
|
-
|
|
13
|
+
let sorters = [`id_ASC`, `id_DESC`, "savedOn_ASC", "savedOn_DESC", "createdOn_ASC", "createdOn_DESC"];
|
|
12
14
|
for (const field of model.fields) {
|
|
13
|
-
const plugin = fieldTypePlugins[field
|
|
15
|
+
const plugin = fieldTypePlugins[(0, _getBaseFieldType.getBaseFieldType)(field)];
|
|
14
16
|
if (!plugin) {
|
|
15
17
|
continue;
|
|
18
|
+
} else if (plugin.createSorters) {
|
|
19
|
+
const result = plugin.createSorters({
|
|
20
|
+
model,
|
|
21
|
+
field,
|
|
22
|
+
sorters
|
|
23
|
+
});
|
|
24
|
+
if (result) {
|
|
25
|
+
sorters = result;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
16
28
|
}
|
|
17
29
|
if (!plugin.isSortable) {
|
|
18
30
|
continue;
|
|
@@ -20,6 +32,11 @@ const renderSortEnum = ({
|
|
|
20
32
|
sorters.push(`${field.fieldId}_ASC`);
|
|
21
33
|
sorters.push(`${field.fieldId}_DESC`);
|
|
22
34
|
}
|
|
23
|
-
return
|
|
35
|
+
return sorterPlugins.reduce((result, plugin) => {
|
|
36
|
+
return plugin.createSorter({
|
|
37
|
+
model,
|
|
38
|
+
sorters: result
|
|
39
|
+
});
|
|
40
|
+
}, sorters).join("\n");
|
|
24
41
|
};
|
|
25
42
|
exports.renderSortEnum = renderSortEnum;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["renderSortEnum","model","fieldTypePlugins","sorters","field","fields","plugin","
|
|
1
|
+
{"version":3,"names":["renderSortEnum","model","fieldTypePlugins","sorterPlugins","sorters","field","fields","plugin","getBaseFieldType","createSorters","result","isSortable","push","fieldId","reduce","createSorter","join"],"sources":["renderSortEnum.ts"],"sourcesContent":["import { CmsFieldTypePlugins, CmsModel } from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\nimport { CmsGraphQLSchemaSorterPlugin } from \"~/plugins/CmsGraphQLSchemaSorterPlugin\";\n\ninterface RenderSortEnumParams {\n model: CmsModel;\n fieldTypePlugins: CmsFieldTypePlugins;\n sorterPlugins: CmsGraphQLSchemaSorterPlugin[];\n}\ninterface RenderSortEnum {\n (params: RenderSortEnumParams): string;\n}\n\nexport const renderSortEnum: RenderSortEnum = ({\n model,\n fieldTypePlugins,\n sorterPlugins\n}): string => {\n let sorters: string[] = [\n `id_ASC`,\n `id_DESC`,\n \"savedOn_ASC\",\n \"savedOn_DESC\",\n \"createdOn_ASC\",\n \"createdOn_DESC\"\n ];\n\n for (const field of model.fields) {\n const plugin = fieldTypePlugins[getBaseFieldType(field)];\n if (!plugin) {\n continue;\n } else if (plugin.createSorters) {\n const result = plugin.createSorters({\n model,\n field,\n sorters\n });\n if (result) {\n sorters = result;\n continue;\n }\n }\n if (!plugin.isSortable) {\n continue;\n }\n sorters.push(`${field.fieldId}_ASC`);\n sorters.push(`${field.fieldId}_DESC`);\n }\n\n return sorterPlugins\n .reduce((result, plugin) => {\n return plugin.createSorter({\n model,\n sorters: result\n });\n }, sorters)\n .join(\"\\n\");\n};\n"],"mappings":";;;;;;AACA;AAYO,MAAMA,cAA8B,GAAG,CAAC;EAC3CC,KAAK;EACLC,gBAAgB;EAChBC;AACJ,CAAC,KAAa;EACV,IAAIC,OAAiB,GAAG,CACnB,QAAO,EACP,SAAQ,EACT,aAAa,EACb,cAAc,EACd,eAAe,EACf,gBAAgB,CACnB;EAED,KAAK,MAAMC,KAAK,IAAIJ,KAAK,CAACK,MAAM,EAAE;IAC9B,MAAMC,MAAM,GAAGL,gBAAgB,CAAC,IAAAM,kCAAgB,EAACH,KAAK,CAAC,CAAC;IACxD,IAAI,CAACE,MAAM,EAAE;MACT;IACJ,CAAC,MAAM,IAAIA,MAAM,CAACE,aAAa,EAAE;MAC7B,MAAMC,MAAM,GAAGH,MAAM,CAACE,aAAa,CAAC;QAChCR,KAAK;QACLI,KAAK;QACLD;MACJ,CAAC,CAAC;MACF,IAAIM,MAAM,EAAE;QACRN,OAAO,GAAGM,MAAM;QAChB;MACJ;IACJ;IACA,IAAI,CAACH,MAAM,CAACI,UAAU,EAAE;MACpB;IACJ;IACAP,OAAO,CAACQ,IAAI,CAAE,GAAEP,KAAK,CAACQ,OAAQ,MAAK,CAAC;IACpCT,OAAO,CAACQ,IAAI,CAAE,GAAEP,KAAK,CAACQ,OAAQ,OAAM,CAAC;EACzC;EAEA,OAAOV,aAAa,CACfW,MAAM,CAAC,CAACJ,MAAM,EAAEH,MAAM,KAAK;IACxB,OAAOA,MAAM,CAACQ,YAAY,CAAC;MACvBd,KAAK;MACLG,OAAO,EAAEM;IACb,CAAC,CAAC;EACN,CAAC,EAAEN,OAAO,CAAC,CACVY,IAAI,CAAC,IAAI,CAAC;AACnB,CAAC;AAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createDynamicZoneValidator = void 0;
|
|
7
|
+
const createDynamicZoneValidator = () => {
|
|
8
|
+
return {
|
|
9
|
+
type: "cms-model-field-validator",
|
|
10
|
+
name: "cms-model-field-validator-dynamic-zone",
|
|
11
|
+
validator: {
|
|
12
|
+
name: "dynamicZone",
|
|
13
|
+
validate() {
|
|
14
|
+
// TODO: implement validation.
|
|
15
|
+
return Promise.resolve(true);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
exports.createDynamicZoneValidator = createDynamicZoneValidator;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createDynamicZoneValidator","type","name","validator","validate","Promise","resolve"],"sources":["dynamicZone.ts"],"sourcesContent":["import { CmsModelFieldValidatorPlugin } from \"~/types\";\n\nexport const createDynamicZoneValidator = (): CmsModelFieldValidatorPlugin => {\n return {\n type: \"cms-model-field-validator\",\n name: \"cms-model-field-validator-dynamic-zone\",\n validator: {\n name: \"dynamicZone\",\n validate() {\n // TODO: implement validation.\n return Promise.resolve(true);\n }\n }\n };\n};\n"],"mappings":";;;;;;AAEO,MAAMA,0BAA0B,GAAG,MAAoC;EAC1E,OAAO;IACHC,IAAI,EAAE,2BAA2B;IACjCC,IAAI,EAAE,wCAAwC;IAC9CC,SAAS,EAAE;MACPD,IAAI,EAAE,aAAa;MACnBE,QAAQ,GAAG;QACP;QACA,OAAOC,OAAO,CAACC,OAAO,CAAC,IAAI,CAAC;MAChC;IACJ;EACJ,CAAC;AACL,CAAC;AAAC"}
|
package/validators/index.js
CHANGED
|
@@ -17,5 +17,6 @@ var _dateGte = require("./dateGte");
|
|
|
17
17
|
var _timeLte = require("./timeLte");
|
|
18
18
|
var _timeGte = require("./timeGte");
|
|
19
19
|
var _unique = require("./unique");
|
|
20
|
-
|
|
20
|
+
var _dynamicZone = require("./dynamicZone");
|
|
21
|
+
const createValidators = () => [(0, _gte.createGteValidator)(), (0, _in.createInValidator)(), (0, _lte.createLteValidator)(), (0, _maxLength.createMaxLengthValidator)(), (0, _minLength.createMinLengthValidator)(), (0, _pattern.createPatternValidator)(), (0, _required.createRequiredValidator)(), (0, _patternPlugins.createPatternValidatorPlugins)(), (0, _dateLte.createDateLteValidator)(), (0, _dateGte.createDateGteValidator)(), (0, _timeLte.createTimeLteValidator)(), (0, _timeGte.createTimeGteValidator)(), (0, _unique.createUniqueValidator)(), (0, _dynamicZone.createDynamicZoneValidator)()];
|
|
21
22
|
exports.createValidators = createValidators;
|