@webiny/api-headless-cms 0.0.0-unstable.9e825fd5fb → 0.0.0-unstable.ad3a7a4920
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 +4 -3
- package/context.js.map +1 -1
- package/crud/contentEntry/referenceFieldsMapping.js +34 -5
- package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
- package/crud/contentEntry.crud.d.ts +1 -1
- package/crud/contentEntry.crud.js +26 -90
- package/crud/contentEntry.crud.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/validation.d.ts +48 -16
- package/crud/contentModel/validation.js +2 -2
- package/crud/contentModel/validation.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/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 +5 -190
- 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/createFieldResolvers.js +2 -1
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.js +44 -17
- package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -1
- package/graphqlFields/ref.js +7 -7
- package/graphqlFields/ref.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +13 -9
- package/index.js.map +1 -1
- package/package.json +22 -22
- package/plugins/CmsModelPlugin.d.ts +3 -1
- package/plugins/CmsModelPlugin.js +5 -5
- 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 +43 -41
- package/types.js.map +1 -1
- package/utils/converters/valueKeyStorageConverter.d.ts +1 -5
- package/utils/converters/valueKeyStorageConverter.js +19 -23
- package/utils/converters/valueKeyStorageConverter.js.map +1 -1
- package/utils/createTypeFromFields.js +1 -2
- 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
|
@@ -13,11 +13,11 @@ var _upperFirst = _interopRequireDefault(require("lodash/upperFirst"));
|
|
|
13
13
|
var _pluralize = _interopRequireDefault(require("pluralize"));
|
|
14
14
|
var _plugins = require("@webiny/plugins");
|
|
15
15
|
var _createFieldStorageId = require("../crud/contentModel/createFieldStorageId");
|
|
16
|
-
const
|
|
16
|
+
const createApiName = name => {
|
|
17
17
|
return (0, _upperFirst.default)((0, _camelCase.default)(name));
|
|
18
18
|
};
|
|
19
|
-
const
|
|
20
|
-
return (0, _pluralize.default)(
|
|
19
|
+
const createPluralApiName = name => {
|
|
20
|
+
return (0, _pluralize.default)(createApiName(name));
|
|
21
21
|
};
|
|
22
22
|
class CmsModelPlugin extends _plugins.Plugin {
|
|
23
23
|
constructor(contentModel, options) {
|
|
@@ -29,8 +29,8 @@ class CmsModelPlugin extends _plugins.Plugin {
|
|
|
29
29
|
}
|
|
30
30
|
buildModel(input) {
|
|
31
31
|
const isPrivate = input.isPrivate || false;
|
|
32
|
-
const singularApiName = input.singularApiName
|
|
33
|
-
const pluralApiName = input.pluralApiName
|
|
32
|
+
const singularApiName = input.singularApiName ? createApiName(input.singularApiName) : createApiName(input.name);
|
|
33
|
+
const pluralApiName = input.pluralApiName ? createApiName(input.pluralApiName) : createPluralApiName(input.name);
|
|
34
34
|
if (input.noValidate) {
|
|
35
35
|
/**
|
|
36
36
|
* We can safely ignore this error, because we are sure noValidate is not a model field.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["transformNameToSingularApiName","name","upperFirst","camelCase","transformNameToPluralApiName","pluralize","CmsModelPlugin","Plugin","constructor","contentModel","options","buildModel","input","isPrivate","singularApiName","pluralApiName","noValidate","model","fields","buildFields","validateLayout","inputFields","length","WebinyError","modelId","storageIdList","fieldIdList","fieldId","trim","field","lodashCamelCase","match","includes","storageId","createFieldStorageId","settings","childFields","type","push","total","row","layout","count","filter","cell","id","createCmsModel"],"sources":["CmsModelPlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport lodashCamelCase from \"lodash/camelCase\";\nimport camelCase from \"lodash/camelCase\";\nimport upperFirst from \"lodash/upperFirst\";\nimport pluralize from \"pluralize\";\nimport { Plugin } from \"@webiny/plugins\";\nimport {\n CmsModel as CmsModelBase,\n CmsModelField as CmsModelFieldBase,\n CmsModelFieldSettings as BaseCmsModelFieldSettings\n} from \"~/types\";\nimport { createFieldStorageId } from \"~/crud/contentModel/createFieldStorageId\";\n\nconst transformNameToSingularApiName = (name: string) => {\n return upperFirst(camelCase(name));\n};\n\nconst transformNameToPluralApiName = (name: string) => {\n return pluralize(transformNameToSingularApiName(name));\n};\n\ninterface CmsModelFieldSettings extends Omit<BaseCmsModelFieldSettings, \"fields\"> {\n /**\n * Object field has child fields.\n */\n fields?: CmsModelFieldInput[];\n}\n\ninterface CmsModelFieldInput extends Omit<CmsModelFieldBase, \"storageId\" | \"settings\"> {\n /**\n * If defined, it must be camelCased string.\n * This is for backwards compatibility - before fields had storageId.\n *\n * This should only be populated in old model fields.\n * News ones must have this empty.\n */\n storageId?: string;\n /**\n * We must have a possibility to have a nested field defined without the storageId.\n */\n settings?: CmsModelFieldSettings;\n}\n\nexport interface CmsApiModel extends Omit<CmsModel, \"isPrivate\" | \"fields\"> {\n isPrivate?: never;\n noValidate?: never;\n fields: CmsModelFieldInput[];\n}\n\nexport interface CmsApiModelFull extends Omit<CmsApiModel, \"fields\" | \"noValidate\"> {\n noValidate: true;\n fields: CmsModelFieldBase[];\n}\n\ninterface CmsPrivateModel\n extends Omit<CmsModel, \"isPrivate\" | \"singularApiName\" | \"pluralApiName\" | \"fields\"> {\n noValidate?: never;\n singularApiName?: never;\n pluralApiName?: never;\n isPrivate: true;\n fields: CmsModelFieldInput[];\n}\n\nexport interface CmsPrivateModelFull extends Omit<CmsPrivateModel, \"fields\" | \"noValidate\"> {\n fields: CmsModelFieldBase[];\n noValidate: true;\n}\n\nexport type CmsModelInput = CmsApiModel | CmsPrivateModel | CmsApiModelFull | CmsPrivateModelFull;\n\ninterface CmsModel extends Omit<CmsModelBase, \"locale\" | \"tenant\" | \"webinyVersion\"> {\n locale?: string;\n tenant?: string;\n}\n\ninterface CmsModelPluginOptions {\n validateLayout?: boolean;\n}\n\nexport class CmsModelPlugin extends Plugin {\n public static override readonly type: string = \"cms-content-model\";\n public readonly contentModel: CmsModel;\n\n private readonly options: CmsModelPluginOptions;\n\n constructor(contentModel: CmsModelInput, options?: CmsModelPluginOptions) {\n super();\n this.options = options || {};\n this.contentModel = this.buildModel(contentModel);\n }\n\n private buildModel(input: CmsModelInput): CmsModel {\n const isPrivate = input.isPrivate || false;\n const singularApiName = input.singularApiName || transformNameToSingularApiName(input.name);\n const pluralApiName = input.pluralApiName || transformNameToPluralApiName(input.name);\n\n if (input.noValidate) {\n /**\n * We can safely ignore this error, because we are sure noValidate is not a model field.\n */\n // @ts-ignore\n delete input[\"noValidate\"];\n return {\n ...input,\n isPrivate,\n singularApiName,\n pluralApiName\n };\n }\n\n const model: CmsModel = {\n ...input,\n isPrivate,\n singularApiName,\n pluralApiName,\n fields: this.buildFields(input, input.fields)\n };\n this.validateLayout(model);\n return model;\n }\n\n private buildFields(\n model: CmsModelInput,\n inputFields: CmsModelFieldInput[]\n ): CmsModelFieldBase[] {\n if (inputFields.length === 0) {\n throw new WebinyError(\n `Missing fields for the defined model \"${model.modelId}\".`,\n \"MISSING_FIELDS\",\n {\n model\n }\n );\n }\n const fields: CmsModelFieldBase[] = [];\n const storageIdList: string[] = [];\n const fieldIdList: string[] = [];\n for (const input of inputFields) {\n /**\n * Field must contain an fieldId. It is required in the graphql, but lets check it just in case\n */\n if (!(input.fieldId || \"\").trim()) {\n throw new WebinyError(\n `Field's \"storageId\" is not defined for the content model \"${model.modelId}\".`,\n \"FIELD_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n const fieldId = lodashCamelCase(input.fieldId);\n /**\n * FieldID must be in correct pattern.\n */\n if (fieldId.match(/^[0-9]/) !== null) {\n throw new WebinyError(\n `Field's \"fieldId\" does not match correct pattern in the content model \"${model.modelId}\" - cannot start with a number.`,\n \"FIELD_FIELD_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n /**\n * FieldID also must be camelCased.\n */\n if (fieldId !== input.fieldId) {\n throw new WebinyError(\n `Field's \"fieldId\" must be a camel cased string in the content model \"${model.modelId}\".`,\n \"FIELD_FIELD_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n /**\n * ... and fieldId must be unique.\n */\n if (fieldIdList.includes(fieldId) === true) {\n throw new WebinyError(\n `Field's \"fieldId\" is not unique in the content model \"${model.modelId}\".`,\n \"FIELD_ID_NOT_UNIQUE_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n\n let storageId = input.storageId ? lodashCamelCase(input.storageId) : null;\n /**\n * If defined, storageId MUST be camel cased string - for backward compatibility.\n */\n if (\n storageId &&\n (storageId.match(/^([a-zA-Z-0-9]+)$/) === null || storageId !== input.storageId)\n ) {\n throw new WebinyError(\n `Field's \"storageId\" of the field with \"fieldId\" ${input.fieldId} is not camel cased string in the content model \"${model.modelId}\".`,\n \"STORAGE_ID_NOT_CAMEL_CASED_ERROR\",\n {\n model,\n storageId,\n field: input\n }\n );\n } else if (!storageId) {\n storageId = createFieldStorageId(input);\n }\n\n /**\n * Fields storageId must be unique.\n */\n if (storageIdList.includes(storageId) === true) {\n throw new WebinyError(\n `Field's \"storageId\" is not unique in the content model \"${model.modelId}\".`,\n \"STORAGE_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n\n /**\n * We can safely ignore error because we are going through the fields and making sure each has storageId.\n */\n // @ts-ignore\n let settings: BaseCmsModelFieldSettings = input.settings;\n\n const childFields = settings?.fields || [];\n if (input.type === \"object\" && childFields.length > 0) {\n settings = {\n ...(settings || {}),\n fields: this.buildFields(model, childFields)\n };\n }\n\n const field: CmsModelFieldBase = {\n ...input,\n settings,\n storageId\n };\n /**\n * Add all relevant data to arrays.\n */\n fields.push(field);\n storageIdList.push(field.storageId);\n fieldIdList.push(field.fieldId);\n }\n return fields;\n }\n\n private validateLayout(model: CmsModel): void {\n /**\n * Only skip validation if option.validateLayout was set as false, explicitly.\n */\n if (this.options.validateLayout === false) {\n return;\n }\n for (const field of model.fields) {\n let total = 0;\n for (const row of model.layout) {\n const count = row.filter(cell => cell === field.id).length;\n total = total + count;\n }\n if (total === 1) {\n continue;\n } else if (total > 1) {\n throw new WebinyError(\n `Field \"${field.id}\" is in more than one layout cell.`,\n \"DUPLICATE_FIELD_IN_LAYOUT\",\n {\n model,\n field\n }\n );\n }\n throw new WebinyError(\n `Missing field \"${field.id}\" in layout.`,\n \"MISSING_FIELD_IN_LAYOUT\",\n {\n model,\n field\n }\n );\n }\n }\n}\n\nexport const createCmsModel = (\n model: CmsModelInput,\n options?: CmsModelPluginOptions\n): CmsModelPlugin => {\n return new CmsModelPlugin(model, options);\n};\n"],"mappings":";;;;;;;;;AAAA;AACA;AAEA;AACA;AACA;AAMA;A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,CAACoB,IAAI,CAACT,KAAK,CAAC;MAClBJ,aAAa,CAACa,IAAI,CAACT,KAAK,CAACI,SAAS,CAAC;MACnCP,WAAW,CAACY,IAAI,CAACT,KAAK,CAACF,OAAO,CAAC;IACnC;IACA,OAAOT,MAAM;EACjB;EAEQE,cAAc,CAACH,KAAe,EAAQ;IAC1C;AACR;AACA;IACQ,IAAI,IAAI,CAACP,OAAO,CAACU,cAAc,KAAK,KAAK,EAAE;MACvC;IACJ;IACA,KAAK,MAAMS,KAAK,IAAIZ,KAAK,CAACC,MAAM,EAAE;MAC9B,IAAIqB,KAAK,GAAG,CAAC;MACb,KAAK,MAAMC,GAAG,IAAIvB,KAAK,CAACwB,MAAM,EAAE;QAC5B,MAAMC,KAAK,GAAGF,GAAG,CAACG,MAAM,CAACC,IAAI,IAAIA,IAAI,KAAKf,KAAK,CAACgB,EAAE,CAAC,CAACvB,MAAM;QAC1DiB,KAAK,GAAGA,KAAK,GAAGG,KAAK;MACzB;MACA,IAAIH,KAAK,KAAK,CAAC,EAAE;QACb;MACJ,CAAC,MAAM,IAAIA,KAAK,GAAG,CAAC,EAAE;QAClB,MAAM,IAAIhB,cAAW,CAChB,UAASM,KAAK,CAACgB,EAAG,oCAAmC,EACtD,2BAA2B,EAC3B;UACI5B,KAAK;UACLY;QACJ,CAAC,CACJ;MACL;MACA,MAAM,IAAIN,cAAW,CAChB,kBAAiBM,KAAK,CAACgB,EAAG,cAAa,EACxC,yBAAyB,EACzB;QACI5B,KAAK;QACLY;MACJ,CAAC,CACJ;IACL;EACJ;AACJ;AAAC;AAAA,8BApNYvB,cAAc,UACwB,mBAAmB;AAqN/D,MAAMwC,cAAc,GAAG,CAC1B7B,KAAoB,EACpBP,OAA+B,KACd;EACjB,OAAO,IAAIJ,cAAc,CAACW,KAAK,EAAEP,OAAO,CAAC;AAC7C,CAAC;AAAC"}
|
|
1
|
+
{"version":3,"names":["createApiName","name","upperFirst","camelCase","createPluralApiName","pluralize","CmsModelPlugin","Plugin","constructor","contentModel","options","buildModel","input","isPrivate","singularApiName","pluralApiName","noValidate","model","fields","buildFields","validateLayout","inputFields","length","WebinyError","modelId","storageIdList","fieldIdList","fieldId","trim","field","lodashCamelCase","match","includes","storageId","createFieldStorageId","settings","childFields","type","push","total","row","layout","count","filter","cell","id","createCmsModel"],"sources":["CmsModelPlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport lodashCamelCase from \"lodash/camelCase\";\nimport camelCase from \"lodash/camelCase\";\nimport upperFirst from \"lodash/upperFirst\";\nimport pluralize from \"pluralize\";\nimport { Plugin } from \"@webiny/plugins\";\nimport {\n CmsModel as CmsModelBase,\n CmsModelField as CmsModelFieldBase,\n CmsModelFieldSettings as BaseCmsModelFieldSettings\n} from \"~/types\";\nimport { createFieldStorageId } from \"~/crud/contentModel/createFieldStorageId\";\n\nconst createApiName = (name: string) => {\n return upperFirst(camelCase(name));\n};\n\nconst createPluralApiName = (name: string) => {\n return pluralize(createApiName(name));\n};\n\ninterface CmsModelFieldSettings extends Omit<BaseCmsModelFieldSettings, \"fields\"> {\n /**\n * Object field has child fields.\n */\n fields?: CmsModelFieldInput[];\n}\n\ninterface CmsModelFieldInput extends Omit<CmsModelFieldBase, \"storageId\" | \"settings\"> {\n /**\n * If defined, it must be camelCased string.\n * This is for backwards compatibility - before fields had storageId.\n *\n * This should only be populated in old model fields.\n * News ones must have this empty.\n */\n storageId?: string;\n /**\n * We must have a possibility to have a nested field defined without the storageId.\n */\n settings?: CmsModelFieldSettings;\n}\n\nexport interface CmsApiModel\n extends Omit<CmsModel, \"isPrivate\" | \"fields\" | \"singularApiName\" | \"pluralApiName\"> {\n isPrivate?: never;\n noValidate?: never;\n singularApiName?: string;\n pluralApiName?: string;\n fields: CmsModelFieldInput[];\n}\n\nexport interface CmsApiModelFull extends Omit<CmsApiModel, \"fields\" | \"noValidate\"> {\n noValidate: true;\n fields: CmsModelFieldBase[];\n}\n\ninterface CmsPrivateModel\n extends Omit<CmsModel, \"isPrivate\" | \"singularApiName\" | \"pluralApiName\" | \"fields\"> {\n noValidate?: never;\n singularApiName?: never;\n pluralApiName?: never;\n isPrivate: true;\n fields: CmsModelFieldInput[];\n}\n\nexport interface CmsPrivateModelFull extends Omit<CmsPrivateModel, \"fields\" | \"noValidate\"> {\n fields: CmsModelFieldBase[];\n noValidate: true;\n}\n\nexport type CmsModelInput = CmsApiModel | CmsPrivateModel | CmsApiModelFull | CmsPrivateModelFull;\n\ninterface CmsModel extends Omit<CmsModelBase, \"locale\" | \"tenant\" | \"webinyVersion\"> {\n locale?: string;\n tenant?: string;\n}\n\ninterface CmsModelPluginOptions {\n validateLayout?: boolean;\n}\n\nexport class CmsModelPlugin extends Plugin {\n public static override readonly type: string = \"cms-content-model\";\n public readonly contentModel: CmsModel;\n\n private readonly options: CmsModelPluginOptions;\n\n constructor(contentModel: CmsModelInput, options?: CmsModelPluginOptions) {\n super();\n this.options = options || {};\n this.contentModel = this.buildModel(contentModel);\n }\n\n private buildModel(input: CmsModelInput): CmsModel {\n const isPrivate = input.isPrivate || false;\n const singularApiName = input.singularApiName\n ? createApiName(input.singularApiName)\n : createApiName(input.name);\n const pluralApiName = input.pluralApiName\n ? createApiName(input.pluralApiName)\n : createPluralApiName(input.name);\n\n if (input.noValidate) {\n /**\n * We can safely ignore this error, because we are sure noValidate is not a model field.\n */\n // @ts-ignore\n delete input[\"noValidate\"];\n return {\n ...input,\n isPrivate,\n singularApiName,\n pluralApiName\n };\n }\n\n const model: CmsModel = {\n ...input,\n isPrivate,\n singularApiName,\n pluralApiName,\n fields: this.buildFields(input, input.fields)\n };\n this.validateLayout(model);\n return model;\n }\n\n private buildFields(\n model: CmsModelInput,\n inputFields: CmsModelFieldInput[]\n ): CmsModelFieldBase[] {\n if (inputFields.length === 0) {\n throw new WebinyError(\n `Missing fields for the defined model \"${model.modelId}\".`,\n \"MISSING_FIELDS\",\n {\n model\n }\n );\n }\n const fields: CmsModelFieldBase[] = [];\n const storageIdList: string[] = [];\n const fieldIdList: string[] = [];\n for (const input of inputFields) {\n /**\n * Field must contain an fieldId. It is required in the graphql, but lets check it just in case\n */\n if (!(input.fieldId || \"\").trim()) {\n throw new WebinyError(\n `Field's \"storageId\" is not defined for the content model \"${model.modelId}\".`,\n \"FIELD_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n const fieldId = lodashCamelCase(input.fieldId);\n /**\n * FieldID must be in correct pattern.\n */\n if (fieldId.match(/^[0-9]/) !== null) {\n throw new WebinyError(\n `Field's \"fieldId\" does not match correct pattern in the content model \"${model.modelId}\" - cannot start with a number.`,\n \"FIELD_FIELD_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n /**\n * FieldID also must be camelCased.\n */\n if (fieldId !== input.fieldId) {\n throw new WebinyError(\n `Field's \"fieldId\" must be a camel cased string in the content model \"${model.modelId}\".`,\n \"FIELD_FIELD_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n /**\n * ... and fieldId must be unique.\n */\n if (fieldIdList.includes(fieldId) === true) {\n throw new WebinyError(\n `Field's \"fieldId\" is not unique in the content model \"${model.modelId}\".`,\n \"FIELD_ID_NOT_UNIQUE_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n\n let storageId = input.storageId ? lodashCamelCase(input.storageId) : null;\n /**\n * If defined, storageId MUST be camel cased string - for backward compatibility.\n */\n if (\n storageId &&\n (storageId.match(/^([a-zA-Z-0-9]+)$/) === null || storageId !== input.storageId)\n ) {\n throw new WebinyError(\n `Field's \"storageId\" of the field with \"fieldId\" ${input.fieldId} is not camel cased string in the content model \"${model.modelId}\".`,\n \"STORAGE_ID_NOT_CAMEL_CASED_ERROR\",\n {\n model,\n storageId,\n field: input\n }\n );\n } else if (!storageId) {\n storageId = createFieldStorageId(input);\n }\n\n /**\n * Fields storageId must be unique.\n */\n if (storageIdList.includes(storageId) === true) {\n throw new WebinyError(\n `Field's \"storageId\" is not unique in the content model \"${model.modelId}\".`,\n \"STORAGE_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n\n /**\n * We can safely ignore error because we are going through the fields and making sure each has storageId.\n */\n // @ts-ignore\n let settings: BaseCmsModelFieldSettings = input.settings;\n\n const childFields = settings?.fields || [];\n if (input.type === \"object\" && childFields.length > 0) {\n settings = {\n ...(settings || {}),\n fields: this.buildFields(model, childFields)\n };\n }\n\n const field: CmsModelFieldBase = {\n ...input,\n settings,\n storageId\n };\n /**\n * Add all relevant data to arrays.\n */\n fields.push(field);\n storageIdList.push(field.storageId);\n fieldIdList.push(field.fieldId);\n }\n return fields;\n }\n\n private validateLayout(model: CmsModel): void {\n /**\n * Only skip validation if option.validateLayout was set as false, explicitly.\n */\n if (this.options.validateLayout === false) {\n return;\n }\n for (const field of model.fields) {\n let total = 0;\n for (const row of model.layout) {\n const count = row.filter(cell => cell === field.id).length;\n total = total + count;\n }\n if (total === 1) {\n continue;\n } else if (total > 1) {\n throw new WebinyError(\n `Field \"${field.id}\" is in more than one layout cell.`,\n \"DUPLICATE_FIELD_IN_LAYOUT\",\n {\n model,\n field\n }\n );\n }\n throw new WebinyError(\n `Missing field \"${field.id}\" in layout.`,\n \"MISSING_FIELD_IN_LAYOUT\",\n {\n model,\n field\n }\n );\n }\n }\n}\n\nexport const createCmsModel = (\n model: CmsModelInput,\n options?: CmsModelPluginOptions\n): CmsModelPlugin => {\n return new CmsModelPlugin(model, options);\n};\n"],"mappings":";;;;;;;;;AAAA;AACA;AAEA;AACA;AACA;AAMA;AAEA,MAAMA,aAAa,GAAIC,IAAY,IAAK;EACpC,OAAO,IAAAC,mBAAU,EAAC,IAAAC,kBAAS,EAACF,IAAI,CAAC,CAAC;AACtC,CAAC;AAED,MAAMG,mBAAmB,GAAIH,IAAY,IAAK;EAC1C,OAAO,IAAAI,kBAAS,EAACL,aAAa,CAACC,IAAI,CAAC,CAAC;AACzC,CAAC;AA+DM,MAAMK,cAAc,SAASC,eAAM,CAAC;EAMvCC,WAAW,CAACC,YAA2B,EAAEC,OAA+B,EAAE;IACtE,KAAK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,CAACU,cAAc,KAAK,KAAK,EAAE;MACvC;IACJ;IACA,KAAK,MAAMS,KAAK,IAAIZ,KAAK,CAACC,MAAM,EAAE;MAC9B,IAAIqB,KAAK,GAAG,CAAC;MACb,KAAK,MAAMC,GAAG,IAAIvB,KAAK,CAACwB,MAAM,EAAE;QAC5B,MAAMC,KAAK,GAAGF,GAAG,CAACG,MAAM,CAACC,IAAI,IAAIA,IAAI,KAAKf,KAAK,CAACgB,EAAE,CAAC,CAACvB,MAAM;QAC1DiB,KAAK,GAAGA,KAAK,GAAGG,KAAK;MACzB;MACA,IAAIH,KAAK,KAAK,CAAC,EAAE;QACb;MACJ,CAAC,MAAM,IAAIA,KAAK,GAAG,CAAC,EAAE;QAClB,MAAM,IAAIhB,cAAW,CAChB,UAASM,KAAK,CAACgB,EAAG,oCAAmC,EACtD,2BAA2B,EAC3B;UACI5B,KAAK;UACLY;QACJ,CAAC,CACJ;MACL;MACA,MAAM,IAAIN,cAAW,CAChB,kBAAiBM,KAAK,CAACgB,EAAG,cAAa,EACxC,yBAAyB,EACzB;QACI5B,KAAK;QACLY;MACJ,CAAC,CACJ;IACL;EACJ;AACJ;AAAC;AAAA,8BAxNYvB,cAAc,UACwB,mBAAmB;AAyN/D,MAAMwC,cAAc,GAAG,CAC1B7B,KAAoB,EACpBP,OAA+B,KACd;EACjB,OAAO,IAAIJ,cAAc,CAACW,KAAK,EAAEP,OAAO,CAAC;AAC7C,CAAC;AAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
import { CmsModel, StorageOperationsCmsModel } from "../types";
|
|
3
|
+
export interface StorageOperationsCmsModelPluginCallable {
|
|
4
|
+
(model: CmsModel): StorageOperationsCmsModel;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* This plugin should be initialized only once and hence the name.
|
|
8
|
+
*/
|
|
9
|
+
export declare class StorageOperationsCmsModelPlugin extends Plugin {
|
|
10
|
+
static readonly type: string;
|
|
11
|
+
name: string;
|
|
12
|
+
private readonly models;
|
|
13
|
+
private readonly cb;
|
|
14
|
+
constructor(cb: StorageOperationsCmsModelPluginCallable);
|
|
15
|
+
getModel(input: CmsModel): StorageOperationsCmsModel;
|
|
16
|
+
/**
|
|
17
|
+
* We can cache the converters by having a cache key that is a combination of model ID and savedOn.
|
|
18
|
+
* The models created via the code will not have savedOn, so they will be unknown - and that is ok as they cannot change in the middle of the call.
|
|
19
|
+
*
|
|
20
|
+
* The models created via the CRUD operations might get changed in the middle of the call, so we need to re-create the SO model.
|
|
21
|
+
*/
|
|
22
|
+
private createCacheKey;
|
|
23
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.StorageOperationsCmsModelPlugin = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _plugins = require("@webiny/plugins");
|
|
10
|
+
/**
|
|
11
|
+
* This plugin should be initialized only once and hence the name.
|
|
12
|
+
*/
|
|
13
|
+
class StorageOperationsCmsModelPlugin extends _plugins.Plugin {
|
|
14
|
+
constructor(cb) {
|
|
15
|
+
super();
|
|
16
|
+
(0, _defineProperty2.default)(this, "name", "cms.storageOperations.model");
|
|
17
|
+
(0, _defineProperty2.default)(this, "models", {});
|
|
18
|
+
(0, _defineProperty2.default)(this, "cb", void 0);
|
|
19
|
+
this.cb = cb;
|
|
20
|
+
}
|
|
21
|
+
getModel(input) {
|
|
22
|
+
const cacheKey = this.createCacheKey(input);
|
|
23
|
+
if (this.models[cacheKey]) {
|
|
24
|
+
return this.models[cacheKey];
|
|
25
|
+
}
|
|
26
|
+
const model = this.cb(input);
|
|
27
|
+
this.models[cacheKey] = model;
|
|
28
|
+
return model;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* We can cache the converters by having a cache key that is a combination of model ID and savedOn.
|
|
33
|
+
* The models created via the code will not have savedOn, so they will be unknown - and that is ok as they cannot change in the middle of the call.
|
|
34
|
+
*
|
|
35
|
+
* The models created via the CRUD operations might get changed in the middle of the call, so we need to re-create the SO model.
|
|
36
|
+
*/
|
|
37
|
+
createCacheKey(model) {
|
|
38
|
+
return [model.tenant, model.locale, model.modelId, model.savedOn || "unknown"].join("#");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.StorageOperationsCmsModelPlugin = StorageOperationsCmsModelPlugin;
|
|
42
|
+
(0, _defineProperty2.default)(StorageOperationsCmsModelPlugin, "type", "cms.storageOperations.model");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["StorageOperationsCmsModelPlugin","Plugin","constructor","cb","getModel","input","cacheKey","createCacheKey","models","model","tenant","locale","modelId","savedOn","join"],"sources":["StorageOperationsCmsModelPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { CmsModel, StorageOperationsCmsModel } from \"~/types\";\n\nexport interface StorageOperationsCmsModelPluginCallable {\n (model: CmsModel): StorageOperationsCmsModel;\n}\n\n/**\n * This plugin should be initialized only once and hence the name.\n */\nexport class StorageOperationsCmsModelPlugin extends Plugin {\n public static override readonly type: string = \"cms.storageOperations.model\";\n public override name = \"cms.storageOperations.model\";\n\n private readonly models: Record<string, StorageOperationsCmsModel> = {};\n private readonly cb: StorageOperationsCmsModelPluginCallable;\n\n public constructor(cb: StorageOperationsCmsModelPluginCallable) {\n super();\n this.cb = cb;\n }\n\n public getModel(input: CmsModel) {\n const cacheKey = this.createCacheKey(input);\n if (this.models[cacheKey]) {\n return this.models[cacheKey];\n }\n const model = this.cb(input);\n\n this.models[cacheKey] = model;\n\n return model;\n }\n\n /**\n * We can cache the converters by having a cache key that is a combination of model ID and savedOn.\n * The models created via the code will not have savedOn, so they will be unknown - and that is ok as they cannot change in the middle of the call.\n *\n * The models created via the CRUD operations might get changed in the middle of the call, so we need to re-create the SO model.\n */\n private createCacheKey(model: CmsModel): string {\n return [model.tenant, model.locale, model.modelId, model.savedOn || \"unknown\"].join(\"#\");\n }\n}\n"],"mappings":";;;;;;;;AAAA;AAOA;AACA;AACA;AACO,MAAMA,+BAA+B,SAASC,eAAM,CAAC;EAOjDC,WAAW,CAACC,EAA2C,EAAE;IAC5D,KAAK,EAAE;IAAC,4CANW,6BAA6B;IAAA,8CAEiB,CAAC,CAAC;IAAA;IAKnE,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;EAEOC,QAAQ,CAACC,KAAe,EAAE;IAC7B,MAAMC,QAAQ,GAAG,IAAI,CAACC,cAAc,CAACF,KAAK,CAAC;IAC3C,IAAI,IAAI,CAACG,MAAM,CAACF,QAAQ,CAAC,EAAE;MACvB,OAAO,IAAI,CAACE,MAAM,CAACF,QAAQ,CAAC;IAChC;IACA,MAAMG,KAAK,GAAG,IAAI,CAACN,EAAE,CAACE,KAAK,CAAC;IAE5B,IAAI,CAACG,MAAM,CAACF,QAAQ,CAAC,GAAGG,KAAK;IAE7B,OAAOA,KAAK;EAChB;;EAEA;AACJ;AACA;AACA;AACA;AACA;EACYF,cAAc,CAACE,KAAe,EAAU;IAC5C,OAAO,CAACA,KAAK,CAACC,MAAM,EAAED,KAAK,CAACE,MAAM,EAAEF,KAAK,CAACG,OAAO,EAAEH,KAAK,CAACI,OAAO,IAAI,SAAS,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;EAC5F;AACJ;AAAC;AAAA,8BAjCYd,+BAA+B,UACO,6BAA6B"}
|
package/plugins/index.d.ts
CHANGED
package/plugins/index.js
CHANGED
|
@@ -79,4 +79,15 @@ Object.keys(_CmsGraphQLSchemaSorterPlugin).forEach(function (key) {
|
|
|
79
79
|
return _CmsGraphQLSchemaSorterPlugin[key];
|
|
80
80
|
}
|
|
81
81
|
});
|
|
82
|
+
});
|
|
83
|
+
var _StorageOperationsCmsModelPlugin = require("./StorageOperationsCmsModelPlugin");
|
|
84
|
+
Object.keys(_StorageOperationsCmsModelPlugin).forEach(function (key) {
|
|
85
|
+
if (key === "default" || key === "__esModule") return;
|
|
86
|
+
if (key in exports && exports[key] === _StorageOperationsCmsModelPlugin[key]) return;
|
|
87
|
+
Object.defineProperty(exports, key, {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function () {
|
|
90
|
+
return _StorageOperationsCmsModelPlugin[key];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
82
93
|
});
|
package/plugins/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./CmsGroupPlugin\";\nexport * from \"./CmsModelPlugin\";\nexport * from \"./StorageTransformPlugin\";\nexport * from \"./CmsParametersPlugin\";\nexport * from \"./CmsModelFieldConverterPlugin\";\nexport * from \"./CmsGraphQLSchemaPlugin\";\nexport * from \"./CmsGraphQLSchemaSorterPlugin\";\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./CmsGroupPlugin\";\nexport * from \"./CmsModelPlugin\";\nexport * from \"./StorageTransformPlugin\";\nexport * from \"./CmsParametersPlugin\";\nexport * from \"./CmsModelFieldConverterPlugin\";\nexport * from \"./CmsGraphQLSchemaPlugin\";\nexport * from \"./CmsGraphQLSchemaSorterPlugin\";\nexport * from \"./StorageOperationsCmsModelPlugin\";\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
package/types.d.ts
CHANGED
|
@@ -118,6 +118,7 @@ export interface CmsModelFieldSettings {
|
|
|
118
118
|
*/
|
|
119
119
|
[key: string]: any;
|
|
120
120
|
}
|
|
121
|
+
export declare type CmsModelFieldType = "boolean" | "datetime" | "file" | "long-text" | "number" | "object" | "ref" | "rich-text" | "text" | "dynamicZone" | string;
|
|
121
122
|
/**
|
|
122
123
|
* A definition for content model field. This type exists on the app side as well.
|
|
123
124
|
*
|
|
@@ -138,7 +139,7 @@ export interface CmsModelField {
|
|
|
138
139
|
* A type of the field.
|
|
139
140
|
* We are defining our built-in fields, so people know which are available by the default.
|
|
140
141
|
*/
|
|
141
|
-
type:
|
|
142
|
+
type: CmsModelFieldType;
|
|
142
143
|
/**
|
|
143
144
|
* A unique storage ID for storing actual values.
|
|
144
145
|
* Must in form of a-zA-Z0-9@a-zA-Z0-9
|
|
@@ -513,6 +514,7 @@ interface CmsModelFieldToGraphQLCreateResolverParams<TField> {
|
|
|
513
514
|
graphQLType: string;
|
|
514
515
|
field: TField;
|
|
515
516
|
createFieldResolvers: any;
|
|
517
|
+
fieldTypePlugins: CmsFieldTypePlugins;
|
|
516
518
|
}
|
|
517
519
|
export interface CmsModelFieldToGraphQLCreateResolver<TField = CmsModelField> {
|
|
518
520
|
(params: CmsModelFieldToGraphQLCreateResolverParams<TField>): GraphQLFieldResolver | {
|
|
@@ -1880,12 +1882,12 @@ export interface CmsEntryMeta {
|
|
|
1880
1882
|
export interface OnEntryBeforeCreateTopicParams {
|
|
1881
1883
|
input: CreateCmsEntryInput;
|
|
1882
1884
|
entry: CmsEntry;
|
|
1883
|
-
model:
|
|
1885
|
+
model: CmsModel;
|
|
1884
1886
|
}
|
|
1885
1887
|
export interface OnEntryAfterCreateTopicParams {
|
|
1886
1888
|
input: CreateCmsEntryInput;
|
|
1887
1889
|
entry: CmsEntry;
|
|
1888
|
-
model:
|
|
1890
|
+
model: CmsModel;
|
|
1889
1891
|
storageEntry: CmsEntry;
|
|
1890
1892
|
}
|
|
1891
1893
|
export interface OnEntryCreateErrorTopicParams {
|
|
@@ -1901,13 +1903,13 @@ export interface OnEntryRevisionBeforeCreateTopicParams {
|
|
|
1901
1903
|
input: CreateFromCmsEntryInput;
|
|
1902
1904
|
entry: CmsEntry;
|
|
1903
1905
|
original: CmsEntry;
|
|
1904
|
-
model:
|
|
1906
|
+
model: CmsModel;
|
|
1905
1907
|
}
|
|
1906
1908
|
export interface OnEntryRevisionAfterCreateTopicParams {
|
|
1907
1909
|
input: CreateFromCmsEntryInput;
|
|
1908
1910
|
entry: CmsEntry;
|
|
1909
1911
|
original: CmsEntry;
|
|
1910
|
-
model:
|
|
1912
|
+
model: CmsModel;
|
|
1911
1913
|
storageEntry: CmsEntry;
|
|
1912
1914
|
}
|
|
1913
1915
|
export interface OnEntryCreateRevisionErrorTopicParams {
|
|
@@ -1924,13 +1926,13 @@ export interface OnEntryBeforeUpdateTopicParams {
|
|
|
1924
1926
|
input: UpdateCmsEntryInput;
|
|
1925
1927
|
original: CmsEntry;
|
|
1926
1928
|
entry: CmsEntry;
|
|
1927
|
-
model:
|
|
1929
|
+
model: CmsModel;
|
|
1928
1930
|
}
|
|
1929
1931
|
export interface OnEntryAfterUpdateTopicParams {
|
|
1930
1932
|
input: UpdateCmsEntryInput;
|
|
1931
1933
|
original: CmsEntry;
|
|
1932
1934
|
entry: CmsEntry;
|
|
1933
|
-
model:
|
|
1935
|
+
model: CmsModel;
|
|
1934
1936
|
storageEntry: CmsEntry;
|
|
1935
1937
|
}
|
|
1936
1938
|
export interface OnEntryUpdateErrorTopicParams {
|
|
@@ -1944,45 +1946,45 @@ export interface OnEntryUpdateErrorTopicParams {
|
|
|
1944
1946
|
*/
|
|
1945
1947
|
export interface OnEntryBeforePublishTopicParams {
|
|
1946
1948
|
entry: CmsEntry;
|
|
1947
|
-
model:
|
|
1949
|
+
model: CmsModel;
|
|
1948
1950
|
}
|
|
1949
1951
|
export interface OnEntryAfterPublishTopicParams {
|
|
1950
1952
|
entry: CmsEntry;
|
|
1951
|
-
model:
|
|
1953
|
+
model: CmsModel;
|
|
1952
1954
|
storageEntry: CmsEntry;
|
|
1953
1955
|
}
|
|
1954
1956
|
export interface OnEntryPublishErrorTopicParams {
|
|
1955
1957
|
error: Error;
|
|
1956
1958
|
entry: CmsEntry;
|
|
1957
|
-
model:
|
|
1959
|
+
model: CmsModel;
|
|
1958
1960
|
}
|
|
1959
1961
|
/**
|
|
1960
1962
|
* Republish
|
|
1961
1963
|
*/
|
|
1962
1964
|
export interface OnEntryBeforeRepublishTopicParams {
|
|
1963
1965
|
entry: CmsEntry;
|
|
1964
|
-
model:
|
|
1966
|
+
model: CmsModel;
|
|
1965
1967
|
}
|
|
1966
1968
|
export interface OnEntryAfterRepublishTopicParams {
|
|
1967
1969
|
entry: CmsEntry;
|
|
1968
|
-
model:
|
|
1970
|
+
model: CmsModel;
|
|
1969
1971
|
storageEntry: CmsEntry;
|
|
1970
1972
|
}
|
|
1971
1973
|
export interface OnEntryRepublishErrorTopicParams {
|
|
1972
1974
|
error: Error;
|
|
1973
1975
|
entry: CmsEntry;
|
|
1974
|
-
model:
|
|
1976
|
+
model: CmsModel;
|
|
1975
1977
|
}
|
|
1976
1978
|
/**
|
|
1977
1979
|
* Unpublish
|
|
1978
1980
|
*/
|
|
1979
1981
|
export interface OnEntryBeforeUnpublishTopicParams {
|
|
1980
1982
|
entry: CmsEntry;
|
|
1981
|
-
model:
|
|
1983
|
+
model: CmsModel;
|
|
1982
1984
|
}
|
|
1983
1985
|
export interface OnEntryAfterUnpublishTopicParams {
|
|
1984
1986
|
entry: CmsEntry;
|
|
1985
|
-
model:
|
|
1987
|
+
model: CmsModel;
|
|
1986
1988
|
storageEntry: CmsEntry;
|
|
1987
1989
|
}
|
|
1988
1990
|
export interface OnEntryUnpublishErrorTopicParams {
|
|
@@ -1992,37 +1994,37 @@ export interface OnEntryUnpublishErrorTopicParams {
|
|
|
1992
1994
|
}
|
|
1993
1995
|
export interface OnEntryBeforeDeleteTopicParams {
|
|
1994
1996
|
entry: CmsEntry;
|
|
1995
|
-
model:
|
|
1997
|
+
model: CmsModel;
|
|
1996
1998
|
}
|
|
1997
1999
|
export interface OnEntryAfterDeleteTopicParams {
|
|
1998
2000
|
entry: CmsEntry;
|
|
1999
|
-
model:
|
|
2001
|
+
model: CmsModel;
|
|
2000
2002
|
}
|
|
2001
2003
|
export interface OnEntryDeleteErrorTopicParams {
|
|
2002
2004
|
error: Error;
|
|
2003
2005
|
entry: CmsEntry;
|
|
2004
|
-
model:
|
|
2006
|
+
model: CmsModel;
|
|
2005
2007
|
}
|
|
2006
2008
|
export interface OnEntryRevisionBeforeDeleteTopicParams {
|
|
2007
2009
|
entry: CmsEntry;
|
|
2008
|
-
model:
|
|
2010
|
+
model: CmsModel;
|
|
2009
2011
|
}
|
|
2010
2012
|
export interface OnEntryRevisionAfterDeleteTopicParams {
|
|
2011
2013
|
entry: CmsEntry;
|
|
2012
|
-
model:
|
|
2014
|
+
model: CmsModel;
|
|
2013
2015
|
}
|
|
2014
2016
|
export interface OnEntryRevisionDeleteErrorTopicParams {
|
|
2015
2017
|
error: Error;
|
|
2016
2018
|
entry: CmsEntry;
|
|
2017
|
-
model:
|
|
2019
|
+
model: CmsModel;
|
|
2018
2020
|
}
|
|
2019
2021
|
export interface OnEntryBeforeGetTopicParams {
|
|
2020
|
-
model:
|
|
2022
|
+
model: CmsModel;
|
|
2021
2023
|
where: CmsEntryListWhere;
|
|
2022
2024
|
}
|
|
2023
2025
|
export interface EntryBeforeListTopicParams {
|
|
2024
2026
|
where: CmsEntryListWhere;
|
|
2025
|
-
model:
|
|
2027
|
+
model: CmsModel;
|
|
2026
2028
|
}
|
|
2027
2029
|
/**
|
|
2028
2030
|
* @category Context
|
|
@@ -2551,71 +2553,71 @@ export interface CmsEntryStorageOperations<T extends CmsStorageEntry = CmsStorag
|
|
|
2551
2553
|
/**
|
|
2552
2554
|
* Get all the entries of the ids.
|
|
2553
2555
|
*/
|
|
2554
|
-
getByIds: (model:
|
|
2556
|
+
getByIds: (model: CmsModel, params: CmsEntryStorageOperationsGetByIdsParams) => Promise<T[]>;
|
|
2555
2557
|
/**
|
|
2556
2558
|
* Get all the published entries of the ids.
|
|
2557
2559
|
*/
|
|
2558
|
-
getPublishedByIds: (model:
|
|
2560
|
+
getPublishedByIds: (model: CmsModel, params: CmsEntryStorageOperationsGetPublishedByIdsParams) => Promise<T[]>;
|
|
2559
2561
|
/**
|
|
2560
2562
|
* Get all the latest entries of the ids.
|
|
2561
2563
|
*/
|
|
2562
|
-
getLatestByIds: (model:
|
|
2564
|
+
getLatestByIds: (model: CmsModel, params: CmsEntryStorageOperationsGetLatestByIdsParams) => Promise<T[]>;
|
|
2563
2565
|
/**
|
|
2564
2566
|
* Get all revisions of the given entry id.
|
|
2565
2567
|
*/
|
|
2566
|
-
getRevisions: (model:
|
|
2568
|
+
getRevisions: (model: CmsModel, params: CmsEntryStorageOperationsGetRevisionsParams) => Promise<T[]>;
|
|
2567
2569
|
/**
|
|
2568
2570
|
* Get the entry by the given revision id.
|
|
2569
2571
|
*/
|
|
2570
|
-
getRevisionById: (model:
|
|
2572
|
+
getRevisionById: (model: CmsModel, params: CmsEntryStorageOperationsGetRevisionParams) => Promise<T | null>;
|
|
2571
2573
|
/**
|
|
2572
2574
|
* Get the published entry by given entryId.
|
|
2573
2575
|
*/
|
|
2574
|
-
getPublishedRevisionByEntryId: (model:
|
|
2576
|
+
getPublishedRevisionByEntryId: (model: CmsModel, params: CmsEntryStorageOperationsGetPublishedRevisionParams) => Promise<T | null>;
|
|
2575
2577
|
/**
|
|
2576
2578
|
* Get the latest entry by given entryId.
|
|
2577
2579
|
*/
|
|
2578
|
-
getLatestRevisionByEntryId: (model:
|
|
2580
|
+
getLatestRevisionByEntryId: (model: CmsModel, params: CmsEntryStorageOperationsGetLatestRevisionParams) => Promise<T | null>;
|
|
2579
2581
|
/**
|
|
2580
2582
|
* Get the revision of the entry before given one.
|
|
2581
2583
|
*/
|
|
2582
|
-
getPreviousRevision: (model:
|
|
2584
|
+
getPreviousRevision: (model: CmsModel, params: CmsEntryStorageOperationsGetPreviousRevisionParams) => Promise<T | null>;
|
|
2583
2585
|
/**
|
|
2584
2586
|
* Gets entry by given params.
|
|
2585
2587
|
*/
|
|
2586
|
-
get: (model:
|
|
2588
|
+
get: (model: CmsModel, params: CmsEntryStorageOperationsGetParams) => Promise<T | null>;
|
|
2587
2589
|
/**
|
|
2588
2590
|
* List all entries. Filterable via params.
|
|
2589
2591
|
*/
|
|
2590
|
-
list: (model:
|
|
2592
|
+
list: (model: CmsModel, params: CmsEntryStorageOperationsListParams) => Promise<CmsEntryStorageOperationsListResponse<T>>;
|
|
2591
2593
|
/**
|
|
2592
2594
|
* Create a new entry.
|
|
2593
2595
|
*/
|
|
2594
|
-
create: (model:
|
|
2596
|
+
create: (model: CmsModel, params: CmsEntryStorageOperationsCreateParams<T>) => Promise<T>;
|
|
2595
2597
|
/**
|
|
2596
2598
|
* Create a new entry from existing one.
|
|
2597
2599
|
*/
|
|
2598
|
-
createRevisionFrom: (model:
|
|
2600
|
+
createRevisionFrom: (model: CmsModel, params: CmsEntryStorageOperationsCreateRevisionFromParams<T>) => Promise<T>;
|
|
2599
2601
|
/**
|
|
2600
2602
|
* Update existing entry.
|
|
2601
2603
|
*/
|
|
2602
|
-
update: (model:
|
|
2604
|
+
update: (model: CmsModel, params: CmsEntryStorageOperationsUpdateParams<T>) => Promise<T>;
|
|
2603
2605
|
/**
|
|
2604
2606
|
* Delete the entry revision.
|
|
2605
2607
|
*/
|
|
2606
|
-
deleteRevision: (model:
|
|
2608
|
+
deleteRevision: (model: CmsModel, params: CmsEntryStorageOperationsDeleteRevisionParams<T>) => Promise<void>;
|
|
2607
2609
|
/**
|
|
2608
2610
|
* Delete the entry.
|
|
2609
2611
|
*/
|
|
2610
|
-
delete: (model:
|
|
2612
|
+
delete: (model: CmsModel, params: CmsEntryStorageOperationsDeleteParams) => Promise<void>;
|
|
2611
2613
|
/**
|
|
2612
2614
|
* Publish the entry.
|
|
2613
2615
|
*/
|
|
2614
|
-
publish: (model:
|
|
2616
|
+
publish: (model: CmsModel, params: CmsEntryStorageOperationsPublishParams<T>) => Promise<T>;
|
|
2615
2617
|
/**
|
|
2616
2618
|
* Unpublish the entry.
|
|
2617
2619
|
*/
|
|
2618
|
-
unpublish: (model:
|
|
2620
|
+
unpublish: (model: CmsModel, params: CmsEntryStorageOperationsUnpublishParams<T>) => Promise<T>;
|
|
2619
2621
|
}
|
|
2620
2622
|
export declare enum CONTENT_ENTRY_STATUS {
|
|
2621
2623
|
DRAFT = "draft",
|
|
@@ -2687,7 +2689,7 @@ export interface HeadlessCmsStorageOperations<C = CmsContext> {
|
|
|
2687
2689
|
/**
|
|
2688
2690
|
* Either attach something from the storage operations or run something in it.
|
|
2689
2691
|
*/
|
|
2690
|
-
beforeInit
|
|
2692
|
+
beforeInit: (context: C) => Promise<void>;
|
|
2691
2693
|
init?: (context: C) => Promise<void>;
|
|
2692
2694
|
}
|
|
2693
2695
|
export {};
|