@webiny/api-headless-cms 0.0.0-unstable.bca7b3e350 → 0.0.0-unstable.c2780f51fe
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 +47 -43
- package/context.js.map +1 -1
- package/crud/contentEntry/markLockedFields.d.ts +1 -1
- package/crud/contentEntry/markLockedFields.js +3 -0
- package/crud/contentEntry/markLockedFields.js.map +1 -1
- package/crud/contentEntry.crud.d.ts +5 -2
- package/crud/contentEntry.crud.js +848 -830
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/beforeCreate.js +39 -76
- package/crud/contentModel/beforeCreate.js.map +1 -1
- package/crud/contentModel/beforeDelete.d.ts +1 -1
- package/crud/contentModel/beforeDelete.js +1 -5
- package/crud/contentModel/beforeDelete.js.map +1 -1
- package/crud/contentModel/beforeUpdate.js +31 -3
- package/crud/contentModel/beforeUpdate.js.map +1 -1
- package/crud/contentModel/compatibility/modelApiName.d.ts +3 -0
- package/crud/contentModel/compatibility/modelApiName.js +24 -0
- package/crud/contentModel/compatibility/modelApiName.js.map +1 -0
- package/crud/contentModel/defaultFields.d.ts +5 -0
- package/crud/contentModel/defaultFields.js +58 -0
- package/crud/contentModel/defaultFields.js.map +1 -0
- package/crud/contentModel/fields/descriptionField.d.ts +2 -0
- package/crud/contentModel/fields/descriptionField.js +42 -0
- package/crud/contentModel/fields/descriptionField.js.map +1 -0
- package/crud/contentModel/fields/imageField.d.ts +2 -0
- package/crud/contentModel/fields/imageField.js +46 -0
- package/crud/contentModel/fields/imageField.js.map +1 -0
- package/crud/contentModel/fields/titleField.d.ts +2 -0
- package/crud/contentModel/fields/titleField.js +58 -0
- package/crud/contentModel/fields/titleField.js.map +1 -0
- package/crud/contentModel/systemFields.js.map +1 -1
- package/crud/contentModel/validate/endingAllowed.d.ts +6 -0
- package/crud/contentModel/validate/endingAllowed.js +26 -0
- package/crud/contentModel/validate/endingAllowed.js.map +1 -0
- package/crud/contentModel/validate/isModelEndingAllowed.d.ts +6 -0
- package/crud/contentModel/validate/isModelEndingAllowed.js +24 -0
- package/crud/contentModel/validate/isModelEndingAllowed.js.map +1 -0
- package/crud/contentModel/validate/modelId.d.ts +11 -0
- package/crud/contentModel/validate/modelId.js +36 -0
- package/crud/contentModel/validate/modelId.js.map +1 -0
- package/crud/contentModel/validate/pluralApiName.d.ts +7 -0
- package/crud/contentModel/validate/pluralApiName.js +24 -0
- package/crud/contentModel/validate/pluralApiName.js.map +1 -0
- package/crud/contentModel/validate/singularApiName.d.ts +7 -0
- package/crud/contentModel/validate/singularApiName.js +24 -0
- package/crud/contentModel/validate/singularApiName.js.map +1 -0
- package/crud/contentModel/validateModel.d.ts +1 -0
- package/crud/contentModel/validateModel.js.map +1 -1
- package/crud/contentModel/validateModelFields.d.ts +2 -1
- package/crud/contentModel/validateModelFields.js +19 -57
- package/crud/contentModel/validateModelFields.js.map +1 -1
- package/crud/contentModel/validation.d.ts +136 -62
- package/crud/contentModel/validation.js +61 -13
- package/crud/contentModel/validation.js.map +1 -1
- package/crud/contentModel.crud.js +346 -285
- package/crud/contentModel.crud.js.map +1 -1
- package/crud/contentModelGroup.crud.js +170 -142
- package/crud/contentModelGroup.crud.js.map +1 -1
- package/crud/settings.crud.d.ts +1 -1
- package/crud/settings.crud.js +5 -10
- package/crud/settings.crud.js.map +1 -1
- package/crud/system.crud.js +0 -60
- package/crud/system.crud.js.map +1 -1
- package/graphql/checkEndpointAccess.d.ts +2 -0
- package/graphql/checkEndpointAccess.js +18 -0
- package/graphql/checkEndpointAccess.js.map +1 -0
- package/graphql/createExecutableSchema.d.ts +2 -3
- package/graphql/createExecutableSchema.js.map +1 -1
- package/graphql/createRequestBody.d.ts +2 -0
- package/graphql/createRequestBody.js +14 -0
- package/graphql/createRequestBody.js.map +1 -0
- package/graphql/formatErrorPayload.d.ts +1 -0
- package/graphql/formatErrorPayload.js +25 -0
- package/graphql/formatErrorPayload.js.map +1 -0
- package/graphql/generateSchema.js.map +1 -1
- package/graphql/getSchema.d.ts +17 -0
- package/graphql/getSchema.js +102 -0
- package/graphql/getSchema.js.map +1 -0
- package/graphql/graphQLHandlerFactory.js +6 -145
- package/graphql/graphQLHandlerFactory.js.map +1 -1
- package/graphql/handleRequest.d.ts +11 -0
- package/graphql/handleRequest.js +81 -0
- package/graphql/handleRequest.js.map +1 -0
- package/graphql/schema/baseContentSchema.js +1 -7
- package/graphql/schema/baseContentSchema.js.map +1 -1
- package/graphql/schema/contentEntries.js +90 -53
- package/graphql/schema/contentEntries.js.map +1 -1
- package/graphql/schema/contentModelGroups.js +7 -7
- package/graphql/schema/contentModelGroups.js.map +1 -1
- package/graphql/schema/contentModels.js +23 -4
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createManageResolvers.d.ts +1 -1
- package/graphql/schema/createManageResolvers.js +33 -17
- package/graphql/schema/createManageResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.d.ts +1 -0
- package/graphql/schema/createManageSDL.js +55 -49
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/createPreviewResolvers.js +3 -7
- package/graphql/schema/createPreviewResolvers.js.map +1 -1
- package/graphql/schema/createReadResolvers.js +4 -8
- package/graphql/schema/createReadResolvers.js.map +1 -1
- package/graphql/schema/createReadSDL.d.ts +1 -0
- package/graphql/schema/createReadSDL.js +24 -22
- package/graphql/schema/createReadSDL.js.map +1 -1
- package/graphql/schema/resolvers/commonFieldResolvers.d.ts +3 -2
- package/graphql/schema/resolvers/commonFieldResolvers.js +2 -1
- package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
- package/graphql/schema/schemaPlugins.js +12 -12
- package/graphql/schema/schemaPlugins.js.map +1 -1
- package/graphql/system.js +0 -16
- package/graphql/system.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.js +24 -4
- package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -1
- package/graphqlFields/object.js +21 -2
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +42 -14
- package/graphqlFields/ref.js.map +1 -1
- package/index.d.ts +3 -1
- package/index.js +25 -2
- package/index.js.map +1 -1
- package/package.json +22 -23
- package/plugins/CmsModelPlugin.d.ts +19 -3
- package/plugins/CmsModelPlugin.js +28 -2
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/plugins/StorageOperationsCmsModelPlugin.d.ts +23 -0
- package/plugins/StorageOperationsCmsModelPlugin.js +42 -0
- package/plugins/StorageOperationsCmsModelPlugin.js.map +1 -0
- package/plugins/index.d.ts +1 -0
- package/plugins/index.js +11 -0
- package/plugins/index.js.map +1 -1
- package/types.d.ts +118 -66
- package/types.js +1 -1
- 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/converters/valueKeyStorageConverter.d.ts +1 -5
- package/utils/converters/valueKeyStorageConverter.js +21 -18
- package/utils/converters/valueKeyStorageConverter.js.map +1 -1
- package/utils/createTypeFromFields.d.ts +1 -0
- package/utils/createTypeFromFields.js +7 -5
- package/utils/createTypeFromFields.js.map +1 -1
- package/utils/createTypeName.d.ts +0 -2
- package/utils/createTypeName.js +2 -10
- package/utils/createTypeName.js.map +1 -1
- package/utils/getEntryDescription.d.ts +2 -0
- package/utils/getEntryDescription.js +17 -0
- package/utils/getEntryDescription.js.map +1 -0
- package/utils/getEntryImage.d.ts +2 -0
- package/utils/getEntryImage.js +17 -0
- package/utils/getEntryImage.js.map +1 -0
- package/utils/incrementEntryIdVersion.d.ts +5 -0
- package/utils/incrementEntryIdVersion.js +29 -0
- package/utils/incrementEntryIdVersion.js.map +1 -0
- package/utils/ownership.d.ts +3 -3
- package/utils/ownership.js.map +1 -1
- package/utils/pluralizedTypeName.js +6 -0
- package/utils/pluralizedTypeName.js.map +1 -1
- package/utils/renderFields.d.ts +2 -1
- package/utils/renderFields.js +8 -1
- package/utils/renderFields.js.map +1 -1
- package/utils/renderInputFields.d.ts +2 -1
- package/utils/renderInputFields.js +4 -0
- package/utils/renderInputFields.js.map +1 -1
|
@@ -10,9 +10,5 @@ interface Params {
|
|
|
10
10
|
}
|
|
11
11
|
export declare const createValueKeyToStorageConverter: (params: Params) => CmsModelConverterCallable;
|
|
12
12
|
export declare const createValueKeyFromStorageConverter: (params: Params) => CmsModelConverterCallable;
|
|
13
|
-
|
|
14
|
-
plugins: PluginsContainer;
|
|
15
|
-
model: CmsModel;
|
|
16
|
-
}
|
|
17
|
-
export declare const attachCmsModelFieldConverters: (params: AttachConvertersParams) => StorageOperationsCmsModel;
|
|
13
|
+
export declare const createCmsModelFieldConvertersAttachFactory: (plugins: PluginsContainer) => (model: StorageOperationsCmsModel | CmsModel) => StorageOperationsCmsModel;
|
|
18
14
|
export {};
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.createValueKeyToStorageConverter = exports.createValueKeyFromStorageConverter = exports.
|
|
7
|
+
exports.createValueKeyToStorageConverter = exports.createValueKeyFromStorageConverter = exports.createCmsModelFieldConvertersAttachFactory = void 0;
|
|
8
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
9
|
var _ConverterCollection = require("./ConverterCollection");
|
|
10
10
|
var _semver = _interopRequireDefault(require("semver"));
|
|
@@ -26,7 +26,8 @@ const isFeatureEnabled = model => {
|
|
|
26
26
|
/**
|
|
27
27
|
* If is a test environment, always have this turned on.
|
|
28
28
|
*/
|
|
29
|
-
|
|
29
|
+
const nodeEnv = process.env.NODE_ENV;
|
|
30
|
+
if (nodeEnv === "test" || nodeEnv === "disable" || isBetaOrNext(model)) {
|
|
30
31
|
return true;
|
|
31
32
|
}
|
|
32
33
|
/**
|
|
@@ -103,20 +104,22 @@ const createValueKeyFromStorageConverter = params => {
|
|
|
103
104
|
};
|
|
104
105
|
};
|
|
105
106
|
exports.createValueKeyFromStorageConverter = createValueKeyFromStorageConverter;
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
model
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
107
|
+
const createCmsModelFieldConvertersAttachFactory = plugins => {
|
|
108
|
+
return model => {
|
|
109
|
+
const storageModel = model;
|
|
110
|
+
if (!!storageModel.convertValueKeyToStorage && !!storageModel.convertValueKeyFromStorage) {
|
|
111
|
+
return storageModel;
|
|
112
|
+
}
|
|
113
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, model), {}, {
|
|
114
|
+
convertValueKeyToStorage: createValueKeyToStorageConverter({
|
|
115
|
+
model,
|
|
116
|
+
plugins
|
|
117
|
+
}),
|
|
118
|
+
convertValueKeyFromStorage: createValueKeyFromStorageConverter({
|
|
119
|
+
model,
|
|
120
|
+
plugins
|
|
121
|
+
})
|
|
122
|
+
});
|
|
123
|
+
};
|
|
121
124
|
};
|
|
122
|
-
exports.
|
|
125
|
+
exports.createCmsModelFieldConvertersAttachFactory = createCmsModelFieldConvertersAttachFactory;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["featureVersion","semver","coerce","isBetaOrNext","model","webinyVersion","match","isFeatureEnabled","process","env","NODE_ENV","modelVersion","console","log","modelId","compare","createValueKeyToStorageConverter","params","plugins","values","converters","ConverterCollection","fields","result","convertToStorage","createValueKeyFromStorageConverter","convertFromStorage","
|
|
1
|
+
{"version":3,"names":["featureVersion","semver","coerce","isBetaOrNext","model","webinyVersion","match","isFeatureEnabled","nodeEnv","process","env","NODE_ENV","modelVersion","console","log","modelId","compare","createValueKeyToStorageConverter","params","plugins","values","converters","ConverterCollection","fields","result","convertToStorage","createValueKeyFromStorageConverter","convertFromStorage","createCmsModelFieldConvertersAttachFactory","storageModel","convertValueKeyToStorage","convertValueKeyFromStorage"],"sources":["valueKeyStorageConverter.ts"],"sourcesContent":["import { PluginsContainer } from \"@webiny/plugins\";\nimport {\n CmsModelConverterCallable,\n ConverterCollection,\n ConverterCollectionConvertParams as BaseConverterCollectionConvertParams\n} from \"~/utils/converters/ConverterCollection\";\nimport { CmsModel, StorageOperationsCmsModel } from \"~/types\";\nimport semver, { SemVer } from \"semver\";\n\nconst featureVersion = semver.coerce(\"5.33.0\") as SemVer;\n\nconst isBetaOrNext = (model: CmsModel): boolean => {\n if (!model.webinyVersion) {\n return false;\n }\n return model.webinyVersion.match(/next|beta/) !== null;\n};\n\nconst isFeatureEnabled = (model: CmsModel): boolean => {\n /**\n * In case of disabled webinyVersion value, we disable this feature.\n * This is only for testing...\n */\n if (model.webinyVersion === \"disable\") {\n return false;\n }\n /**\n * If is a test environment, always have this turned on.\n */\n const nodeEnv = process.env.NODE_ENV as string;\n if (nodeEnv === \"test\" || nodeEnv === \"disable\" || isBetaOrNext(model)) {\n return true;\n }\n /**\n * Possibility that the version is not defined, this means it is a quite old system where models did not change.\n */\n if (!model.webinyVersion) {\n return false;\n }\n /**\n * In case feature version value is greater than the model version, feature is not enabled as it is an older model with no storageId.\n *\n * TODO change if necessary after the update to the system\n */\n const modelVersion = semver.coerce(model.webinyVersion);\n if (!modelVersion) {\n console.log(`Warning: Model \"${model.modelId}\" does not have valid Webiny version set.`);\n return true;\n } else if (semver.compare(modelVersion, featureVersion) === -1) {\n return false;\n }\n return true;\n};\n\ninterface Params {\n /**\n * We need a model to determine if the conversion feature is enabled.\n */\n model: CmsModel;\n plugins: PluginsContainer;\n}\n\n/**\n * In the first call of the converter we do not need the fields property as it will be taken directly from the model.\n */\ninterface ConverterCollectionConvertParams\n extends Omit<BaseConverterCollectionConvertParams, \"fields\"> {\n fields?: BaseConverterCollectionConvertParams[\"fields\"];\n}\n\nexport const createValueKeyToStorageConverter = (params: Params): CmsModelConverterCallable => {\n const { plugins, model } = params;\n\n if (isFeatureEnabled(model) === false) {\n return ({ values }: ConverterCollectionConvertParams) => {\n return values || {};\n };\n }\n\n const converters = new ConverterCollection({\n plugins\n });\n\n return ({ fields, values }: ConverterCollectionConvertParams) => {\n const result = converters.convertToStorage({\n fields: fields || model.fields,\n values\n });\n return result || {};\n };\n};\n\nexport const createValueKeyFromStorageConverter = (params: Params): CmsModelConverterCallable => {\n const { plugins, model } = params;\n\n if (isFeatureEnabled(model) === false) {\n return ({ values }: ConverterCollectionConvertParams) => {\n return values || {};\n };\n }\n\n const converters = new ConverterCollection({\n plugins\n });\n\n return ({ fields, values }: ConverterCollectionConvertParams) => {\n const result = converters.convertFromStorage({\n fields: fields || model.fields,\n values\n });\n return result || {};\n };\n};\n\nexport const createCmsModelFieldConvertersAttachFactory = (plugins: PluginsContainer) => {\n return (model: StorageOperationsCmsModel | CmsModel): StorageOperationsCmsModel => {\n const storageModel = model as Partial<StorageOperationsCmsModel>;\n if (!!storageModel.convertValueKeyToStorage && !!storageModel.convertValueKeyFromStorage) {\n return storageModel as StorageOperationsCmsModel;\n }\n return {\n ...model,\n convertValueKeyToStorage: createValueKeyToStorageConverter({\n model,\n plugins\n }),\n convertValueKeyFromStorage: createValueKeyFromStorageConverter({\n model,\n plugins\n })\n };\n };\n};\n"],"mappings":";;;;;;;;AACA;AAMA;AAEA,MAAMA,cAAc,GAAGC,eAAM,CAACC,MAAM,CAAC,QAAQ,CAAW;AAExD,MAAMC,YAAY,GAAIC,KAAe,IAAc;EAC/C,IAAI,CAACA,KAAK,CAACC,aAAa,EAAE;IACtB,OAAO,KAAK;EAChB;EACA,OAAOD,KAAK,CAACC,aAAa,CAACC,KAAK,CAAC,WAAW,CAAC,KAAK,IAAI;AAC1D,CAAC;AAED,MAAMC,gBAAgB,GAAIH,KAAe,IAAc;EACnD;AACJ;AACA;AACA;EACI,IAAIA,KAAK,CAACC,aAAa,KAAK,SAAS,EAAE;IACnC,OAAO,KAAK;EAChB;EACA;AACJ;AACA;EACI,MAAMG,OAAO,GAAGC,OAAO,CAACC,GAAG,CAACC,QAAkB;EAC9C,IAAIH,OAAO,KAAK,MAAM,IAAIA,OAAO,KAAK,SAAS,IAAIL,YAAY,CAACC,KAAK,CAAC,EAAE;IACpE,OAAO,IAAI;EACf;EACA;AACJ;AACA;EACI,IAAI,CAACA,KAAK,CAACC,aAAa,EAAE;IACtB,OAAO,KAAK;EAChB;EACA;AACJ;AACA;AACA;AACA;EACI,MAAMO,YAAY,GAAGX,eAAM,CAACC,MAAM,CAACE,KAAK,CAACC,aAAa,CAAC;EACvD,IAAI,CAACO,YAAY,EAAE;IACfC,OAAO,CAACC,GAAG,CAAE,mBAAkBV,KAAK,CAACW,OAAQ,2CAA0C,CAAC;IACxF,OAAO,IAAI;EACf,CAAC,MAAM,IAAId,eAAM,CAACe,OAAO,CAACJ,YAAY,EAAEZ,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE;IAC5D,OAAO,KAAK;EAChB;EACA,OAAO,IAAI;AACf,CAAC;AAkBM,MAAMiB,gCAAgC,GAAIC,MAAc,IAAgC;EAC3F,MAAM;IAAEC,OAAO;IAAEf;EAAM,CAAC,GAAGc,MAAM;EAEjC,IAAIX,gBAAgB,CAACH,KAAK,CAAC,KAAK,KAAK,EAAE;IACnC,OAAO,CAAC;MAAEgB;IAAyC,CAAC,KAAK;MACrD,OAAOA,MAAM,IAAI,CAAC,CAAC;IACvB,CAAC;EACL;EAEA,MAAMC,UAAU,GAAG,IAAIC,wCAAmB,CAAC;IACvCH;EACJ,CAAC,CAAC;EAEF,OAAO,CAAC;IAAEI,MAAM;IAAEH;EAAyC,CAAC,KAAK;IAC7D,MAAMI,MAAM,GAAGH,UAAU,CAACI,gBAAgB,CAAC;MACvCF,MAAM,EAAEA,MAAM,IAAInB,KAAK,CAACmB,MAAM;MAC9BH;IACJ,CAAC,CAAC;IACF,OAAOI,MAAM,IAAI,CAAC,CAAC;EACvB,CAAC;AACL,CAAC;AAAC;AAEK,MAAME,kCAAkC,GAAIR,MAAc,IAAgC;EAC7F,MAAM;IAAEC,OAAO;IAAEf;EAAM,CAAC,GAAGc,MAAM;EAEjC,IAAIX,gBAAgB,CAACH,KAAK,CAAC,KAAK,KAAK,EAAE;IACnC,OAAO,CAAC;MAAEgB;IAAyC,CAAC,KAAK;MACrD,OAAOA,MAAM,IAAI,CAAC,CAAC;IACvB,CAAC;EACL;EAEA,MAAMC,UAAU,GAAG,IAAIC,wCAAmB,CAAC;IACvCH;EACJ,CAAC,CAAC;EAEF,OAAO,CAAC;IAAEI,MAAM;IAAEH;EAAyC,CAAC,KAAK;IAC7D,MAAMI,MAAM,GAAGH,UAAU,CAACM,kBAAkB,CAAC;MACzCJ,MAAM,EAAEA,MAAM,IAAInB,KAAK,CAACmB,MAAM;MAC9BH;IACJ,CAAC,CAAC;IACF,OAAOI,MAAM,IAAI,CAAC,CAAC;EACvB,CAAC;AACL,CAAC;AAAC;AAEK,MAAMI,0CAA0C,GAAIT,OAAyB,IAAK;EACrF,OAAQf,KAA2C,IAAgC;IAC/E,MAAMyB,YAAY,GAAGzB,KAA2C;IAChE,IAAI,CAAC,CAACyB,YAAY,CAACC,wBAAwB,IAAI,CAAC,CAACD,YAAY,CAACE,0BAA0B,EAAE;MACtF,OAAOF,YAAY;IACvB;IACA,mEACOzB,KAAK;MACR0B,wBAAwB,EAAEb,gCAAgC,CAAC;QACvDb,KAAK;QACLe;MACJ,CAAC,CAAC;MACFY,0BAA0B,EAAEL,kCAAkC,CAAC;QAC3DtB,KAAK;QACLe;MACJ,CAAC;IAAC;EAEV,CAAC;AACL,CAAC;AAAC"}
|
|
@@ -4,20 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createTypeFromFields = void 0;
|
|
7
|
-
var _createTypeName = require("./createTypeName");
|
|
8
7
|
var _renderFields = require("./renderFields");
|
|
9
8
|
var _renderInputFields = require("./renderInputFields");
|
|
10
9
|
const createTypeFromFields = params => {
|
|
11
10
|
const {
|
|
12
11
|
typeOfType,
|
|
13
12
|
model,
|
|
13
|
+
models,
|
|
14
14
|
type,
|
|
15
15
|
typeNamePrefix,
|
|
16
16
|
fields,
|
|
17
17
|
fieldTypePlugins
|
|
18
18
|
} = params;
|
|
19
19
|
const typeSuffix = typeOfType === "input" ? "Input" : "";
|
|
20
|
-
const mTypeName =
|
|
20
|
+
const mTypeName = model.singularApiName;
|
|
21
21
|
const typeFields = [];
|
|
22
22
|
const nestedTypes = [];
|
|
23
23
|
|
|
@@ -27,14 +27,16 @@ const createTypeFromFields = params => {
|
|
|
27
27
|
// Every time the types are returned, we need to replace the model name in the generated type name
|
|
28
28
|
// with the actual prefix which includes parent field name type.
|
|
29
29
|
const replace = new RegExp(`${mTypeName}_`, "g");
|
|
30
|
-
for (const
|
|
30
|
+
for (const field of fields) {
|
|
31
31
|
const result = typeOfType === "type" ? (0, _renderFields.renderField)({
|
|
32
|
-
field
|
|
32
|
+
field,
|
|
33
33
|
type,
|
|
34
|
+
models,
|
|
34
35
|
model,
|
|
35
36
|
fieldTypePlugins
|
|
36
37
|
}) : (0, _renderInputFields.renderInputField)({
|
|
37
|
-
field
|
|
38
|
+
field,
|
|
39
|
+
models,
|
|
38
40
|
model,
|
|
39
41
|
fieldTypePlugins
|
|
40
42
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createTypeFromFields","params","typeOfType","model","type","typeNamePrefix","fields","fieldTypePlugins","typeSuffix","mTypeName","
|
|
1
|
+
{"version":3,"names":["createTypeFromFields","params","typeOfType","model","models","type","typeNamePrefix","fields","fieldTypePlugins","typeSuffix","mTypeName","singularApiName","typeFields","nestedTypes","replace","RegExp","field","result","renderField","renderInputField","typeDefs","push","fieldType","join"],"sources":["createTypeFromFields.ts"],"sourcesContent":["import { renderField } from \"~/utils/renderFields\";\nimport { renderInputField } from \"~/utils/renderInputFields\";\nimport { ApiEndpoint, CmsFieldTypePlugins, CmsModel, CmsModelField } from \"~/types\";\n\ninterface TypeFromFieldParams {\n typeOfType: \"type\" | \"input\";\n models: CmsModel[];\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, models, type, typeNamePrefix, fields, fieldTypePlugins } = params;\n const typeSuffix = typeOfType === \"input\" ? \"Input\" : \"\";\n const mTypeName = model.singularApiName;\n\n const typeFields: string[] = [];\n const nestedTypes: string[] = [];\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 field of fields) {\n const result =\n typeOfType === \"type\"\n ? renderField({ field, type, models, model, fieldTypePlugins })\n : renderInputField({ field, models, 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;AAkBO,MAAMA,oBAAoB,GAAIC,MAA2B,IAAmC;EAC/F,MAAM;IAAEC,UAAU;IAAEC,KAAK;IAAEC,MAAM;IAAEC,IAAI;IAAEC,cAAc;IAAEC,MAAM;IAAEC;EAAiB,CAAC,GAAGP,MAAM;EAC5F,MAAMQ,UAAU,GAAGP,UAAU,KAAK,OAAO,GAAG,OAAO,GAAG,EAAE;EACxD,MAAMQ,SAAS,GAAGP,KAAK,CAACQ,eAAe;EAEvC,MAAMC,UAAoB,GAAG,EAAE;EAC/B,MAAMC,WAAqB,GAAG,EAAE;;EAEhC;EACA;EACA;EACA;EACA;EACA,MAAMC,OAAO,GAAG,IAAIC,MAAM,CAAE,GAAEL,SAAU,GAAE,EAAE,GAAG,CAAC;EAEhD,KAAK,MAAMM,KAAK,IAAIT,MAAM,EAAE;IACxB,MAAMU,MAAM,GACRf,UAAU,KAAK,MAAM,GACf,IAAAgB,yBAAW,EAAC;MAAEF,KAAK;MAAEX,IAAI;MAAED,MAAM;MAAED,KAAK;MAAEK;IAAiB,CAAC,CAAC,GAC7D,IAAAW,mCAAgB,EAAC;MAAEH,KAAK;MAAEZ,MAAM;MAAED,KAAK;MAAEK;IAAiB,CAAC,CAAC;IAEtE,IAAI,CAACS,MAAM,EAAE;MACT;IACJ;IAEA,MAAM;MAAEV,MAAM;MAAEa;IAAS,CAAC,GAAGH,MAAM;IAEnCL,UAAU,CAACS,IAAI,CAACd,MAAM,CAACO,OAAO,CAACA,OAAO,EAAG,GAAER,cAAe,GAAE,CAAC,CAAC;IAC9D,IAAIc,QAAQ,EAAE;MACVP,WAAW,CAACQ,IAAI,CAACD,QAAQ,CAACN,OAAO,CAACA,OAAO,EAAG,GAAER,cAAe,GAAE,CAAC,CAAC;IACrE;EACJ;EAEA,OAAO;IACHgB,SAAS,EAAG,GAAEhB,cAAe,GAAEG,UAAW,EAAC;IAC3CW,QAAQ,EAAE,aAAe;AACjC,cAAcP,WAAW,CAACU,IAAI,CAAC,IAAI,CAAE;AACrC;AACA,cAAcrB,UAAW,IAAGI,cAAe,GAAEG,UAAW;AACxD,kBAAkBG,UAAU,CAACW,IAAI,CAAC,IAAI,CAAE;AACxC;AACA;EACI,CAAC;AACL,CAAC;AAAC"}
|
package/utils/createTypeName.js
CHANGED
|
@@ -4,18 +4,10 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.createTypeName =
|
|
7
|
+
exports.createTypeName = void 0;
|
|
8
8
|
var _upperFirst = _interopRequireDefault(require("lodash/upperFirst"));
|
|
9
9
|
var _camelCase = _interopRequireDefault(require("lodash/camelCase"));
|
|
10
10
|
const createTypeName = modelId => {
|
|
11
11
|
return (0, _upperFirst.default)((0, _camelCase.default)(modelId));
|
|
12
12
|
};
|
|
13
|
-
exports.createTypeName = createTypeName;
|
|
14
|
-
const createReadTypeName = baseTypeName => {
|
|
15
|
-
return createTypeName(baseTypeName);
|
|
16
|
-
};
|
|
17
|
-
exports.createReadTypeName = createReadTypeName;
|
|
18
|
-
const createManageTypeName = baseTypeName => {
|
|
19
|
-
return createTypeName(baseTypeName);
|
|
20
|
-
};
|
|
21
|
-
exports.createManageTypeName = createManageTypeName;
|
|
13
|
+
exports.createTypeName = createTypeName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createTypeName","modelId","upperFirst","camelCase"
|
|
1
|
+
{"version":3,"names":["createTypeName","modelId","upperFirst","camelCase"],"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"],"mappings":";;;;;;;AAAA;AACA;AAEO,MAAMA,cAAc,GAAIC,OAAe,IAAa;EACvD,OAAO,IAAAC,mBAAU,EAAC,IAAAC,kBAAS,EAACF,OAAO,CAAC,CAAC;AACzC,CAAC;AAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getEntryDescription = getEntryDescription;
|
|
7
|
+
function getEntryDescription(model, entry) {
|
|
8
|
+
if (!model.descriptionFieldId) {
|
|
9
|
+
return "";
|
|
10
|
+
}
|
|
11
|
+
const field = model.fields.find(f => f.fieldId === model.descriptionFieldId);
|
|
12
|
+
if (!field) {
|
|
13
|
+
return "";
|
|
14
|
+
}
|
|
15
|
+
const descriptionFieldId = field.fieldId;
|
|
16
|
+
return entry.values[descriptionFieldId] || "";
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getEntryDescription","model","entry","descriptionFieldId","field","fields","find","f","fieldId","values"],"sources":["getEntryDescription.ts"],"sourcesContent":["import { CmsEntry, CmsModel } from \"~/types\";\n\nexport function getEntryDescription(model: CmsModel, entry: CmsEntry): string {\n if (!model.descriptionFieldId) {\n return \"\";\n }\n const field = model.fields.find(f => f.fieldId === model.descriptionFieldId);\n if (!field) {\n return \"\";\n }\n const descriptionFieldId = field.fieldId;\n return entry.values[descriptionFieldId] || \"\";\n}\n"],"mappings":";;;;;;AAEO,SAASA,mBAAmB,CAACC,KAAe,EAAEC,KAAe,EAAU;EAC1E,IAAI,CAACD,KAAK,CAACE,kBAAkB,EAAE;IAC3B,OAAO,EAAE;EACb;EACA,MAAMC,KAAK,GAAGH,KAAK,CAACI,MAAM,CAACC,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACC,OAAO,KAAKP,KAAK,CAACE,kBAAkB,CAAC;EAC5E,IAAI,CAACC,KAAK,EAAE;IACR,OAAO,EAAE;EACb;EACA,MAAMD,kBAAkB,GAAGC,KAAK,CAACI,OAAO;EACxC,OAAON,KAAK,CAACO,MAAM,CAACN,kBAAkB,CAAC,IAAI,EAAE;AACjD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getEntryImage = getEntryImage;
|
|
7
|
+
function getEntryImage(model, entry) {
|
|
8
|
+
if (!model.imageFieldId) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const field = model.fields.find(f => f.fieldId === model.imageFieldId);
|
|
12
|
+
if (!field) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const imageFieldId = field.fieldId;
|
|
16
|
+
return entry.values[imageFieldId] || null;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getEntryImage","model","entry","imageFieldId","field","fields","find","f","fieldId","values"],"sources":["getEntryImage.ts"],"sourcesContent":["import { CmsEntry, CmsModel } from \"~/types\";\n\nexport function getEntryImage(model: CmsModel, entry: CmsEntry): string | null {\n if (!model.imageFieldId) {\n return null;\n }\n const field = model.fields.find(f => f.fieldId === model.imageFieldId);\n if (!field) {\n return null;\n }\n const imageFieldId = field.fieldId;\n return entry.values[imageFieldId] || null;\n}\n"],"mappings":";;;;;;AAEO,SAASA,aAAa,CAACC,KAAe,EAAEC,KAAe,EAAiB;EAC3E,IAAI,CAACD,KAAK,CAACE,YAAY,EAAE;IACrB,OAAO,IAAI;EACf;EACA,MAAMC,KAAK,GAAGH,KAAK,CAACI,MAAM,CAACC,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACC,OAAO,KAAKP,KAAK,CAACE,YAAY,CAAC;EACtE,IAAI,CAACC,KAAK,EAAE;IACR,OAAO,IAAI;EACf;EACA,MAAMD,YAAY,GAAGC,KAAK,CAACI,OAAO;EAClC,OAAON,KAAK,CAACO,MAAM,CAACN,YAAY,CAAC,IAAI,IAAI;AAC7C"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.incrementEntryIdVersion = void 0;
|
|
8
|
+
var _utils = require("@webiny/utils");
|
|
9
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
10
|
+
const incrementEntryIdVersion = id => {
|
|
11
|
+
const {
|
|
12
|
+
id: entryId,
|
|
13
|
+
version
|
|
14
|
+
} = (0, _utils.parseIdentifier)(id);
|
|
15
|
+
if (!version) {
|
|
16
|
+
throw new _error.default("Cannot increase version on the ID without the version part.", "WRONG_ID", {
|
|
17
|
+
id
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
entryId,
|
|
22
|
+
version: version + 1,
|
|
23
|
+
id: (0, _utils.createIdentifier)({
|
|
24
|
+
id: entryId,
|
|
25
|
+
version: version + 1
|
|
26
|
+
})
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
exports.incrementEntryIdVersion = incrementEntryIdVersion;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["incrementEntryIdVersion","id","entryId","version","parseIdentifier","WebinyError","createIdentifier"],"sources":["incrementEntryIdVersion.ts"],"sourcesContent":["import { createIdentifier, parseIdentifier } from \"@webiny/utils\";\nimport WebinyError from \"@webiny/error\";\n\nexport const incrementEntryIdVersion = (id: string) => {\n const { id: entryId, version } = parseIdentifier(id);\n if (!version) {\n throw new WebinyError(\n \"Cannot increase version on the ID without the version part.\",\n \"WRONG_ID\",\n {\n id\n }\n );\n }\n return {\n entryId,\n version: version + 1,\n id: createIdentifier({\n id: entryId,\n version: version + 1\n })\n };\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAEO,MAAMA,uBAAuB,GAAIC,EAAU,IAAK;EACnD,MAAM;IAAEA,EAAE,EAAEC,OAAO;IAAEC;EAAQ,CAAC,GAAG,IAAAC,sBAAe,EAACH,EAAE,CAAC;EACpD,IAAI,CAACE,OAAO,EAAE;IACV,MAAM,IAAIE,cAAW,CACjB,6DAA6D,EAC7D,UAAU,EACV;MACIJ;IACJ,CAAC,CACJ;EACL;EACA,OAAO;IACHC,OAAO;IACPC,OAAO,EAAEA,OAAO,GAAG,CAAC;IACpBF,EAAE,EAAE,IAAAK,uBAAgB,EAAC;MACjBL,EAAE,EAAEC,OAAO;MACXC,OAAO,EAAEA,OAAO,GAAG;IACvB,CAAC;EACL,CAAC;AACL,CAAC;AAAC"}
|
package/utils/ownership.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BaseCmsSecurityPermission, CmsContext,
|
|
1
|
+
import { BaseCmsSecurityPermission, CmsContext, CmsIdentity } from "../types";
|
|
2
2
|
interface OwnableRecord {
|
|
3
|
-
createdBy?:
|
|
4
|
-
ownedBy?:
|
|
3
|
+
createdBy?: CmsIdentity;
|
|
4
|
+
ownedBy?: CmsIdentity;
|
|
5
5
|
}
|
|
6
6
|
export declare const checkOwnership: (context: CmsContext, permission: BaseCmsSecurityPermission, record: OwnableRecord) => void;
|
|
7
7
|
export declare const validateOwnership: (context: CmsContext, permission: BaseCmsSecurityPermission, record: OwnableRecord) => boolean;
|
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,
|
|
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, CmsIdentity } from \"~/types\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\n\ninterface OwnableRecord {\n createdBy?: CmsIdentity;\n ownedBy?: CmsIdentity;\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,OAAmB,EACnBC,UAAqC,EACrCC,MAAqB,KACd;EAAA;EACP,IAAI,CAACD,UAAU,CAACE,GAAG,EAAE;IACjB;EACJ;EAEA,MAAMC,QAAQ,GAAGJ,OAAO,CAACK,QAAQ,CAACC,WAAW,EAAE;EAC/C,MAAMC,KAAK,GAAGH,QAAQ,IAAI,oBAAAF,MAAM,CAACM,OAAO,oDAAd,gBAAgBC,EAAE,MAAKL,QAAQ,CAACK,EAAE;EAC5D,MAAMC,OAAO,GAAGN,QAAQ,IAAI,sBAAAF,MAAM,CAACS,SAAS,sDAAhB,kBAAkBF,EAAE,MAAKL,QAAQ,CAACK,EAAE;EAEhE,IAAI,CAACF,KAAK,IAAI,CAACG,OAAO,EAAE;IACpB,MAAM,IAAIE,+BAAkB,CAAC;MACzBC,IAAI,EAAE;QACFC,MAAM,EAAG;MACb;IACJ,CAAC,CAAC;EACN;AACJ,CAAC;AAAC;AAEK,MAAMC,iBAAiB,GAAG,CAC7Bf,OAAmB,EACnBC,UAAqC,EACrCC,MAAqB,KACX;EACV,IAAI;IACAH,cAAc,CAACC,OAAO,EAAEC,UAAU,EAAEC,MAAM,CAAC;IAC3C,OAAO,IAAI;EACf,CAAC,CAAC,MAAM;IACJ,OAAO,KAAK;EAChB;AACJ,CAAC;AAAC"}
|
|
@@ -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"}
|
package/utils/renderFields.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ApiEndpoint, CmsFieldTypePlugins, CmsModel, CmsModelField, CmsModelFieldDefinition } from "../types";
|
|
2
2
|
interface RenderFieldsParams {
|
|
3
|
+
models: CmsModel[];
|
|
3
4
|
model: CmsModel;
|
|
4
5
|
type: ApiEndpoint;
|
|
5
6
|
fieldTypePlugins: CmsFieldTypePlugins;
|
|
@@ -11,5 +12,5 @@ export declare const renderFields: RenderFields;
|
|
|
11
12
|
interface RenderFieldParams extends RenderFieldsParams {
|
|
12
13
|
field: CmsModelField;
|
|
13
14
|
}
|
|
14
|
-
export declare const renderField: ({ model, type, field, fieldTypePlugins }: RenderFieldParams) => CmsModelFieldDefinition | null;
|
|
15
|
+
export declare const renderField: ({ models, model, type, field, fieldTypePlugins }: RenderFieldParams) => CmsModelFieldDefinition | null;
|
|
15
16
|
export {};
|
package/utils/renderFields.js
CHANGED
|
@@ -6,11 +6,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.renderFields = exports.renderField = void 0;
|
|
7
7
|
var _getBaseFieldType = require("./getBaseFieldType");
|
|
8
8
|
const renderFields = ({
|
|
9
|
+
models,
|
|
9
10
|
model,
|
|
10
11
|
type,
|
|
11
12
|
fieldTypePlugins
|
|
12
13
|
}) => {
|
|
13
14
|
return model.fields.map(field => renderField({
|
|
15
|
+
models,
|
|
14
16
|
model,
|
|
15
17
|
type,
|
|
16
18
|
field,
|
|
@@ -19,6 +21,7 @@ const renderFields = ({
|
|
|
19
21
|
};
|
|
20
22
|
exports.renderFields = renderFields;
|
|
21
23
|
const renderField = ({
|
|
24
|
+
models,
|
|
22
25
|
model,
|
|
23
26
|
type,
|
|
24
27
|
field,
|
|
@@ -29,7 +32,11 @@ const renderField = ({
|
|
|
29
32
|
// Let's not render the field if it does not exist in the field plugins.
|
|
30
33
|
return null;
|
|
31
34
|
}
|
|
32
|
-
const
|
|
35
|
+
const {
|
|
36
|
+
createTypeField
|
|
37
|
+
} = plugin[type];
|
|
38
|
+
const defs = createTypeField({
|
|
39
|
+
models,
|
|
33
40
|
model,
|
|
34
41
|
field,
|
|
35
42
|
fieldTypePlugins
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["renderFields","model","type","fieldTypePlugins","fields","map","field","renderField","filter","Boolean","plugin","getBaseFieldType","
|
|
1
|
+
{"version":3,"names":["renderFields","models","model","type","fieldTypePlugins","fields","map","field","renderField","filter","Boolean","plugin","getBaseFieldType","createTypeField","defs"],"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 models: CmsModel[];\n model: CmsModel;\n type: ApiEndpoint;\n fieldTypePlugins: CmsFieldTypePlugins;\n}\n\ninterface RenderFields {\n (params: RenderFieldsParams): CmsModelFieldDefinition[];\n}\n\nexport const renderFields: RenderFields = ({\n models,\n model,\n type,\n fieldTypePlugins\n}): CmsModelFieldDefinition[] => {\n return model.fields\n .map(field => renderField({ models, model, type, field, fieldTypePlugins }))\n .filter(Boolean) as CmsModelFieldDefinition[];\n};\n\ninterface RenderFieldParams extends RenderFieldsParams {\n field: CmsModelField;\n}\n\nexport const renderField = ({\n models,\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 { createTypeField } = plugin[type] as CmsModelFieldToGraphQLPlugin[\"manage\"];\n const defs = createTypeField({\n models,\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;AAaO,MAAMA,YAA0B,GAAG,CAAC;EACvCC,MAAM;EACNC,KAAK;EACLC,IAAI;EACJC;AACJ,CAAC,KAAgC;EAC7B,OAAOF,KAAK,CAACG,MAAM,CACdC,GAAG,CAACC,KAAK,IAAIC,WAAW,CAAC;IAAEP,MAAM;IAAEC,KAAK;IAAEC,IAAI;IAAEI,KAAK;IAAEH;EAAiB,CAAC,CAAC,CAAC,CAC3EK,MAAM,CAACC,OAAO,CAAC;AACxB,CAAC;AAAC;AAMK,MAAMF,WAAW,GAAG,CAAC;EACxBP,MAAM;EACNC,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,MAAM;IAAEE;EAAgB,CAAC,GAAGF,MAAM,CAACR,IAAI,CAA2C;EAClF,MAAMW,IAAI,GAAGD,eAAe,CAAC;IACzBZ,MAAM;IACNC,KAAK;IACLK,KAAK;IACLH;EACJ,CAAC,CAAC;EAEF,IAAI,CAACU,IAAI,EAAE;IACP,OAAO,IAAI;EACf,CAAC,MAAM,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;IACjC,OAAO;MACHT,MAAM,EAAES;IACZ,CAAC;EACL;EAEA,OAAOA,IAAI;AACf,CAAC;AAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CmsFieldTypePlugins, CmsModel, CmsModelField, CmsModelFieldDefinition } from "../types";
|
|
2
2
|
interface RenderInputFieldsParams {
|
|
3
|
+
models: CmsModel[];
|
|
3
4
|
model: CmsModel;
|
|
4
5
|
fieldTypePlugins: CmsFieldTypePlugins;
|
|
5
6
|
}
|
|
@@ -10,5 +11,5 @@ interface RenderInputFields {
|
|
|
10
11
|
(params: RenderInputFieldsParams): CmsModelFieldDefinition[];
|
|
11
12
|
}
|
|
12
13
|
export declare const renderInputFields: RenderInputFields;
|
|
13
|
-
export declare const renderInputField: ({ model, field, fieldTypePlugins }: RenderInputFieldParams) => CmsModelFieldDefinition | null;
|
|
14
|
+
export declare const renderInputField: ({ models, model, field, fieldTypePlugins }: RenderInputFieldParams) => CmsModelFieldDefinition | null;
|
|
14
15
|
export {};
|
|
@@ -6,10 +6,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.renderInputFields = exports.renderInputField = void 0;
|
|
7
7
|
var _getBaseFieldType = require("./getBaseFieldType");
|
|
8
8
|
const renderInputFields = ({
|
|
9
|
+
models,
|
|
9
10
|
model,
|
|
10
11
|
fieldTypePlugins
|
|
11
12
|
}) => {
|
|
12
13
|
return model.fields.map(field => renderInputField({
|
|
14
|
+
models,
|
|
13
15
|
model,
|
|
14
16
|
field,
|
|
15
17
|
fieldTypePlugins
|
|
@@ -17,6 +19,7 @@ const renderInputFields = ({
|
|
|
17
19
|
};
|
|
18
20
|
exports.renderInputFields = renderInputFields;
|
|
19
21
|
const renderInputField = ({
|
|
22
|
+
models,
|
|
20
23
|
model,
|
|
21
24
|
field,
|
|
22
25
|
fieldTypePlugins
|
|
@@ -32,6 +35,7 @@ const renderInputField = ({
|
|
|
32
35
|
return null;
|
|
33
36
|
}
|
|
34
37
|
const def = plugin.manage.createInputField({
|
|
38
|
+
models,
|
|
35
39
|
model,
|
|
36
40
|
field,
|
|
37
41
|
fieldTypePlugins
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
1
|
+
{"version":3,"names":["renderInputFields","models","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 models: CmsModel[];\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 models,\n model,\n fieldTypePlugins\n}): CmsModelFieldDefinition[] => {\n return model.fields\n .map(field => renderInputField({ models, model, field, fieldTypePlugins }))\n .filter(Boolean) as CmsModelFieldDefinition[];\n};\n\nexport const renderInputField = ({\n models,\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 models,\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;AAcO,MAAMA,iBAAoC,GAAG,CAAC;EACjDC,MAAM;EACNC,KAAK;EACLC;AACJ,CAAC,KAAgC;EAC7B,OAAOD,KAAK,CAACE,MAAM,CACdC,GAAG,CAACC,KAAK,IAAIC,gBAAgB,CAAC;IAAEN,MAAM;IAAEC,KAAK;IAAEI,KAAK;IAAEH;EAAiB,CAAC,CAAC,CAAC,CAC1EK,MAAM,CAACC,OAAO,CAAC;AACxB,CAAC;AAAC;AAEK,MAAMF,gBAAgB,GAAG,CAAC;EAC7BN,MAAM;EACNC,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;IACvCb,MAAM;IACNC,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"}
|