@webiny/api-headless-cms 0.0.0-unstable.6e5425ee89 → 0.0.0-unstable.78f581c1d2
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.js +15 -0
- package/context.js.map +1 -1
- package/crud/contentEntry/afterDelete.js +5 -0
- package/crud/contentEntry/afterDelete.js.map +1 -1
- package/crud/contentEntry/beforeCreate.js +3 -0
- package/crud/contentEntry/beforeCreate.js.map +1 -1
- package/crud/contentEntry/beforeUpdate.js +3 -0
- package/crud/contentEntry/beforeUpdate.js.map +1 -1
- package/crud/contentEntry/entryDataValidation.js +40 -1
- package/crud/contentEntry/entryDataValidation.js.map +1 -1
- package/crud/contentEntry/markLockedFields.js +25 -2
- package/crud/contentEntry/markLockedFields.js.map +1 -1
- package/crud/contentEntry/referenceFieldsMapping.js +59 -5
- package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
- package/crud/contentEntry.crud.js +145 -27
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/afterCreate.js +2 -0
- package/crud/contentModel/afterCreate.js.map +1 -1
- package/crud/contentModel/afterCreateFrom.js +2 -0
- package/crud/contentModel/afterCreateFrom.js.map +1 -1
- package/crud/contentModel/afterDelete.js +2 -0
- package/crud/contentModel/afterDelete.js.map +1 -1
- package/crud/contentModel/afterUpdate.js +2 -0
- package/crud/contentModel/afterUpdate.js.map +1 -1
- package/crud/contentModel/beforeCreate.js +32 -4
- package/crud/contentModel/beforeCreate.js.map +1 -1
- package/crud/contentModel/beforeDelete.js +10 -0
- package/crud/contentModel/beforeDelete.js.map +1 -1
- package/crud/contentModel/beforeUpdate.js +5 -0
- package/crud/contentModel/beforeUpdate.js.map +1 -1
- package/crud/contentModel/contentModelManagerFactory.js +7 -0
- package/crud/contentModel/contentModelManagerFactory.js.map +1 -1
- package/crud/contentModel/createFieldModels.js +6 -0
- package/crud/contentModel/createFieldModels.js.map +1 -1
- package/crud/contentModel/createFieldStorageId.js +2 -0
- package/crud/contentModel/createFieldStorageId.js.map +1 -1
- package/crud/contentModel/fieldIdValidation.js +5 -0
- package/crud/contentModel/fieldIdValidation.js.map +1 -1
- package/crud/contentModel/idValidation.js +5 -0
- package/crud/contentModel/idValidation.js.map +1 -1
- package/crud/contentModel/models.js +8 -1
- package/crud/contentModel/models.js.map +1 -1
- package/crud/contentModel/systemFields.js.map +1 -1
- package/crud/contentModel/validateLayout.js +8 -0
- package/crud/contentModel/validateLayout.js.map +1 -1
- package/crud/contentModel/validateModel.js +8 -0
- package/crud/contentModel/validateModel.js.map +1 -1
- package/crud/contentModel/validateModelFields.js +60 -8
- package/crud/contentModel/validateModelFields.js.map +1 -1
- package/crud/contentModel.crud.js +96 -11
- package/crud/contentModel.crud.js.map +1 -1
- package/crud/contentModelGroup/beforeCreate.js +12 -0
- package/crud/contentModelGroup/beforeCreate.js.map +1 -1
- package/crud/contentModelGroup/beforeDelete.js +8 -0
- package/crud/contentModelGroup/beforeDelete.js.map +1 -1
- package/crud/contentModelGroup/beforeUpdate.js +5 -0
- package/crud/contentModelGroup/beforeUpdate.js.map +1 -1
- package/crud/contentModelGroup.crud.js +47 -10
- package/crud/contentModelGroup.crud.js.map +1 -1
- package/crud/index.js +16 -0
- package/crud/index.js.map +1 -1
- package/crud/settings.crud.js +12 -0
- package/crud/settings.crud.js.map +1 -1
- package/crud/system.crud.js +37 -2
- package/crud/system.crud.js.map +1 -1
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +13 -0
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +53 -0
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/index.js +4 -0
- package/fieldConverters/index.js.map +1 -1
- package/graphql/buildSchemaPlugins.js +9 -5
- package/graphql/buildSchemaPlugins.js.map +1 -1
- package/graphql/graphQLHandlerFactory.js +28 -3
- package/graphql/graphQLHandlerFactory.js.map +1 -1
- package/graphql/index.js +8 -1
- package/graphql/index.js.map +1 -1
- package/graphql/schema/baseContentSchema.js +9 -1
- package/graphql/schema/baseContentSchema.js.map +1 -1
- package/graphql/schema/contentEntries.js +42 -2
- package/graphql/schema/contentEntries.js.map +1 -1
- package/graphql/schema/contentModelGroups.js +19 -2
- package/graphql/schema/contentModelGroups.js.map +1 -1
- package/graphql/schema/contentModels.js +18 -2
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createFieldResolvers.js +21 -3
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphql/schema/createManageResolvers.js +26 -0
- package/graphql/schema/createManageResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.js +14 -1
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/createPreviewResolvers.js +10 -0
- package/graphql/schema/createPreviewResolvers.js.map +1 -1
- package/graphql/schema/createReadResolvers.js +10 -0
- package/graphql/schema/createReadResolvers.js.map +1 -1
- package/graphql/schema/createReadSDL.js +10 -0
- package/graphql/schema/createReadSDL.js.map +1 -1
- package/graphql/schema/resolvers/commonFieldResolvers.js +2 -0
- package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveCreate.js +3 -0
- package/graphql/schema/resolvers/manage/resolveCreate.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js +3 -0
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveDelete.js +6 -0
- package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGet.js +16 -0
- package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGetByIds.js +3 -0
- package/graphql/schema/resolvers/manage/resolveGetByIds.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGetRevisions.js +3 -0
- package/graphql/schema/resolvers/manage/resolveGetRevisions.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveList.js +3 -0
- package/graphql/schema/resolvers/manage/resolveList.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolvePublish.js +3 -0
- package/graphql/schema/resolvers/manage/resolvePublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveRepublish.js +3 -0
- package/graphql/schema/resolvers/manage/resolveRepublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveUnpublish.js +3 -0
- package/graphql/schema/resolvers/manage/resolveUnpublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveUpdate.js +3 -0
- package/graphql/schema/resolvers/manage/resolveUpdate.js.map +1 -1
- package/graphql/schema/resolvers/preview/resolveGet.js +8 -0
- package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/preview/resolveList.js +3 -0
- package/graphql/schema/resolvers/preview/resolveList.js.map +1 -1
- package/graphql/schema/resolvers/read/resolveGet.js +8 -0
- package/graphql/schema/resolvers/read/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/read/resolveList.js +3 -0
- package/graphql/schema/resolvers/read/resolveList.js.map +1 -1
- package/graphql/schema/schemaPlugins.js +19 -5
- package/graphql/schema/schemaPlugins.js.map +1 -1
- package/graphql/system.js +14 -1
- package/graphql/system.js.map +1 -1
- package/graphqlFields/boolean.js +12 -0
- package/graphqlFields/boolean.js.map +1 -1
- package/graphqlFields/datetime.js +17 -0
- package/graphqlFields/datetime.js.map +1 -1
- package/graphqlFields/file.js +8 -0
- package/graphqlFields/file.js.map +1 -1
- package/graphqlFields/helpers.js +10 -0
- package/graphqlFields/helpers.js.map +1 -1
- package/graphqlFields/index.js +11 -0
- package/graphqlFields/index.js.map +1 -1
- package/graphqlFields/longText.js +10 -0
- package/graphqlFields/longText.js.map +1 -1
- package/graphqlFields/number.js +12 -0
- package/graphqlFields/number.js.map +1 -1
- package/graphqlFields/object.js +36 -6
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +51 -17
- package/graphqlFields/ref.js.map +1 -1
- package/graphqlFields/richText.js +9 -0
- package/graphqlFields/richText.js.map +1 -1
- package/graphqlFields/text.js +11 -0
- package/graphqlFields/text.js.map +1 -1
- package/index.js +19 -0
- package/index.js.map +1 -1
- package/modelManager/DefaultCmsModelManager.js +16 -0
- package/modelManager/DefaultCmsModelManager.js.map +1 -1
- package/modelManager/index.js +4 -0
- package/modelManager/index.js.map +1 -1
- package/package.json +24 -24
- package/parameters/context.js +4 -0
- package/parameters/context.js.map +1 -1
- package/parameters/header.js +11 -0
- package/parameters/header.js.map +1 -1
- package/parameters/index.js +8 -0
- package/parameters/index.js.map +1 -1
- package/parameters/manual.js +8 -1
- package/parameters/manual.js.map +1 -1
- package/parameters/path.js +11 -0
- package/parameters/path.js.map +1 -1
- package/plugins/CmsGroupPlugin.js +8 -0
- package/plugins/CmsGroupPlugin.js.map +1 -1
- package/plugins/CmsModelFieldConverterPlugin.js +5 -0
- package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
- package/plugins/CmsModelPlugin.js +38 -2
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/plugins/CmsParametersPlugin.js +7 -0
- package/plugins/CmsParametersPlugin.js.map +1 -1
- package/plugins/StorageTransformPlugin.js +9 -0
- package/plugins/StorageTransformPlugin.js.map +1 -1
- package/plugins/index.js +10 -0
- package/plugins/index.js.map +1 -1
- package/storage/default.js +3 -0
- package/storage/default.js.map +1 -1
- package/storage/object.js +18 -0
- package/storage/object.js.map +1 -1
- package/types.js +62 -0
- package/types.js.map +1 -1
- package/upgrades/5.33.0/index.js +26 -3
- package/upgrades/5.33.0/index.js.map +1 -1
- package/upgrades/index.js +3 -0
- package/upgrades/index.js.map +1 -1
- package/utils/access.js +25 -11
- package/utils/access.js.map +1 -1
- package/utils/converters/Converter.js +13 -0
- package/utils/converters/Converter.js.map +1 -1
- package/utils/converters/ConverterCollection.js +32 -9
- package/utils/converters/ConverterCollection.js.map +1 -1
- package/utils/converters/valueKeyStorageConverter.js +26 -0
- package/utils/converters/valueKeyStorageConverter.js.map +1 -1
- package/utils/createTypeName.js +8 -0
- package/utils/createTypeName.js.map +1 -1
- package/utils/entryStorage.js +26 -10
- package/utils/entryStorage.js.map +1 -1
- package/utils/filterAsync.js +5 -0
- package/utils/filterAsync.js.map +1 -1
- package/utils/filterModelFields.js +9 -3
- package/utils/filterModelFields.js.map +1 -1
- package/utils/getEntryTitle.js +9 -0
- package/utils/getEntryTitle.js.map +1 -1
- package/utils/getSchemaFromFieldPlugins.js +6 -2
- package/utils/getSchemaFromFieldPlugins.js.map +1 -1
- package/utils/ownership.js +8 -0
- package/utils/ownership.js.map +1 -1
- package/utils/permissions.js +23 -8
- package/utils/permissions.js.map +1 -1
- package/utils/pluralizedTypeName.js +6 -0
- package/utils/pluralizedTypeName.js.map +1 -1
- package/utils/renderFields.js +8 -0
- package/utils/renderFields.js.map +1 -1
- package/utils/renderGetFilterFields.js +11 -0
- package/utils/renderGetFilterFields.js.map +1 -1
- package/utils/renderInputFields.js +8 -0
- package/utils/renderInputFields.js.map +1 -1
- package/utils/renderListFilterFields.js +9 -1
- package/utils/renderListFilterFields.js.map +1 -1
- package/utils/renderSortEnum.js +7 -0
- package/utils/renderSortEnum.js.map +1 -1
- package/utils/toSlug.js +4 -0
- package/utils/toSlug.js.map +1 -1
- package/validators/dateGte.js +7 -0
- package/validators/dateGte.js.map +1 -1
- package/validators/dateLte.js +7 -0
- package/validators/dateLte.js.map +1 -1
- package/validators/gte.js +8 -0
- package/validators/gte.js.map +1 -1
- package/validators/in.js +8 -0
- package/validators/in.js.map +1 -1
- package/validators/index.js +15 -0
- package/validators/index.js.map +1 -1
- package/validators/lte.js +8 -0
- package/validators/lte.js.map +1 -1
- package/validators/maxLength.js +8 -0
- package/validators/maxLength.js.map +1 -1
- package/validators/minLength.js +8 -0
- package/validators/minLength.js.map +1 -1
- package/validators/pattern.js +9 -0
- package/validators/pattern.js.map +1 -1
- package/validators/patternPlugins/email.js +2 -0
- package/validators/patternPlugins/email.js.map +1 -1
- package/validators/patternPlugins/index.js +8 -0
- package/validators/patternPlugins/index.js.map +1 -1
- package/validators/patternPlugins/lowerCase.js +2 -0
- package/validators/patternPlugins/lowerCase.js.map +1 -1
- package/validators/patternPlugins/lowerCaseSpace.js +2 -0
- package/validators/patternPlugins/lowerCaseSpace.js.map +1 -1
- package/validators/patternPlugins/upperCase.js +2 -0
- package/validators/patternPlugins/upperCase.js.map +1 -1
- package/validators/patternPlugins/upperCaseSpace.js +2 -0
- package/validators/patternPlugins/upperCaseSpace.js.map +1 -1
- package/validators/patternPlugins/url.js +2 -0
- package/validators/patternPlugins/url.js.map +1 -1
- package/validators/required.js +5 -0
- package/validators/required.js.map +1 -1
- package/validators/timeGte.js +8 -0
- package/validators/timeGte.js.map +1 -1
- package/validators/timeLte.js +8 -0
- package/validators/timeLte.js.map +1 -1
- package/validators/unique.js +7 -0
- package/validators/unique.js.map +1 -1
package/utils/entryStorage.js
CHANGED
|
@@ -1,50 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
7
8
|
exports.entryToStorageTransform = exports.entryFromStorageTransform = exports.entryFieldFromStorageTransform = void 0;
|
|
9
|
+
|
|
8
10
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
9
12
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
10
14
|
var _StorageTransformPlugin = require("../plugins/StorageTransformPlugin");
|
|
15
|
+
|
|
11
16
|
const getStoragePluginFactory = context => {
|
|
12
17
|
let defaultStoragePlugin;
|
|
13
|
-
const plugins = context.plugins.byType(_StorageTransformPlugin.StorageTransformPlugin.type)
|
|
14
|
-
// we reverse plugins because we want to get latest added only
|
|
18
|
+
const plugins = context.plugins.byType(_StorageTransformPlugin.StorageTransformPlugin.type) // we reverse plugins because we want to get latest added only
|
|
15
19
|
.reverse().reduce((collection, plugin) => {
|
|
16
20
|
// check if it's a default plugin
|
|
17
21
|
if (plugin.fieldType === "*" && !defaultStoragePlugin) {
|
|
18
22
|
defaultStoragePlugin = plugin;
|
|
19
23
|
return collection;
|
|
20
24
|
}
|
|
21
|
-
|
|
22
25
|
/**
|
|
23
26
|
* either existing plugin added or plugin fieldType does not exist in current model
|
|
24
27
|
* this is to iterate a bit less later
|
|
25
28
|
*/
|
|
29
|
+
|
|
30
|
+
|
|
26
31
|
if (!collection[plugin.fieldType]) {
|
|
27
32
|
collection[plugin.fieldType] = plugin;
|
|
28
33
|
}
|
|
34
|
+
|
|
29
35
|
return collection;
|
|
30
36
|
}, {});
|
|
31
37
|
return fieldType => {
|
|
32
38
|
return plugins[fieldType] || defaultStoragePlugin;
|
|
33
39
|
};
|
|
34
40
|
};
|
|
35
|
-
|
|
36
41
|
/**
|
|
37
42
|
* This should be used when transforming the whole entry.
|
|
38
43
|
*/
|
|
44
|
+
|
|
45
|
+
|
|
39
46
|
const entryStorageTransform = async (context, model, operation, entry) => {
|
|
40
47
|
const getStoragePlugin = getStoragePluginFactory(context);
|
|
41
48
|
const transformedValues = {};
|
|
49
|
+
|
|
42
50
|
for (const field of model.fields) {
|
|
43
|
-
const plugin = getStoragePlugin(field.type);
|
|
44
|
-
|
|
51
|
+
const plugin = getStoragePlugin(field.type); // TODO: remove this once plugins are converted into classes
|
|
52
|
+
|
|
45
53
|
if (typeof plugin[operation] !== "function") {
|
|
46
54
|
throw new _error.default(`Missing "${operation}" function in storage plugin "${plugin.name}" for field type "${field.type}"`);
|
|
47
55
|
}
|
|
56
|
+
|
|
48
57
|
transformedValues[field.fieldId] = await plugin[operation]({
|
|
49
58
|
plugins: context.plugins,
|
|
50
59
|
model,
|
|
@@ -53,26 +62,32 @@ const entryStorageTransform = async (context, model, operation, entry) => {
|
|
|
53
62
|
getStoragePlugin
|
|
54
63
|
});
|
|
55
64
|
}
|
|
65
|
+
|
|
56
66
|
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry), {}, {
|
|
57
67
|
values: transformedValues
|
|
58
68
|
});
|
|
59
69
|
};
|
|
60
|
-
|
|
61
70
|
/**
|
|
62
71
|
* A function that is used in crud to transform entry into the storage type.
|
|
63
72
|
*/
|
|
73
|
+
|
|
74
|
+
|
|
64
75
|
const entryToStorageTransform = async (context, model, entry) => {
|
|
65
76
|
return entryStorageTransform(context, model, "toStorage", entry);
|
|
66
77
|
};
|
|
67
|
-
|
|
68
78
|
/**
|
|
69
79
|
* A function that is used to transform the whole entry from storage into its native form.
|
|
70
80
|
*/
|
|
81
|
+
|
|
82
|
+
|
|
71
83
|
exports.entryToStorageTransform = entryToStorageTransform;
|
|
84
|
+
|
|
72
85
|
const entryFromStorageTransform = async (context, model, entry) => {
|
|
73
86
|
return entryStorageTransform(context, model, "fromStorage", entry);
|
|
74
87
|
};
|
|
88
|
+
|
|
75
89
|
exports.entryFromStorageTransform = entryFromStorageTransform;
|
|
90
|
+
|
|
76
91
|
/*
|
|
77
92
|
* A function that is used to transform a single field from storage
|
|
78
93
|
*/
|
|
@@ -84,12 +99,12 @@ const entryFieldFromStorageTransform = async params => {
|
|
|
84
99
|
value
|
|
85
100
|
} = params;
|
|
86
101
|
const getStoragePlugin = getStoragePluginFactory(context);
|
|
87
|
-
const plugin = getStoragePlugin(field.type);
|
|
102
|
+
const plugin = getStoragePlugin(field.type); // TODO: remove this once plugins are converted into classes
|
|
88
103
|
|
|
89
|
-
// TODO: remove this once plugins are converted into classes
|
|
90
104
|
if (typeof plugin.fromStorage !== "function") {
|
|
91
105
|
throw new _error.default(`Missing "fromStorage" function in storage plugin "${plugin.name}" for field type "${field.type}"`);
|
|
92
106
|
}
|
|
107
|
+
|
|
93
108
|
return plugin.fromStorage({
|
|
94
109
|
plugins: context.plugins,
|
|
95
110
|
model,
|
|
@@ -98,4 +113,5 @@ const entryFieldFromStorageTransform = async params => {
|
|
|
98
113
|
getStoragePlugin
|
|
99
114
|
});
|
|
100
115
|
};
|
|
116
|
+
|
|
101
117
|
exports.entryFieldFromStorageTransform = entryFieldFromStorageTransform;
|
|
@@ -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 // check if it's a default plugin\n if (plugin.fieldType === \"*\" && !defaultStoragePlugin) {\n defaultStoragePlugin = plugin;\n return collection;\n }\n\n /**\n * either existing plugin added or plugin fieldType does not exist in current model\n * this is to iterate a bit less later\n */\n if (!collection[plugin.fieldType]) {\n collection[plugin.fieldType] = plugin;\n }\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 plugin = getStoragePlugin(field.type);\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 \"${field.type}\"`\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 plugin = getStoragePlugin(field.type);\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 \"${field.type}\"`\n );\n }\n\n return plugin.fromStorage({\n plugins: context.plugins,\n model,\n field,\n value,\n getStoragePlugin\n });\n};\n"],"mappings":"
|
|
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 // check if it's a default plugin\n if (plugin.fieldType === \"*\" && !defaultStoragePlugin) {\n defaultStoragePlugin = plugin;\n return collection;\n }\n\n /**\n * either existing plugin added or plugin fieldType does not exist in current model\n * this is to iterate a bit less later\n */\n if (!collection[plugin.fieldType]) {\n collection[plugin.fieldType] = plugin;\n }\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 plugin = getStoragePlugin(field.type);\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 \"${field.type}\"`\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 plugin = getStoragePlugin(field.type);\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 \"${field.type}\"`\n );\n }\n\n return plugin.fromStorage({\n plugins: context.plugins,\n model,\n field,\n value,\n getStoragePlugin\n });\n};\n"],"mappings":"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"}
|
package/utils/filterAsync.js
CHANGED
|
@@ -4,15 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.filterAsync = void 0;
|
|
7
|
+
|
|
7
8
|
const filterAsync = async (items, predicate) => {
|
|
8
9
|
const filteredItems = [];
|
|
10
|
+
|
|
9
11
|
for (let i = 0; i < items.length; i++) {
|
|
10
12
|
const item = items[i];
|
|
11
13
|
const valid = await predicate(item);
|
|
14
|
+
|
|
12
15
|
if (valid) {
|
|
13
16
|
filteredItems.push(item);
|
|
14
17
|
}
|
|
15
18
|
}
|
|
19
|
+
|
|
16
20
|
return filteredItems;
|
|
17
21
|
};
|
|
22
|
+
|
|
18
23
|
exports.filterAsync = filterAsync;
|
package/utils/filterAsync.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["filterAsync","items","predicate","filteredItems","i","length","item","valid","push"],"sources":["filterAsync.ts"],"sourcesContent":["export const filterAsync = async <T = Record<string, any>>(\n items: T[],\n predicate: (param: T) => Promise<boolean>\n): Promise<T[]> => {\n const filteredItems = [];\n\n for (let i = 0; i < items.length; i++) {\n const item = items[i];\n const valid = await predicate(item);\n if (valid) {\n filteredItems.push(item);\n }\n }\n\n return filteredItems;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["filterAsync","items","predicate","filteredItems","i","length","item","valid","push"],"sources":["filterAsync.ts"],"sourcesContent":["export const filterAsync = async <T = Record<string, any>>(\n items: T[],\n predicate: (param: T) => Promise<boolean>\n): Promise<T[]> => {\n const filteredItems = [];\n\n for (let i = 0; i < items.length; i++) {\n const item = items[i];\n const valid = await predicate(item);\n if (valid) {\n filteredItems.push(item);\n }\n }\n\n return filteredItems;\n};\n"],"mappings":";;;;;;;AAAO,MAAMA,WAAW,GAAG,OACvBC,KADuB,EAEvBC,SAFuB,KAGR;EACf,MAAMC,aAAa,GAAG,EAAtB;;EAEA,KAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGH,KAAK,CAACI,MAA1B,EAAkCD,CAAC,EAAnC,EAAuC;IACnC,MAAME,IAAI,GAAGL,KAAK,CAACG,CAAD,CAAlB;IACA,MAAMG,KAAK,GAAG,MAAML,SAAS,CAACI,IAAD,CAA7B;;IACA,IAAIC,KAAJ,EAAW;MACPJ,aAAa,CAACK,IAAd,CAAmBF,IAAnB;IACH;EACJ;;EAED,OAAOH,aAAP;AACH,CAfM"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
7
8
|
exports.filterModelsDeletedFields = void 0;
|
|
9
|
+
|
|
8
10
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
9
12
|
/**
|
|
10
13
|
* We are leaving this file because isDeleted might come back later
|
|
11
14
|
*/
|
|
@@ -16,10 +19,10 @@ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/obje
|
|
|
16
19
|
*
|
|
17
20
|
* Used to recursively delete fields - object field.
|
|
18
21
|
*/
|
|
19
|
-
|
|
20
22
|
const filterDeletedFields = params => {
|
|
21
23
|
return params.fields.reduce((output, field) => {
|
|
22
24
|
var _field$settings;
|
|
25
|
+
|
|
23
26
|
if (!!field.isDeleted) {
|
|
24
27
|
return output;
|
|
25
28
|
} else if ((_field$settings = field.settings) !== null && _field$settings !== void 0 && _field$settings.fields) {
|
|
@@ -33,15 +36,16 @@ const filterDeletedFields = params => {
|
|
|
33
36
|
}));
|
|
34
37
|
return output;
|
|
35
38
|
}
|
|
39
|
+
|
|
36
40
|
output.push(field);
|
|
37
41
|
return output;
|
|
38
42
|
}, []);
|
|
39
43
|
};
|
|
40
|
-
|
|
41
44
|
/**
|
|
42
45
|
* Filters deleted fields from given model.
|
|
43
46
|
*/
|
|
44
47
|
|
|
48
|
+
|
|
45
49
|
const filterModelDeletedFields = ({
|
|
46
50
|
model
|
|
47
51
|
}) => {
|
|
@@ -50,11 +54,11 @@ const filterModelDeletedFields = ({
|
|
|
50
54
|
fields
|
|
51
55
|
});
|
|
52
56
|
};
|
|
53
|
-
|
|
54
57
|
/**
|
|
55
58
|
* Filters deleted fields from all given models.
|
|
56
59
|
*/
|
|
57
60
|
|
|
61
|
+
|
|
58
62
|
const filterModelsDeletedFields = ({
|
|
59
63
|
models,
|
|
60
64
|
type
|
|
@@ -62,10 +66,12 @@ const filterModelsDeletedFields = ({
|
|
|
62
66
|
if (type === "manage") {
|
|
63
67
|
return models;
|
|
64
68
|
}
|
|
69
|
+
|
|
65
70
|
return models.map(model => {
|
|
66
71
|
return filterModelDeletedFields({
|
|
67
72
|
model
|
|
68
73
|
});
|
|
69
74
|
});
|
|
70
75
|
};
|
|
76
|
+
|
|
71
77
|
exports.filterModelsDeletedFields = filterModelsDeletedFields;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["filterDeletedFields","params","fields","reduce","output","field","isDeleted","settings","push","filterModelDeletedFields","model","filterModelsDeletedFields","models","type","map"],"sources":["filterModelFields.ts"],"sourcesContent":["/**\n * We are leaving this file because isDeleted might come back later\n */\n// @ts-nocheck\nimport { ApiEndpoint, CmsModel, CmsModelField } from \"~/types\";\n\n/**\n * Filters deleted fields from the list of fields.\n *\n * Used to recursively delete fields - object field.\n */\ninterface FilterModelFieldsCallableParams {\n fields: CmsModelField[];\n}\ninterface FilterModelFieldsCallable {\n (params: FilterModelFieldsCallableParams): CmsModelField[];\n}\n\nconst filterDeletedFields: FilterModelFieldsCallable = params => {\n return params.fields.reduce<CmsModelField[]>((output, field) => {\n if (!!field.isDeleted) {\n return output;\n } else if (field.settings?.fields) {\n const fields = filterDeletedFields({\n fields: field.settings.fields\n });\n\n output.push({\n ...field,\n settings: {\n ...field.settings,\n fields\n }\n });\n return output;\n }\n\n output.push(field);\n\n return output;\n }, []);\n};\n\n/**\n * Filters deleted fields from given model.\n */\ninterface FilterModelDeletedFieldsCallableParams {\n model: CmsModel;\n}\ninterface FilterModelDeletedFieldsCallable {\n (params: FilterModelDeletedFieldsCallableParams): CmsModel;\n}\nconst filterModelDeletedFields: FilterModelDeletedFieldsCallable = ({ model }) => {\n const fields = filterDeletedFields(model);\n return {\n ...model,\n fields\n };\n};\n\n/**\n * Filters deleted fields from all given models.\n */\ninterface FilterModelsDeletedFieldsCallableParams {\n models: CmsModel[];\n type: ApiEndpoint;\n}\ninterface FilterModelsDeletedFieldsCallable {\n (params: FilterModelsDeletedFieldsCallableParams): CmsModel[];\n}\nexport const filterModelsDeletedFields: FilterModelsDeletedFieldsCallable = ({ models, type }) => {\n if (type === \"manage\") {\n return models;\n }\n return models.map(model => {\n return filterModelDeletedFields({\n model\n });\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["filterDeletedFields","params","fields","reduce","output","field","isDeleted","settings","push","filterModelDeletedFields","model","filterModelsDeletedFields","models","type","map"],"sources":["filterModelFields.ts"],"sourcesContent":["/**\n * We are leaving this file because isDeleted might come back later\n */\n// @ts-nocheck\nimport { ApiEndpoint, CmsModel, CmsModelField } from \"~/types\";\n\n/**\n * Filters deleted fields from the list of fields.\n *\n * Used to recursively delete fields - object field.\n */\ninterface FilterModelFieldsCallableParams {\n fields: CmsModelField[];\n}\ninterface FilterModelFieldsCallable {\n (params: FilterModelFieldsCallableParams): CmsModelField[];\n}\n\nconst filterDeletedFields: FilterModelFieldsCallable = params => {\n return params.fields.reduce<CmsModelField[]>((output, field) => {\n if (!!field.isDeleted) {\n return output;\n } else if (field.settings?.fields) {\n const fields = filterDeletedFields({\n fields: field.settings.fields\n });\n\n output.push({\n ...field,\n settings: {\n ...field.settings,\n fields\n }\n });\n return output;\n }\n\n output.push(field);\n\n return output;\n }, []);\n};\n\n/**\n * Filters deleted fields from given model.\n */\ninterface FilterModelDeletedFieldsCallableParams {\n model: CmsModel;\n}\ninterface FilterModelDeletedFieldsCallable {\n (params: FilterModelDeletedFieldsCallableParams): CmsModel;\n}\nconst filterModelDeletedFields: FilterModelDeletedFieldsCallable = ({ model }) => {\n const fields = filterDeletedFields(model);\n return {\n ...model,\n fields\n };\n};\n\n/**\n * Filters deleted fields from all given models.\n */\ninterface FilterModelsDeletedFieldsCallableParams {\n models: CmsModel[];\n type: ApiEndpoint;\n}\ninterface FilterModelsDeletedFieldsCallable {\n (params: FilterModelsDeletedFieldsCallableParams): CmsModel[];\n}\nexport const filterModelsDeletedFields: FilterModelsDeletedFieldsCallable = ({ models, type }) => {\n if (type === \"manage\") {\n return models;\n }\n return models.map(model => {\n return filterModelDeletedFields({\n model\n });\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AAQA,MAAMA,mBAA8C,GAAGC,MAAM,IAAI;EAC7D,OAAOA,MAAM,CAACC,MAAP,CAAcC,MAAd,CAAsC,CAACC,MAAD,EAASC,KAAT,KAAmB;IAAA;;IAC5D,IAAI,CAAC,CAACA,KAAK,CAACC,SAAZ,EAAuB;MACnB,OAAOF,MAAP;IACH,CAFD,MAEO,uBAAIC,KAAK,CAACE,QAAV,4CAAI,gBAAgBL,MAApB,EAA4B;MAC/B,MAAMA,MAAM,GAAGF,mBAAmB,CAAC;QAC/BE,MAAM,EAAEG,KAAK,CAACE,QAAN,CAAeL;MADQ,CAAD,CAAlC;MAIAE,MAAM,CAACI,IAAP,6DACOH,KADP;QAEIE,QAAQ,8DACDF,KAAK,CAACE,QADL;UAEJL;QAFI;MAFZ;MAOA,OAAOE,MAAP;IACH;;IAEDA,MAAM,CAACI,IAAP,CAAYH,KAAZ;IAEA,OAAOD,MAAP;EACH,CArBM,EAqBJ,EArBI,CAAP;AAsBH,CAvBD;AAyBA;AACA;AACA;;;AAOA,MAAMK,wBAA0D,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAe;EAC9E,MAAMR,MAAM,GAAGF,mBAAmB,CAACU,KAAD,CAAlC;EACA,mEACOA,KADP;IAEIR;EAFJ;AAIH,CAND;AAQA;AACA;AACA;;;AAQO,MAAMS,yBAA4D,GAAG,CAAC;EAAEC,MAAF;EAAUC;AAAV,CAAD,KAAsB;EAC9F,IAAIA,IAAI,KAAK,QAAb,EAAuB;IACnB,OAAOD,MAAP;EACH;;EACD,OAAOA,MAAM,CAACE,GAAP,CAAWJ,KAAK,IAAI;IACvB,OAAOD,wBAAwB,CAAC;MAC5BC;IAD4B,CAAD,CAA/B;EAGH,CAJM,CAAP;AAKH,CATM"}
|
package/utils/getEntryTitle.js
CHANGED
|
@@ -4,31 +4,40 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getEntryTitle = getEntryTitle;
|
|
7
|
+
|
|
7
8
|
function getEntryTitle(model, entry) {
|
|
8
9
|
if (!model.titleFieldId) {
|
|
9
10
|
return entry.id;
|
|
10
11
|
}
|
|
12
|
+
|
|
11
13
|
const field = model.fields.find(f => f.fieldId === model.titleFieldId);
|
|
14
|
+
|
|
12
15
|
if (!field) {
|
|
13
16
|
return entry.id;
|
|
14
17
|
}
|
|
18
|
+
|
|
15
19
|
const titleFieldId = field.fieldId;
|
|
16
20
|
const titleValue = entry.values[titleFieldId];
|
|
21
|
+
|
|
17
22
|
if (!titleValue) {
|
|
18
23
|
return entry.id;
|
|
19
24
|
}
|
|
25
|
+
|
|
20
26
|
const {
|
|
21
27
|
enabled = false,
|
|
22
28
|
values
|
|
23
29
|
} = field.predefinedValues || {};
|
|
30
|
+
|
|
24
31
|
if (!enabled || !values || Array.isArray(values) === false) {
|
|
25
32
|
return titleValue;
|
|
26
33
|
}
|
|
34
|
+
|
|
27
35
|
for (const value of values) {
|
|
28
36
|
// needs to be loose because titleValue can be a number and value can be a string - but it must match
|
|
29
37
|
if (value.value == titleValue) {
|
|
30
38
|
return value.label;
|
|
31
39
|
}
|
|
32
40
|
}
|
|
41
|
+
|
|
33
42
|
return titleValue;
|
|
34
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getEntryTitle","model","entry","titleFieldId","id","field","fields","find","f","fieldId","titleValue","values","enabled","predefinedValues","Array","isArray","value","label"],"sources":["getEntryTitle.ts"],"sourcesContent":["import { CmsEntry, CmsModel } from \"~/types\";\n\nexport function getEntryTitle(model: CmsModel, entry: CmsEntry): string {\n if (!model.titleFieldId) {\n return entry.id;\n }\n const field = model.fields.find(f => f.fieldId === model.titleFieldId);\n if (!field) {\n return entry.id;\n }\n const titleFieldId = field.fieldId;\n const titleValue = entry.values[titleFieldId];\n if (!titleValue) {\n return entry.id;\n }\n\n const { enabled = false, values } = field.predefinedValues || {};\n if (!enabled || !values || Array.isArray(values) === false) {\n return titleValue;\n }\n for (const value of values) {\n // needs to be loose because titleValue can be a number and value can be a string - but it must match\n if (value.value == titleValue) {\n return value.label;\n }\n }\n return titleValue;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["getEntryTitle","model","entry","titleFieldId","id","field","fields","find","f","fieldId","titleValue","values","enabled","predefinedValues","Array","isArray","value","label"],"sources":["getEntryTitle.ts"],"sourcesContent":["import { CmsEntry, CmsModel } from \"~/types\";\n\nexport function getEntryTitle(model: CmsModel, entry: CmsEntry): string {\n if (!model.titleFieldId) {\n return entry.id;\n }\n const field = model.fields.find(f => f.fieldId === model.titleFieldId);\n if (!field) {\n return entry.id;\n }\n const titleFieldId = field.fieldId;\n const titleValue = entry.values[titleFieldId];\n if (!titleValue) {\n return entry.id;\n }\n\n const { enabled = false, values } = field.predefinedValues || {};\n if (!enabled || !values || Array.isArray(values) === false) {\n return titleValue;\n }\n for (const value of values) {\n // needs to be loose because titleValue can be a number and value can be a string - but it must match\n if (value.value == titleValue) {\n return value.label;\n }\n }\n return titleValue;\n}\n"],"mappings":";;;;;;;AAEO,SAASA,aAAT,CAAuBC,KAAvB,EAAwCC,KAAxC,EAAiE;EACpE,IAAI,CAACD,KAAK,CAACE,YAAX,EAAyB;IACrB,OAAOD,KAAK,CAACE,EAAb;EACH;;EACD,MAAMC,KAAK,GAAGJ,KAAK,CAACK,MAAN,CAAaC,IAAb,CAAkBC,CAAC,IAAIA,CAAC,CAACC,OAAF,KAAcR,KAAK,CAACE,YAA3C,CAAd;;EACA,IAAI,CAACE,KAAL,EAAY;IACR,OAAOH,KAAK,CAACE,EAAb;EACH;;EACD,MAAMD,YAAY,GAAGE,KAAK,CAACI,OAA3B;EACA,MAAMC,UAAU,GAAGR,KAAK,CAACS,MAAN,CAAaR,YAAb,CAAnB;;EACA,IAAI,CAACO,UAAL,EAAiB;IACb,OAAOR,KAAK,CAACE,EAAb;EACH;;EAED,MAAM;IAAEQ,OAAO,GAAG,KAAZ;IAAmBD;EAAnB,IAA8BN,KAAK,CAACQ,gBAAN,IAA0B,EAA9D;;EACA,IAAI,CAACD,OAAD,IAAY,CAACD,MAAb,IAAuBG,KAAK,CAACC,OAAN,CAAcJ,MAAd,MAA0B,KAArD,EAA4D;IACxD,OAAOD,UAAP;EACH;;EACD,KAAK,MAAMM,KAAX,IAAoBL,MAApB,EAA4B;IACxB;IACA,IAAIK,KAAK,CAACA,KAAN,IAAeN,UAAnB,EAA+B;MAC3B,OAAOM,KAAK,CAACC,KAAb;IACH;EACJ;;EACD,OAAOP,UAAP;AACH"}
|
|
@@ -9,6 +9,7 @@ const TYPE_MAP = {
|
|
|
9
9
|
read: "read",
|
|
10
10
|
manage: "manage"
|
|
11
11
|
};
|
|
12
|
+
|
|
12
13
|
const getSchemaFromFieldPlugins = ({
|
|
13
14
|
models,
|
|
14
15
|
fieldTypePlugins,
|
|
@@ -18,14 +19,17 @@ const getSchemaFromFieldPlugins = ({
|
|
|
18
19
|
if (!TYPE_MAP[type] || !plugin[TYPE_MAP[type]]) {
|
|
19
20
|
return null;
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
// Render gql types generated by field type plugins
|
|
22
|
+
|
|
23
|
+
const createSchema = plugin[TYPE_MAP[type]].createSchema; // Render gql types generated by field type plugins
|
|
24
|
+
|
|
23
25
|
if (!createSchema) {
|
|
24
26
|
return null;
|
|
25
27
|
}
|
|
28
|
+
|
|
26
29
|
return createSchema({
|
|
27
30
|
models
|
|
28
31
|
});
|
|
29
32
|
}).filter(Boolean);
|
|
30
33
|
};
|
|
34
|
+
|
|
31
35
|
exports.getSchemaFromFieldPlugins = getSchemaFromFieldPlugins;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TYPE_MAP","preview","read","manage","getSchemaFromFieldPlugins","models","fieldTypePlugins","type","Object","values","map","plugin","createSchema","filter","Boolean"],"sources":["getSchemaFromFieldPlugins.ts"],"sourcesContent":["import { CmsModel, CmsContext, CmsFieldTypePlugins, ApiEndpoint } from \"~/types\";\nimport { GraphQLSchemaDefinition } from \"@webiny/handler-graphql/types\";\n\ninterface RenderTypesFromFieldPluginsParams {\n models: CmsModel[];\n fieldTypePlugins: CmsFieldTypePlugins;\n type: ApiEndpoint;\n}\ninterface RenderTypesFromFieldPlugins {\n (params: RenderTypesFromFieldPluginsParams): GraphQLSchemaDefinition<CmsContext>[];\n}\n\nconst TYPE_MAP: Record<string, \"manage\" | \"read\"> = {\n preview: \"read\",\n read: \"read\",\n manage: \"manage\"\n};\n\nexport const getSchemaFromFieldPlugins: RenderTypesFromFieldPlugins = ({\n models,\n fieldTypePlugins,\n type\n}) => {\n return Object.values(fieldTypePlugins)\n .map(plugin => {\n if (!TYPE_MAP[type] || !plugin[TYPE_MAP[type]]) {\n return null;\n }\n const createSchema = plugin[TYPE_MAP[type]].createSchema;\n // Render gql types generated by field type plugins\n if (!createSchema) {\n return null;\n }\n return createSchema({ models });\n })\n .filter(Boolean) as GraphQLSchemaDefinition<CmsContext>[];\n};\n"],"mappings":";;;;;;AAYA,MAAMA,QAA2C,GAAG;EAChDC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"names":["TYPE_MAP","preview","read","manage","getSchemaFromFieldPlugins","models","fieldTypePlugins","type","Object","values","map","plugin","createSchema","filter","Boolean"],"sources":["getSchemaFromFieldPlugins.ts"],"sourcesContent":["import { CmsModel, CmsContext, CmsFieldTypePlugins, ApiEndpoint } from \"~/types\";\nimport { GraphQLSchemaDefinition } from \"@webiny/handler-graphql/types\";\n\ninterface RenderTypesFromFieldPluginsParams {\n models: CmsModel[];\n fieldTypePlugins: CmsFieldTypePlugins;\n type: ApiEndpoint;\n}\ninterface RenderTypesFromFieldPlugins {\n (params: RenderTypesFromFieldPluginsParams): GraphQLSchemaDefinition<CmsContext>[];\n}\n\nconst TYPE_MAP: Record<string, \"manage\" | \"read\"> = {\n preview: \"read\",\n read: \"read\",\n manage: \"manage\"\n};\n\nexport const getSchemaFromFieldPlugins: RenderTypesFromFieldPlugins = ({\n models,\n fieldTypePlugins,\n type\n}) => {\n return Object.values(fieldTypePlugins)\n .map(plugin => {\n if (!TYPE_MAP[type] || !plugin[TYPE_MAP[type]]) {\n return null;\n }\n const createSchema = plugin[TYPE_MAP[type]].createSchema;\n // Render gql types generated by field type plugins\n if (!createSchema) {\n return null;\n }\n return createSchema({ models });\n })\n .filter(Boolean) as GraphQLSchemaDefinition<CmsContext>[];\n};\n"],"mappings":";;;;;;AAYA,MAAMA,QAA2C,GAAG;EAChDC,OAAO,EAAE,MADuC;EAEhDC,IAAI,EAAE,MAF0C;EAGhDC,MAAM,EAAE;AAHwC,CAApD;;AAMO,MAAMC,yBAAsD,GAAG,CAAC;EACnEC,MADmE;EAEnEC,gBAFmE;EAGnEC;AAHmE,CAAD,KAIhE;EACF,OAAOC,MAAM,CAACC,MAAP,CAAcH,gBAAd,EACFI,GADE,CACEC,MAAM,IAAI;IACX,IAAI,CAACX,QAAQ,CAACO,IAAD,CAAT,IAAmB,CAACI,MAAM,CAACX,QAAQ,CAACO,IAAD,CAAT,CAA9B,EAAgD;MAC5C,OAAO,IAAP;IACH;;IACD,MAAMK,YAAY,GAAGD,MAAM,CAACX,QAAQ,CAACO,IAAD,CAAT,CAAN,CAAuBK,YAA5C,CAJW,CAKX;;IACA,IAAI,CAACA,YAAL,EAAmB;MACf,OAAO,IAAP;IACH;;IACD,OAAOA,YAAY,CAAC;MAAEP;IAAF,CAAD,CAAnB;EACH,CAXE,EAYFQ,MAZE,CAYKC,OAZL,CAAP;AAaH,CAlBM"}
|
package/utils/ownership.js
CHANGED
|
@@ -4,15 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.validateOwnership = exports.checkOwnership = void 0;
|
|
7
|
+
|
|
7
8
|
var _apiSecurity = require("@webiny/api-security");
|
|
9
|
+
|
|
8
10
|
const checkOwnership = (context, permission, record) => {
|
|
9
11
|
var _record$ownedBy, _record$createdBy;
|
|
12
|
+
|
|
10
13
|
if (!permission.own) {
|
|
11
14
|
return;
|
|
12
15
|
}
|
|
16
|
+
|
|
13
17
|
const identity = context.security.getIdentity();
|
|
14
18
|
const owner = identity && ((_record$ownedBy = record.ownedBy) === null || _record$ownedBy === void 0 ? void 0 : _record$ownedBy.id) === identity.id;
|
|
15
19
|
const creator = identity && ((_record$createdBy = record.createdBy) === null || _record$createdBy === void 0 ? void 0 : _record$createdBy.id) === identity.id;
|
|
20
|
+
|
|
16
21
|
if (!owner && !creator) {
|
|
17
22
|
throw new _apiSecurity.NotAuthorizedError({
|
|
18
23
|
data: {
|
|
@@ -21,7 +26,9 @@ const checkOwnership = (context, permission, record) => {
|
|
|
21
26
|
});
|
|
22
27
|
}
|
|
23
28
|
};
|
|
29
|
+
|
|
24
30
|
exports.checkOwnership = checkOwnership;
|
|
31
|
+
|
|
25
32
|
const validateOwnership = (context, permission, record) => {
|
|
26
33
|
try {
|
|
27
34
|
checkOwnership(context, permission, record);
|
|
@@ -30,4 +37,5 @@ const validateOwnership = (context, permission, record) => {
|
|
|
30
37
|
return false;
|
|
31
38
|
}
|
|
32
39
|
};
|
|
40
|
+
|
|
33
41
|
exports.validateOwnership = validateOwnership;
|
package/utils/ownership.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["checkOwnership","context","permission","record","own","identity","security","getIdentity","owner","ownedBy","id","creator","createdBy","NotAuthorizedError","data","reason","validateOwnership"],"sources":["ownership.ts"],"sourcesContent":["import { BaseCmsSecurityPermission, CmsContext, CreatedBy } from \"~/types\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\n\ninterface OwnableRecord {\n createdBy?: CreatedBy;\n ownedBy?: CreatedBy;\n}\n\nexport const checkOwnership = (\n context: CmsContext,\n permission: BaseCmsSecurityPermission,\n record: OwnableRecord\n): void => {\n if (!permission.own) {\n return;\n }\n\n const identity = context.security.getIdentity();\n const owner = identity && record.ownedBy?.id === identity.id;\n const creator = identity && record.createdBy?.id === identity.id;\n\n if (!owner && !creator) {\n throw new NotAuthorizedError({\n data: {\n reason: `You are not the owner of the record.`\n }\n });\n }\n};\n\nexport const validateOwnership = (\n context: CmsContext,\n permission: BaseCmsSecurityPermission,\n record: OwnableRecord\n): boolean => {\n try {\n checkOwnership(context, permission, record);\n return true;\n } catch {\n return false;\n }\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["checkOwnership","context","permission","record","own","identity","security","getIdentity","owner","ownedBy","id","creator","createdBy","NotAuthorizedError","data","reason","validateOwnership"],"sources":["ownership.ts"],"sourcesContent":["import { BaseCmsSecurityPermission, CmsContext, CreatedBy } from \"~/types\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\n\ninterface OwnableRecord {\n createdBy?: CreatedBy;\n ownedBy?: CreatedBy;\n}\n\nexport const checkOwnership = (\n context: CmsContext,\n permission: BaseCmsSecurityPermission,\n record: OwnableRecord\n): void => {\n if (!permission.own) {\n return;\n }\n\n const identity = context.security.getIdentity();\n const owner = identity && record.ownedBy?.id === identity.id;\n const creator = identity && record.createdBy?.id === identity.id;\n\n if (!owner && !creator) {\n throw new NotAuthorizedError({\n data: {\n reason: `You are not the owner of the record.`\n }\n });\n }\n};\n\nexport const validateOwnership = (\n context: CmsContext,\n permission: BaseCmsSecurityPermission,\n record: OwnableRecord\n): boolean => {\n try {\n checkOwnership(context, permission, record);\n return true;\n } catch {\n return false;\n }\n};\n"],"mappings":";;;;;;;AACA;;AAOO,MAAMA,cAAc,GAAG,CAC1BC,OAD0B,EAE1BC,UAF0B,EAG1BC,MAH0B,KAInB;EAAA;;EACP,IAAI,CAACD,UAAU,CAACE,GAAhB,EAAqB;IACjB;EACH;;EAED,MAAMC,QAAQ,GAAGJ,OAAO,CAACK,QAAR,CAAiBC,WAAjB,EAAjB;EACA,MAAMC,KAAK,GAAGH,QAAQ,IAAI,oBAAAF,MAAM,CAACM,OAAP,oEAAgBC,EAAhB,MAAuBL,QAAQ,CAACK,EAA1D;EACA,MAAMC,OAAO,GAAGN,QAAQ,IAAI,sBAAAF,MAAM,CAACS,SAAP,wEAAkBF,EAAlB,MAAyBL,QAAQ,CAACK,EAA9D;;EAEA,IAAI,CAACF,KAAD,IAAU,CAACG,OAAf,EAAwB;IACpB,MAAM,IAAIE,+BAAJ,CAAuB;MACzBC,IAAI,EAAE;QACFC,MAAM,EAAG;MADP;IADmB,CAAvB,CAAN;EAKH;AACJ,CApBM;;;;AAsBA,MAAMC,iBAAiB,GAAG,CAC7Bf,OAD6B,EAE7BC,UAF6B,EAG7BC,MAH6B,KAInB;EACV,IAAI;IACAH,cAAc,CAACC,OAAD,EAAUC,UAAV,EAAsBC,MAAtB,CAAd;IACA,OAAO,IAAP;EACH,CAHD,CAGE,MAAM;IACJ,OAAO,KAAP;EACH;AACJ,CAXM"}
|
package/utils/permissions.js
CHANGED
|
@@ -4,14 +4,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.hasRwd = exports.hasPw = exports.checkPermissions = void 0;
|
|
7
|
+
|
|
7
8
|
var _apiSecurity = require("@webiny/api-security");
|
|
9
|
+
|
|
8
10
|
const hasRwd = (permission, rwd) => {
|
|
9
11
|
if (typeof permission.rwd !== "string") {
|
|
10
12
|
return true;
|
|
11
13
|
}
|
|
14
|
+
|
|
12
15
|
return permission.rwd.includes(rwd);
|
|
13
16
|
};
|
|
17
|
+
|
|
14
18
|
exports.hasRwd = hasRwd;
|
|
19
|
+
|
|
15
20
|
const hasPw = (permission, pw) => {
|
|
16
21
|
const isCustom = Object.keys(permission).length > 1; // "name" key is always present
|
|
17
22
|
|
|
@@ -19,11 +24,14 @@ const hasPw = (permission, pw) => {
|
|
|
19
24
|
// Means it's a "full-access" permission.
|
|
20
25
|
return true;
|
|
21
26
|
}
|
|
27
|
+
|
|
22
28
|
if (typeof permission.pw !== "string") {
|
|
23
29
|
return false;
|
|
24
30
|
}
|
|
31
|
+
|
|
25
32
|
return permission.pw.includes(pw);
|
|
26
33
|
};
|
|
34
|
+
|
|
27
35
|
exports.hasPw = hasPw;
|
|
28
36
|
const PW = {
|
|
29
37
|
p: "publish",
|
|
@@ -34,23 +42,24 @@ const RWD = {
|
|
|
34
42
|
w: "write",
|
|
35
43
|
d: "delete"
|
|
36
44
|
};
|
|
45
|
+
|
|
37
46
|
const checkPermissions = async (context, name, check) => {
|
|
38
47
|
// Check if user is allowed to edit content in current language
|
|
39
48
|
const contentPermission = await context.security.getPermission("content.i18n");
|
|
49
|
+
|
|
40
50
|
if (!contentPermission) {
|
|
41
51
|
throw new _apiSecurity.NotAuthorizedError({
|
|
42
52
|
data: {
|
|
43
53
|
reason: "Missing access to content in any locale."
|
|
44
54
|
}
|
|
45
55
|
});
|
|
46
|
-
}
|
|
56
|
+
} // We need to check this manually as CMS locale comes from the URL and not the default i18n app.
|
|
47
57
|
|
|
48
|
-
// We need to check this manually as CMS locale comes from the URL and not the default i18n app.
|
|
49
|
-
const code = context.cms.getLocale().code;
|
|
50
|
-
const locales = contentPermission.locales;
|
|
51
58
|
|
|
52
|
-
|
|
59
|
+
const code = context.cms.getLocale().code;
|
|
60
|
+
const locales = contentPermission.locales; // IMPORTANT: If we have a `contentPermission`, and `locales` key is NOT SET - it means the user has access to all locales.
|
|
53
61
|
// However, if the the `locales` IS SET - check that it contains the required locale.
|
|
62
|
+
|
|
54
63
|
if (Array.isArray(locales) && !locales.includes(code)) {
|
|
55
64
|
throw new _apiSecurity.NotAuthorizedError({
|
|
56
65
|
data: {
|
|
@@ -58,7 +67,9 @@ const checkPermissions = async (context, name, check) => {
|
|
|
58
67
|
}
|
|
59
68
|
});
|
|
60
69
|
}
|
|
70
|
+
|
|
61
71
|
const permission = await context.security.getPermission(name);
|
|
72
|
+
|
|
62
73
|
if (!permission) {
|
|
63
74
|
throw new _apiSecurity.NotAuthorizedError({
|
|
64
75
|
data: {
|
|
@@ -66,19 +77,21 @@ const checkPermissions = async (context, name, check) => {
|
|
|
66
77
|
}
|
|
67
78
|
});
|
|
68
79
|
}
|
|
80
|
+
|
|
69
81
|
if (!check) {
|
|
70
82
|
return permission;
|
|
71
83
|
}
|
|
84
|
+
|
|
72
85
|
if (check.rwd && !hasRwd(permission, check.rwd)) {
|
|
73
86
|
throw new _apiSecurity.NotAuthorizedError({
|
|
74
87
|
data: {
|
|
75
88
|
reason: `Not allowed to perform "${RWD[check.rwd]}" on "${name}".`
|
|
76
89
|
}
|
|
77
90
|
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// p = publish
|
|
91
|
+
} // p = publish
|
|
81
92
|
// u = unpublish
|
|
93
|
+
|
|
94
|
+
|
|
82
95
|
if (check.pw && !hasPw(permission, check.pw)) {
|
|
83
96
|
throw new _apiSecurity.NotAuthorizedError({
|
|
84
97
|
data: {
|
|
@@ -86,6 +99,8 @@ const checkPermissions = async (context, name, check) => {
|
|
|
86
99
|
}
|
|
87
100
|
});
|
|
88
101
|
}
|
|
102
|
+
|
|
89
103
|
return permission;
|
|
90
104
|
};
|
|
105
|
+
|
|
91
106
|
exports.checkPermissions = checkPermissions;
|
package/utils/permissions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["hasRwd","permission","rwd","includes","hasPw","pw","isCustom","Object","keys","length","PW","p","u","RWD","r","w","d","checkPermissions","context","name","check","contentPermission","security","getPermission","NotAuthorizedError","data","reason","code","cms","getLocale","locales","Array","isArray"],"sources":["permissions.ts"],"sourcesContent":["import { BaseCmsSecurityPermission, CmsContext, CmsEntryPermission } from \"~/types\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\n\nexport const hasRwd = (permission: BaseCmsSecurityPermission, rwd: string): boolean => {\n if (typeof permission.rwd !== \"string\") {\n return true;\n }\n\n return permission.rwd.includes(rwd);\n};\n\nexport const hasPw = (permission: CmsEntryPermission, pw: string): boolean => {\n const isCustom = Object.keys(permission).length > 1; // \"name\" key is always present\n\n if (!isCustom) {\n // Means it's a \"full-access\" permission.\n return true;\n }\n\n if (typeof permission.pw !== \"string\") {\n return false;\n }\n\n return permission.pw.includes(pw);\n};\n\nconst PW: Record<string, string> = {\n p: \"publish\",\n u: \"unpublish\"\n};\n\nconst RWD: Record<string, string> = {\n r: \"read\",\n w: \"write\",\n d: \"delete\"\n};\n\nexport const checkPermissions = async <\n TPermission extends BaseCmsSecurityPermission = BaseCmsSecurityPermission\n>(\n context: CmsContext,\n name: string,\n check?: { rwd?: string; pw?: string }\n): Promise<TPermission> => {\n // Check if user is allowed to edit content in current language\n const contentPermission = await context.security.getPermission(\"content.i18n\");\n\n if (!contentPermission) {\n throw new NotAuthorizedError({\n data: {\n reason: \"Missing access to content in any locale.\"\n }\n });\n }\n\n // We need to check this manually as CMS locale comes from the URL and not the default i18n app.\n const code = context.cms.getLocale().code;\n\n const locales: string[] = contentPermission.locales;\n\n // IMPORTANT: If we have a `contentPermission`, and `locales` key is NOT SET - it means the user has access to all locales.\n // However, if the the `locales` IS SET - check that it contains the required locale.\n if (Array.isArray(locales) && !locales.includes(code)) {\n throw new NotAuthorizedError({\n data: {\n reason: `Not allowed to access content in \"${code}.\"`\n }\n });\n }\n\n const permission = await context.security.getPermission<TPermission>(name);\n\n if (!permission) {\n throw new NotAuthorizedError({\n data: {\n reason: `Missing permission \"${name}\".`\n }\n });\n }\n\n if (!check) {\n return permission;\n }\n\n if (check.rwd && !hasRwd(permission, check.rwd)) {\n throw new NotAuthorizedError({\n data: {\n reason: `Not allowed to perform \"${RWD[check.rwd]}\" on \"${name}\".`\n }\n });\n }\n\n // p = publish\n // u = unpublish\n if (check.pw && !hasPw(permission, check.pw)) {\n throw new NotAuthorizedError({\n data: {\n reason: `Not allowed to perform \"${PW[check.pw]}\" on \"${name}\".`\n }\n });\n }\n\n return permission;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["hasRwd","permission","rwd","includes","hasPw","pw","isCustom","Object","keys","length","PW","p","u","RWD","r","w","d","checkPermissions","context","name","check","contentPermission","security","getPermission","NotAuthorizedError","data","reason","code","cms","getLocale","locales","Array","isArray"],"sources":["permissions.ts"],"sourcesContent":["import { BaseCmsSecurityPermission, CmsContext, CmsEntryPermission } from \"~/types\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\n\nexport const hasRwd = (permission: BaseCmsSecurityPermission, rwd: string): boolean => {\n if (typeof permission.rwd !== \"string\") {\n return true;\n }\n\n return permission.rwd.includes(rwd);\n};\n\nexport const hasPw = (permission: CmsEntryPermission, pw: string): boolean => {\n const isCustom = Object.keys(permission).length > 1; // \"name\" key is always present\n\n if (!isCustom) {\n // Means it's a \"full-access\" permission.\n return true;\n }\n\n if (typeof permission.pw !== \"string\") {\n return false;\n }\n\n return permission.pw.includes(pw);\n};\n\nconst PW: Record<string, string> = {\n p: \"publish\",\n u: \"unpublish\"\n};\n\nconst RWD: Record<string, string> = {\n r: \"read\",\n w: \"write\",\n d: \"delete\"\n};\n\nexport const checkPermissions = async <\n TPermission extends BaseCmsSecurityPermission = BaseCmsSecurityPermission\n>(\n context: CmsContext,\n name: string,\n check?: { rwd?: string; pw?: string }\n): Promise<TPermission> => {\n // Check if user is allowed to edit content in current language\n const contentPermission = await context.security.getPermission(\"content.i18n\");\n\n if (!contentPermission) {\n throw new NotAuthorizedError({\n data: {\n reason: \"Missing access to content in any locale.\"\n }\n });\n }\n\n // We need to check this manually as CMS locale comes from the URL and not the default i18n app.\n const code = context.cms.getLocale().code;\n\n const locales: string[] = contentPermission.locales;\n\n // IMPORTANT: If we have a `contentPermission`, and `locales` key is NOT SET - it means the user has access to all locales.\n // However, if the the `locales` IS SET - check that it contains the required locale.\n if (Array.isArray(locales) && !locales.includes(code)) {\n throw new NotAuthorizedError({\n data: {\n reason: `Not allowed to access content in \"${code}.\"`\n }\n });\n }\n\n const permission = await context.security.getPermission<TPermission>(name);\n\n if (!permission) {\n throw new NotAuthorizedError({\n data: {\n reason: `Missing permission \"${name}\".`\n }\n });\n }\n\n if (!check) {\n return permission;\n }\n\n if (check.rwd && !hasRwd(permission, check.rwd)) {\n throw new NotAuthorizedError({\n data: {\n reason: `Not allowed to perform \"${RWD[check.rwd]}\" on \"${name}\".`\n }\n });\n }\n\n // p = publish\n // u = unpublish\n if (check.pw && !hasPw(permission, check.pw)) {\n throw new NotAuthorizedError({\n data: {\n reason: `Not allowed to perform \"${PW[check.pw]}\" on \"${name}\".`\n }\n });\n }\n\n return permission;\n};\n"],"mappings":"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"}
|
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
7
8
|
exports.pluralizedTypeName = void 0;
|
|
9
|
+
|
|
8
10
|
var _pluralize = _interopRequireDefault(require("pluralize"));
|
|
11
|
+
|
|
9
12
|
// This will make it so if the content model name is a single capitalized letter
|
|
10
13
|
// Ex. A, pluralizedTypeName will capitalize the name to As, instead of AS
|
|
11
14
|
const pluralizedTypeName = typeName => {
|
|
12
15
|
let pluralizedTypeName;
|
|
16
|
+
|
|
13
17
|
if (typeName.length === 1) {
|
|
14
18
|
pluralizedTypeName = `${typeName}s`;
|
|
15
19
|
} else {
|
|
16
20
|
pluralizedTypeName = (0, _pluralize.default)(typeName);
|
|
17
21
|
}
|
|
22
|
+
|
|
18
23
|
return pluralizedTypeName;
|
|
19
24
|
};
|
|
25
|
+
|
|
20
26
|
exports.pluralizedTypeName = pluralizedTypeName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["pluralizedTypeName","typeName","length","pluralize"],"sources":["pluralizedTypeName.ts"],"sourcesContent":["import pluralize from \"pluralize\";\n\n// This will make it so if the content model name is a single capitalized letter\n// Ex. A, pluralizedTypeName will capitalize the name to As, instead of AS\nexport const pluralizedTypeName = (typeName: string): string => {\n let pluralizedTypeName;\n if (typeName.length === 1) {\n pluralizedTypeName = `${typeName}s`;\n } else {\n pluralizedTypeName = pluralize(typeName);\n }\n return pluralizedTypeName;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["pluralizedTypeName","typeName","length","pluralize"],"sources":["pluralizedTypeName.ts"],"sourcesContent":["import pluralize from \"pluralize\";\n\n// This will make it so if the content model name is a single capitalized letter\n// Ex. A, pluralizedTypeName will capitalize the name to As, instead of AS\nexport const pluralizedTypeName = (typeName: string): string => {\n let pluralizedTypeName;\n if (typeName.length === 1) {\n pluralizedTypeName = `${typeName}s`;\n } else {\n pluralizedTypeName = pluralize(typeName);\n }\n return pluralizedTypeName;\n};\n"],"mappings":";;;;;;;;;AAAA;;AAEA;AACA;AACO,MAAMA,kBAAkB,GAAIC,QAAD,IAA8B;EAC5D,IAAID,kBAAJ;;EACA,IAAIC,QAAQ,CAACC,MAAT,KAAoB,CAAxB,EAA2B;IACvBF,kBAAkB,GAAI,GAAEC,QAAS,GAAjC;EACH,CAFD,MAEO;IACHD,kBAAkB,GAAG,IAAAG,kBAAA,EAAUF,QAAV,CAArB;EACH;;EACD,OAAOD,kBAAP;AACH,CARM"}
|