@webiny/api-headless-cms 6.3.0-beta.1 → 6.3.0-beta.3
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/crud/contentEntry/entryDataFactories/createEntryData.js +1 -1
- package/crud/contentEntry/entryDataFactories/createEntryData.js.map +1 -1
- package/features/contentModel/ContentModelFeature.js +2 -0
- package/features/contentModel/ContentModelFeature.js.map +1 -1
- package/features/contentModel/CreateModel/CreateModelRepository.d.ts +11 -11
- package/features/contentModel/CreateModel/CreateModelRepository.js +12 -10
- package/features/contentModel/CreateModel/CreateModelRepository.js.map +1 -1
- package/features/contentModel/CreateModelFrom/CreateModelFromRepository.d.ts +11 -12
- package/features/contentModel/CreateModelFrom/CreateModelFromRepository.js +12 -11
- package/features/contentModel/CreateModelFrom/CreateModelFromRepository.js.map +1 -1
- package/features/contentModel/ModelFieldCompression/ModelFieldCompression.d.ts +15 -0
- package/features/contentModel/ModelFieldCompression/ModelFieldCompression.js +27 -0
- package/features/contentModel/ModelFieldCompression/ModelFieldCompression.js.map +1 -0
- package/features/contentModel/ModelFieldCompression/abstractions.d.ts +17 -0
- package/features/contentModel/ModelFieldCompression/abstractions.js +4 -0
- package/features/contentModel/ModelFieldCompression/abstractions.js.map +1 -0
- package/features/contentModel/ModelFieldCompression/feature.d.ts +4 -0
- package/features/contentModel/ModelFieldCompression/feature.js +10 -0
- package/features/contentModel/ModelFieldCompression/feature.js.map +1 -0
- package/features/contentModel/ModelFieldCompression/index.d.ts +1 -0
- package/features/contentModel/ModelFieldCompression/index.js +3 -0
- package/features/contentModel/ModelFieldCompression/index.js.map +1 -0
- package/features/contentModel/UpdateModel/UpdateModelRepository.d.ts +9 -9
- package/features/contentModel/UpdateModel/UpdateModelRepository.js +13 -10
- package/features/contentModel/UpdateModel/UpdateModelRepository.js.map +1 -1
- package/features/contentModel/shared/ModelsFetcher.d.ts +7 -5
- package/features/contentModel/shared/ModelsFetcher.js +13 -3
- package/features/contentModel/shared/ModelsFetcher.js.map +1 -1
- package/features/modelBuilder/fields/DateTimeFieldType.js +20 -0
- package/features/modelBuilder/fields/DateTimeFieldType.js.map +1 -1
- package/graphql/schema/cms/createEntryResolver.js +9 -0
- package/graphql/schema/cms/createEntryResolver.js.map +1 -1
- package/graphql/schema/cms/deleteEntryResolver.js +9 -0
- package/graphql/schema/cms/deleteEntryResolver.js.map +1 -1
- package/graphql/schema/cms/getEntryResolver.js +9 -0
- package/graphql/schema/cms/getEntryResolver.js.map +1 -1
- package/graphql/schema/cms/listEntriesResolver.js +14 -0
- package/graphql/schema/cms/listEntriesResolver.js.map +1 -1
- package/graphql/schema/cms/publishEntryResolver.js +9 -0
- package/graphql/schema/cms/publishEntryResolver.js.map +1 -1
- package/graphql/schema/cms/unpublishEntryResolver.js +9 -0
- package/graphql/schema/cms/unpublishEntryResolver.js.map +1 -1
- package/graphql/schema/cms/updateEntryResolver.js +9 -0
- package/graphql/schema/cms/updateEntryResolver.js.map +1 -1
- package/package.json +28 -25
- package/types/model.d.ts +7 -0
- package/types/model.js.map +1 -1
- package/types/types.d.ts +8 -8
- package/types/types.js.map +1 -1
- package/utils/toSlug.js +1 -1
- package/utils/toSlug.js.map +1 -1
|
@@ -55,7 +55,7 @@ const getDefaultValue = field => {
|
|
|
55
55
|
const createEntryId = input => {
|
|
56
56
|
let entryId = mdbid();
|
|
57
57
|
if (input.id) {
|
|
58
|
-
if (input.id.match(/^([a-zA-Z0-9])([a-zA-Z0-9
|
|
58
|
+
if (input.id.match(/^([a-zA-Z0-9])([a-zA-Z0-9-]+)([a-zA-Z0-9])$/) === null) {
|
|
59
59
|
throw new WebinyError("The provided ID is not valid. It must be a string which can be A-Z, a-z, 0-9, - and it cannot start or end with a -.", "INVALID_ID", {
|
|
60
60
|
id: input.id
|
|
61
61
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getDate","ROOT_FOLDER","WebinyError","validateModelEntryDataOrThrow","referenceFieldsMapping","createIdentifier","mdbid","STATUS_DRAFT","STATUS_PUBLISHED","STATUS_UNPUBLISHED","getIdentity","NotAuthorizedError","getSystem","convertDefaultValue","field","value","type","Boolean","Number","getDefaultValue","settings","list","defaultValue","undefined","predefinedValues","enabled","Array","isArray","values","selectedValue","find","selected","filter","map","createEntryId","input","entryId","id","match","version","cleanInputValues","model","fields","reduce","acc","fieldId","key","createEntryData","rawInput","options","context","getSecurityIdentity","getTenant","accessControl","initialValues","skipValidators","validateEntries","currentIdentity","currentDateTime","Date","status","canPublish","canAccessEntry","pw","modelId","canUnpublish","locked","revisionLevelPublishingMetaFields","revisionFirstPublishedOn","revisionLastPublishedOn","revisionFirstPublishedBy","revisionLastPublishedBy","entryLevelPublishingMetaFields","firstPublishedOn","lastPublishedOn","firstPublishedBy","lastPublishedBy","entry","tenant","createdOn","modifiedOn","savedOn","deletedOn","restoredOn","createdBy","modifiedBy","savedBy","deletedBy","restoredBy","revisionCreatedOn","revisionModifiedOn","revisionSavedOn","revisionDeletedOn","revisionRestoredOn","revisionCreatedBy","revisionModifiedBy","revisionSavedBy","revisionDeletedBy","revisionRestoredBy","location","folderId","wbyAco_location","system","live","structuredClone"],"sources":["createEntryData.ts"],"sourcesContent":["import type {\n CmsContext,\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CmsModelField,\n CreateCmsEntryInput,\n CreateCmsEntryOptionsInput\n} from \"~/types/index.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { ROOT_FOLDER } from \"~/constants.js\";\nimport WebinyError from \"@webiny/error\";\nimport { validateModelEntryDataOrThrow } from \"~/crud/contentEntry/entryDataValidation.js\";\nimport { referenceFieldsMapping } from \"~/crud/contentEntry/referenceFieldsMapping.js\";\nimport { createIdentifier, mdbid } from \"@webiny/utils\";\nimport { STATUS_DRAFT, STATUS_PUBLISHED, STATUS_UNPUBLISHED } from \"./statuses.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport type { AccessControl } from \"~/crud/AccessControl/AccessControl.js\";\nimport { NotAuthorizedError } from \"~/utils/errors.js\";\nimport { getSystem } from \"./system.js\";\nimport type { SecurityIdentity } from \"@webiny/api-core/types/security.js\";\nimport type { Tenant } from \"@webiny/api-core/types/tenancy.js\";\n\ntype DefaultValue = boolean | number | string | null;\n\n/**\n * Used for some fields to convert their values.\n */\nconst convertDefaultValue = (field: CmsModelField, value: DefaultValue): DefaultValue => {\n switch (field.type) {\n case \"boolean\":\n return Boolean(value);\n case \"number\":\n return Number(value);\n default:\n return value;\n }\n};\n\nconst getDefaultValue = (field: CmsModelField): (DefaultValue | DefaultValue[]) | undefined => {\n const { settings, list } = field;\n if (settings && settings.defaultValue !== undefined) {\n return convertDefaultValue(field, settings.defaultValue);\n }\n const { predefinedValues } = field;\n if (\n !predefinedValues ||\n !predefinedValues.enabled ||\n Array.isArray(predefinedValues.values) === false\n ) {\n return undefined;\n }\n if (!list) {\n const selectedValue = predefinedValues.values.find(value => {\n return !!value.selected;\n });\n if (selectedValue) {\n return convertDefaultValue(field, selectedValue.value);\n }\n return undefined;\n }\n return predefinedValues.values\n .filter(({ selected }) => !!selected)\n .map(({ value }) => {\n return convertDefaultValue(field, value);\n });\n};\n\nconst createEntryId = (input: CreateCmsEntryInput) => {\n let entryId = mdbid();\n if (input.id) {\n if (input.id.match(/^([a-zA-Z0-9])([a-zA-Z0-9\\-]+)([a-zA-Z0-9])$/) === null) {\n throw new WebinyError(\n \"The provided ID is not valid. It must be a string which can be A-Z, a-z, 0-9, - and it cannot start or end with a -.\",\n \"INVALID_ID\",\n {\n id: input.id\n }\n );\n }\n entryId = input.id;\n }\n const version = 1;\n return {\n entryId,\n version,\n id: createIdentifier({\n id: entryId,\n version\n })\n };\n};\n\n/**\n * Cleans and adds default values to create input data.\n */\nconst cleanInputValues = <TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n input: TValues\n) => {\n return model.fields.reduce<TValues>((acc, field) => {\n /**\n * This should never happen, but let's make it sure.\n * The fix would be for the user to add the fieldId on the field definition.\n */\n if (!field.fieldId) {\n throw new WebinyError(\"Field does not have an fieldId.\", \"MISSING_FIELD_ID\", {\n field\n });\n }\n const key = field.fieldId as keyof TValues;\n const value = input[key] as TValues[keyof TValues];\n /**\n * We set the default value on create input if value is not defined.\n */\n acc[key] = value === undefined ? (getDefaultValue(field) as TValues[keyof TValues]) : value;\n return acc;\n }, {} as TValues);\n};\n\ninterface CreateEntryDataParams<TValues extends CmsEntryValues = CmsEntryValues> {\n model: CmsModel;\n rawInput: CreateCmsEntryInput<TValues>;\n options?: CreateCmsEntryOptionsInput;\n context: CmsContext;\n getIdentity: () => SecurityIdentity;\n getTenant: () => Tenant;\n accessControl: AccessControl;\n}\n\ninterface ICreateEntryDataResponse<TValues extends CmsEntryValues = CmsEntryValues> {\n entry: CmsEntry<TValues>;\n input: CreateCmsEntryInput<TValues>;\n}\n\nexport const createEntryData = async <TValues extends CmsEntryValues = CmsEntryValues>({\n model,\n rawInput,\n options,\n context,\n getIdentity: getSecurityIdentity,\n getTenant,\n accessControl\n}: CreateEntryDataParams<TValues>): Promise<ICreateEntryDataResponse<TValues>> => {\n const initialValues = cleanInputValues<TValues>(model, rawInput.values || ({} as TValues));\n\n await validateModelEntryDataOrThrow({\n context,\n model,\n values: initialValues,\n skipValidators: options?.skipValidators\n });\n\n const values = await referenceFieldsMapping<TValues>({\n context,\n model,\n values: initialValues,\n validateEntries: true\n });\n\n const { id, entryId, version } = createEntryId(rawInput);\n\n /**\n * There is a possibility that user sends an ID in the input, so we will use that one.\n * There is no check if the ID is unique or not, that is up to the user.\n */\n const currentIdentity = getSecurityIdentity();\n const currentDateTime = new Date();\n\n /**\n * Users can set the initial status of the entry. If so, we need to make\n * sure they have the required permissions and also that all the fields\n * are filled in correctly.\n */\n const status = rawInput.status || STATUS_DRAFT;\n if (status !== STATUS_DRAFT) {\n if (status === STATUS_PUBLISHED) {\n const canPublish = await accessControl.canAccessEntry({ model, pw: \"p\" });\n if (!canPublish) {\n throw new NotAuthorizedError(`Not allowed to access \"${model.modelId}\" entries.`);\n }\n } else if (status === STATUS_UNPUBLISHED) {\n const canUnpublish = await accessControl.canAccessEntry({ model, pw: \"u\" });\n if (!canUnpublish) {\n throw new NotAuthorizedError(`Not allowed to access \"${model.modelId}\" entries.`);\n }\n }\n }\n\n const locked = status !== STATUS_DRAFT;\n\n let revisionLevelPublishingMetaFields: Pick<\n CmsEntry,\n | \"revisionFirstPublishedOn\"\n | \"revisionLastPublishedOn\"\n | \"revisionFirstPublishedBy\"\n | \"revisionLastPublishedBy\"\n > = {\n revisionFirstPublishedOn: null,\n revisionLastPublishedOn: null,\n revisionFirstPublishedBy: null,\n revisionLastPublishedBy: null\n };\n\n let entryLevelPublishingMetaFields: Pick<\n CmsEntry,\n \"firstPublishedOn\" | \"lastPublishedOn\" | \"firstPublishedBy\" | \"lastPublishedBy\"\n > = {\n firstPublishedOn: null,\n lastPublishedOn: null,\n firstPublishedBy: null,\n lastPublishedBy: null\n };\n\n if (status === STATUS_PUBLISHED) {\n revisionLevelPublishingMetaFields = {\n revisionFirstPublishedOn: getDate(rawInput.revisionFirstPublishedOn, currentDateTime),\n revisionLastPublishedOn: getDate(rawInput.revisionLastPublishedOn, currentDateTime),\n revisionFirstPublishedBy: getIdentity(\n rawInput.revisionFirstPublishedBy,\n currentIdentity\n ),\n revisionLastPublishedBy: getIdentity(rawInput.revisionLastPublishedBy, currentIdentity)\n };\n\n entryLevelPublishingMetaFields = {\n firstPublishedOn: getDate(rawInput.firstPublishedOn, currentDateTime),\n lastPublishedOn: getDate(rawInput.lastPublishedOn, currentDateTime),\n firstPublishedBy: getIdentity(rawInput.firstPublishedBy, currentIdentity),\n lastPublishedBy: getIdentity(rawInput.lastPublishedBy, currentIdentity)\n };\n }\n\n const entry: CmsEntry<TValues> = {\n tenant: getTenant().id,\n entryId,\n id,\n modelId: model.modelId,\n\n /**\n * Entry-level meta fields. 👇\n */\n createdOn: getDate(rawInput.createdOn, currentDateTime),\n modifiedOn: getDate(rawInput.modifiedOn, null),\n savedOn: getDate(rawInput.savedOn, currentDateTime),\n deletedOn: getDate(rawInput.deletedOn, null),\n restoredOn: getDate(rawInput.restoredOn, null),\n createdBy: getIdentity(rawInput.createdBy, currentIdentity)!,\n modifiedBy: getIdentity(rawInput.modifiedBy, null),\n savedBy: getIdentity(rawInput.savedBy, currentIdentity)!,\n deletedBy: getIdentity(rawInput.deletedBy, null),\n restoredBy: getIdentity(rawInput.restoredBy, null),\n ...entryLevelPublishingMetaFields,\n\n /**\n * Revision-level meta fields. 👇\n */\n revisionCreatedOn: getDate(rawInput.revisionCreatedOn, currentDateTime),\n revisionModifiedOn: getDate(rawInput.revisionModifiedOn, null),\n revisionSavedOn: getDate(rawInput.revisionSavedOn, currentDateTime),\n revisionDeletedOn: getDate(rawInput.revisionDeletedOn, null),\n revisionRestoredOn: getDate(rawInput.revisionRestoredOn, null),\n revisionCreatedBy: getIdentity(rawInput.revisionCreatedBy, currentIdentity)!,\n revisionModifiedBy: getIdentity(rawInput.revisionModifiedBy, null),\n revisionSavedBy: getIdentity(rawInput.revisionSavedBy, currentIdentity)!,\n revisionDeletedBy: getIdentity(rawInput.revisionDeletedBy, null),\n revisionRestoredBy: getIdentity(rawInput.revisionRestoredBy, null),\n ...revisionLevelPublishingMetaFields,\n\n version,\n status,\n locked,\n values,\n location: {\n folderId:\n rawInput.location?.folderId || rawInput.wbyAco_location?.folderId || ROOT_FOLDER\n },\n system: getSystem({\n input: rawInput\n }),\n live:\n status === STATUS_PUBLISHED\n ? {\n version\n }\n : null\n };\n\n if (status !== STATUS_DRAFT) {\n if (status === STATUS_PUBLISHED) {\n const canPublish = await accessControl.canAccessEntry({ model, entry, pw: \"p\" });\n if (!canPublish) {\n throw new NotAuthorizedError(`Not allowed to access entry \"${entry.entryId}\".`);\n }\n } else if (status === STATUS_UNPUBLISHED) {\n const canUnpublish = await accessControl.canAccessEntry({ model, entry, pw: \"u\" });\n if (!canUnpublish) {\n throw new NotAuthorizedError(`Not allowed to access entry \"${entry.entryId}\".`);\n }\n }\n }\n\n return {\n entry,\n input: {\n ...rawInput,\n values: structuredClone(values)\n }\n };\n};\n"],"mappings":"AASA,SAASA,OAAO;AAChB,SAASC,WAAW;AACpB,OAAOC,WAAW,MAAM,eAAe;AACvC,SAASC,6BAA6B;AACtC,SAASC,sBAAsB;AAC/B,SAASC,gBAAgB,EAAEC,KAAK,QAAQ,eAAe;AACvD,SAASC,YAAY,EAAEC,gBAAgB,EAAEC,kBAAkB;AAC3D,SAASC,WAAW;AAEpB,SAASC,kBAAkB;AAC3B,SAASC,SAAS;AAMlB;AACA;AACA;AACA,MAAMC,mBAAmB,GAAGA,CAACC,KAAoB,EAAEC,KAAmB,KAAmB;EACrF,QAAQD,KAAK,CAACE,IAAI;IACd,KAAK,SAAS;MACV,OAAOC,OAAO,CAACF,KAAK,CAAC;IACzB,KAAK,QAAQ;MACT,OAAOG,MAAM,CAACH,KAAK,CAAC;IACxB;MACI,OAAOA,KAAK;EACpB;AACJ,CAAC;AAED,MAAMI,eAAe,GAAIL,KAAoB,IAAkD;EAC3F,MAAM;IAAEM,QAAQ;IAAEC;EAAK,CAAC,GAAGP,KAAK;EAChC,IAAIM,QAAQ,IAAIA,QAAQ,CAACE,YAAY,KAAKC,SAAS,EAAE;IACjD,OAAOV,mBAAmB,CAACC,KAAK,EAAEM,QAAQ,CAACE,YAAY,CAAC;EAC5D;EACA,MAAM;IAAEE;EAAiB,CAAC,GAAGV,KAAK;EAClC,IACI,CAACU,gBAAgB,IACjB,CAACA,gBAAgB,CAACC,OAAO,IACzBC,KAAK,CAACC,OAAO,CAACH,gBAAgB,CAACI,MAAM,CAAC,KAAK,KAAK,EAClD;IACE,OAAOL,SAAS;EACpB;EACA,IAAI,CAACF,IAAI,EAAE;IACP,MAAMQ,aAAa,GAAGL,gBAAgB,CAACI,MAAM,CAACE,IAAI,CAACf,KAAK,IAAI;MACxD,OAAO,CAAC,CAACA,KAAK,CAACgB,QAAQ;IAC3B,CAAC,CAAC;IACF,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;IACzB,IAAIqD,MAAM,KAAKpD,gBAAgB,EAAE;MAC7B,MAAMqD,UAAU,GAAG,MAAMR,aAAa,CAACS,cAAc,CAAC;QAAErB,KAAK;QAAEoC,KAAK;QAAEd,EAAE,EAAE;MAAI,CAAC,CAAC;MAChF,IAAI,CAACF,UAAU,EAAE;QACb,MAAM,IAAIlD,kBAAkB,CAAC,gCAAgCkE,KAAK,CAACzC,OAAO,IAAI,CAAC;MACnF;IACJ,CAAC,MAAM,IAAIwB,MAAM,KAAKnD,kBAAkB,EAAE;MACtC,MAAMwD,YAAY,GAAG,MAAMZ,aAAa,CAACS,cAAc,CAAC;QAAErB,KAAK;QAAEoC,KAAK;QAAEd,EAAE,EAAE;MAAI,CAAC,CAAC;MAClF,IAAI,CAACE,YAAY,EAAE;QACf,MAAM,IAAItD,kBAAkB,CAAC,gCAAgCkE,KAAK,CAACzC,OAAO,IAAI,CAAC;MACnF;IACJ;EACJ;EAEA,OAAO;IACHyC,KAAK;IACL1C,KAAK,EAAE;MACH,GAAGa,QAAQ;MACXpB,MAAM,EAAE4E,eAAe,CAAC5E,MAAM;IAClC;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["getDate","ROOT_FOLDER","WebinyError","validateModelEntryDataOrThrow","referenceFieldsMapping","createIdentifier","mdbid","STATUS_DRAFT","STATUS_PUBLISHED","STATUS_UNPUBLISHED","getIdentity","NotAuthorizedError","getSystem","convertDefaultValue","field","value","type","Boolean","Number","getDefaultValue","settings","list","defaultValue","undefined","predefinedValues","enabled","Array","isArray","values","selectedValue","find","selected","filter","map","createEntryId","input","entryId","id","match","version","cleanInputValues","model","fields","reduce","acc","fieldId","key","createEntryData","rawInput","options","context","getSecurityIdentity","getTenant","accessControl","initialValues","skipValidators","validateEntries","currentIdentity","currentDateTime","Date","status","canPublish","canAccessEntry","pw","modelId","canUnpublish","locked","revisionLevelPublishingMetaFields","revisionFirstPublishedOn","revisionLastPublishedOn","revisionFirstPublishedBy","revisionLastPublishedBy","entryLevelPublishingMetaFields","firstPublishedOn","lastPublishedOn","firstPublishedBy","lastPublishedBy","entry","tenant","createdOn","modifiedOn","savedOn","deletedOn","restoredOn","createdBy","modifiedBy","savedBy","deletedBy","restoredBy","revisionCreatedOn","revisionModifiedOn","revisionSavedOn","revisionDeletedOn","revisionRestoredOn","revisionCreatedBy","revisionModifiedBy","revisionSavedBy","revisionDeletedBy","revisionRestoredBy","location","folderId","wbyAco_location","system","live","structuredClone"],"sources":["createEntryData.ts"],"sourcesContent":["import type {\n CmsContext,\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CmsModelField,\n CreateCmsEntryInput,\n CreateCmsEntryOptionsInput\n} from \"~/types/index.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { ROOT_FOLDER } from \"~/constants.js\";\nimport WebinyError from \"@webiny/error\";\nimport { validateModelEntryDataOrThrow } from \"~/crud/contentEntry/entryDataValidation.js\";\nimport { referenceFieldsMapping } from \"~/crud/contentEntry/referenceFieldsMapping.js\";\nimport { createIdentifier, mdbid } from \"@webiny/utils\";\nimport { STATUS_DRAFT, STATUS_PUBLISHED, STATUS_UNPUBLISHED } from \"./statuses.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport type { AccessControl } from \"~/crud/AccessControl/AccessControl.js\";\nimport { NotAuthorizedError } from \"~/utils/errors.js\";\nimport { getSystem } from \"./system.js\";\nimport type { SecurityIdentity } from \"@webiny/api-core/types/security.js\";\nimport type { Tenant } from \"@webiny/api-core/types/tenancy.js\";\n\ntype DefaultValue = boolean | number | string | null;\n\n/**\n * Used for some fields to convert their values.\n */\nconst convertDefaultValue = (field: CmsModelField, value: DefaultValue): DefaultValue => {\n switch (field.type) {\n case \"boolean\":\n return Boolean(value);\n case \"number\":\n return Number(value);\n default:\n return value;\n }\n};\n\nconst getDefaultValue = (field: CmsModelField): (DefaultValue | DefaultValue[]) | undefined => {\n const { settings, list } = field;\n if (settings && settings.defaultValue !== undefined) {\n return convertDefaultValue(field, settings.defaultValue);\n }\n const { predefinedValues } = field;\n if (\n !predefinedValues ||\n !predefinedValues.enabled ||\n Array.isArray(predefinedValues.values) === false\n ) {\n return undefined;\n }\n if (!list) {\n const selectedValue = predefinedValues.values.find(value => {\n return !!value.selected;\n });\n if (selectedValue) {\n return convertDefaultValue(field, selectedValue.value);\n }\n return undefined;\n }\n return predefinedValues.values\n .filter(({ selected }) => !!selected)\n .map(({ value }) => {\n return convertDefaultValue(field, value);\n });\n};\n\nconst createEntryId = (input: CreateCmsEntryInput) => {\n let entryId = mdbid();\n if (input.id) {\n if (input.id.match(/^([a-zA-Z0-9])([a-zA-Z0-9-]+)([a-zA-Z0-9])$/) === null) {\n throw new WebinyError(\n \"The provided ID is not valid. It must be a string which can be A-Z, a-z, 0-9, - and it cannot start or end with a -.\",\n \"INVALID_ID\",\n {\n id: input.id\n }\n );\n }\n entryId = input.id;\n }\n const version = 1;\n return {\n entryId,\n version,\n id: createIdentifier({\n id: entryId,\n version\n })\n };\n};\n\n/**\n * Cleans and adds default values to create input data.\n */\nconst cleanInputValues = <TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n input: TValues\n) => {\n return model.fields.reduce<TValues>((acc, field) => {\n /**\n * This should never happen, but let's make it sure.\n * The fix would be for the user to add the fieldId on the field definition.\n */\n if (!field.fieldId) {\n throw new WebinyError(\"Field does not have an fieldId.\", \"MISSING_FIELD_ID\", {\n field\n });\n }\n const key = field.fieldId as keyof TValues;\n const value = input[key] as TValues[keyof TValues];\n /**\n * We set the default value on create input if value is not defined.\n */\n acc[key] = value === undefined ? (getDefaultValue(field) as TValues[keyof TValues]) : value;\n return acc;\n }, {} as TValues);\n};\n\ninterface CreateEntryDataParams<TValues extends CmsEntryValues = CmsEntryValues> {\n model: CmsModel;\n rawInput: CreateCmsEntryInput<TValues>;\n options?: CreateCmsEntryOptionsInput;\n context: CmsContext;\n getIdentity: () => SecurityIdentity;\n getTenant: () => Tenant;\n accessControl: AccessControl;\n}\n\ninterface ICreateEntryDataResponse<TValues extends CmsEntryValues = CmsEntryValues> {\n entry: CmsEntry<TValues>;\n input: CreateCmsEntryInput<TValues>;\n}\n\nexport const createEntryData = async <TValues extends CmsEntryValues = CmsEntryValues>({\n model,\n rawInput,\n options,\n context,\n getIdentity: getSecurityIdentity,\n getTenant,\n accessControl\n}: CreateEntryDataParams<TValues>): Promise<ICreateEntryDataResponse<TValues>> => {\n const initialValues = cleanInputValues<TValues>(model, rawInput.values || ({} as TValues));\n\n await validateModelEntryDataOrThrow({\n context,\n model,\n values: initialValues,\n skipValidators: options?.skipValidators\n });\n\n const values = await referenceFieldsMapping<TValues>({\n context,\n model,\n values: initialValues,\n validateEntries: true\n });\n\n const { id, entryId, version } = createEntryId(rawInput);\n\n /**\n * There is a possibility that user sends an ID in the input, so we will use that one.\n * There is no check if the ID is unique or not, that is up to the user.\n */\n const currentIdentity = getSecurityIdentity();\n const currentDateTime = new Date();\n\n /**\n * Users can set the initial status of the entry. If so, we need to make\n * sure they have the required permissions and also that all the fields\n * are filled in correctly.\n */\n const status = rawInput.status || STATUS_DRAFT;\n if (status !== STATUS_DRAFT) {\n if (status === STATUS_PUBLISHED) {\n const canPublish = await accessControl.canAccessEntry({ model, pw: \"p\" });\n if (!canPublish) {\n throw new NotAuthorizedError(`Not allowed to access \"${model.modelId}\" entries.`);\n }\n } else if (status === STATUS_UNPUBLISHED) {\n const canUnpublish = await accessControl.canAccessEntry({ model, pw: \"u\" });\n if (!canUnpublish) {\n throw new NotAuthorizedError(`Not allowed to access \"${model.modelId}\" entries.`);\n }\n }\n }\n\n const locked = status !== STATUS_DRAFT;\n\n let revisionLevelPublishingMetaFields: Pick<\n CmsEntry,\n | \"revisionFirstPublishedOn\"\n | \"revisionLastPublishedOn\"\n | \"revisionFirstPublishedBy\"\n | \"revisionLastPublishedBy\"\n > = {\n revisionFirstPublishedOn: null,\n revisionLastPublishedOn: null,\n revisionFirstPublishedBy: null,\n revisionLastPublishedBy: null\n };\n\n let entryLevelPublishingMetaFields: Pick<\n CmsEntry,\n \"firstPublishedOn\" | \"lastPublishedOn\" | \"firstPublishedBy\" | \"lastPublishedBy\"\n > = {\n firstPublishedOn: null,\n lastPublishedOn: null,\n firstPublishedBy: null,\n lastPublishedBy: null\n };\n\n if (status === STATUS_PUBLISHED) {\n revisionLevelPublishingMetaFields = {\n revisionFirstPublishedOn: getDate(rawInput.revisionFirstPublishedOn, currentDateTime),\n revisionLastPublishedOn: getDate(rawInput.revisionLastPublishedOn, currentDateTime),\n revisionFirstPublishedBy: getIdentity(\n rawInput.revisionFirstPublishedBy,\n currentIdentity\n ),\n revisionLastPublishedBy: getIdentity(rawInput.revisionLastPublishedBy, currentIdentity)\n };\n\n entryLevelPublishingMetaFields = {\n firstPublishedOn: getDate(rawInput.firstPublishedOn, currentDateTime),\n lastPublishedOn: getDate(rawInput.lastPublishedOn, currentDateTime),\n firstPublishedBy: getIdentity(rawInput.firstPublishedBy, currentIdentity),\n lastPublishedBy: getIdentity(rawInput.lastPublishedBy, currentIdentity)\n };\n }\n\n const entry: CmsEntry<TValues> = {\n tenant: getTenant().id,\n entryId,\n id,\n modelId: model.modelId,\n\n /**\n * Entry-level meta fields. 👇\n */\n createdOn: getDate(rawInput.createdOn, currentDateTime),\n modifiedOn: getDate(rawInput.modifiedOn, null),\n savedOn: getDate(rawInput.savedOn, currentDateTime),\n deletedOn: getDate(rawInput.deletedOn, null),\n restoredOn: getDate(rawInput.restoredOn, null),\n createdBy: getIdentity(rawInput.createdBy, currentIdentity)!,\n modifiedBy: getIdentity(rawInput.modifiedBy, null),\n savedBy: getIdentity(rawInput.savedBy, currentIdentity)!,\n deletedBy: getIdentity(rawInput.deletedBy, null),\n restoredBy: getIdentity(rawInput.restoredBy, null),\n ...entryLevelPublishingMetaFields,\n\n /**\n * Revision-level meta fields. 👇\n */\n revisionCreatedOn: getDate(rawInput.revisionCreatedOn, currentDateTime),\n revisionModifiedOn: getDate(rawInput.revisionModifiedOn, null),\n revisionSavedOn: getDate(rawInput.revisionSavedOn, currentDateTime),\n revisionDeletedOn: getDate(rawInput.revisionDeletedOn, null),\n revisionRestoredOn: getDate(rawInput.revisionRestoredOn, null),\n revisionCreatedBy: getIdentity(rawInput.revisionCreatedBy, currentIdentity)!,\n revisionModifiedBy: getIdentity(rawInput.revisionModifiedBy, null),\n revisionSavedBy: getIdentity(rawInput.revisionSavedBy, currentIdentity)!,\n revisionDeletedBy: getIdentity(rawInput.revisionDeletedBy, null),\n revisionRestoredBy: getIdentity(rawInput.revisionRestoredBy, null),\n ...revisionLevelPublishingMetaFields,\n\n version,\n status,\n locked,\n values,\n location: {\n folderId:\n rawInput.location?.folderId || rawInput.wbyAco_location?.folderId || ROOT_FOLDER\n },\n system: getSystem({\n input: rawInput\n }),\n live:\n status === STATUS_PUBLISHED\n ? {\n version\n }\n : null\n };\n\n if (status !== STATUS_DRAFT) {\n if (status === STATUS_PUBLISHED) {\n const canPublish = await accessControl.canAccessEntry({ model, entry, pw: \"p\" });\n if (!canPublish) {\n throw new NotAuthorizedError(`Not allowed to access entry \"${entry.entryId}\".`);\n }\n } else if (status === STATUS_UNPUBLISHED) {\n const canUnpublish = await accessControl.canAccessEntry({ model, entry, pw: \"u\" });\n if (!canUnpublish) {\n throw new NotAuthorizedError(`Not allowed to access entry \"${entry.entryId}\".`);\n }\n }\n }\n\n return {\n entry,\n input: {\n ...rawInput,\n values: structuredClone(values)\n }\n };\n};\n"],"mappings":"AASA,SAASA,OAAO;AAChB,SAASC,WAAW;AACpB,OAAOC,WAAW,MAAM,eAAe;AACvC,SAASC,6BAA6B;AACtC,SAASC,sBAAsB;AAC/B,SAASC,gBAAgB,EAAEC,KAAK,QAAQ,eAAe;AACvD,SAASC,YAAY,EAAEC,gBAAgB,EAAEC,kBAAkB;AAC3D,SAASC,WAAW;AAEpB,SAASC,kBAAkB;AAC3B,SAASC,SAAS;AAMlB;AACA;AACA;AACA,MAAMC,mBAAmB,GAAGA,CAACC,KAAoB,EAAEC,K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;QAAEd,EAAE,EAAE;MAAI,CAAC,CAAC;MAClF,IAAI,CAACE,YAAY,EAAE;QACf,MAAM,IAAItD,kBAAkB,CAAC,gCAAgCkE,KAAK,CAACzC,OAAO,IAAI,CAAC;MACnF;IACJ;EACJ;EAEA,OAAO;IACHyC,KAAK;IACL1C,KAAK,EAAE;MACH,GAAGa,QAAQ;MACXpB,MAAM,EAAE4E,eAAe,CAAC5E,MAAM;IAClC;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -10,6 +10,7 @@ import { DeleteModelFeature } from "./DeleteModel/feature.js";
|
|
|
10
10
|
import { GetModelFeature } from "./GetModel/feature.js";
|
|
11
11
|
import { ListModelsFeature } from "./ListModels/feature.js";
|
|
12
12
|
import { ModelToAstConverterFeature } from "./ModelToAstConverter/feature.js";
|
|
13
|
+
import { ModelFieldCompressionFeature } from "./ModelFieldCompression/feature.js";
|
|
13
14
|
export const ContentModelFeature = createFeature({
|
|
14
15
|
name: "ContentModel",
|
|
15
16
|
register(container) {
|
|
@@ -17,6 +18,7 @@ export const ContentModelFeature = createFeature({
|
|
|
17
18
|
container.register(PluginModelsProvider).inSingletonScope();
|
|
18
19
|
container.register(ModelsFetcher).inSingletonScope();
|
|
19
20
|
ModelToAstConverterFeature.register(container);
|
|
21
|
+
ModelFieldCompressionFeature.register(container);
|
|
20
22
|
|
|
21
23
|
// Query features
|
|
22
24
|
GetModelFeature.register(container);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createFeature","createMemoryCache","PluginModelsProvider","ModelCache","ModelsFetcher","CreateModelFeature","CreateModelFromFeature","UpdateModelFeature","DeleteModelFeature","GetModelFeature","ListModelsFeature","ModelToAstConverterFeature","ContentModelFeature","name","register","container","registerInstance","inSingletonScope"],"sources":["ContentModelFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { createMemoryCache } from \"~/utils/index.js\";\nimport { PluginModelsProvider } from \"
|
|
1
|
+
{"version":3,"names":["createFeature","createMemoryCache","PluginModelsProvider","ModelCache","ModelsFetcher","CreateModelFeature","CreateModelFromFeature","UpdateModelFeature","DeleteModelFeature","GetModelFeature","ListModelsFeature","ModelToAstConverterFeature","ModelFieldCompressionFeature","ContentModelFeature","name","register","container","registerInstance","inSingletonScope"],"sources":["ContentModelFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { createMemoryCache } from \"~/utils/index.js\";\nimport { PluginModelsProvider } from \"./shared/PluginModelsProvider.js\";\nimport { ModelCache } from \"./shared/abstractions.js\";\nimport { ModelsFetcher } from \"./shared/ModelsFetcher.js\";\nimport { CreateModelFeature } from \"./CreateModel/feature.js\";\nimport { CreateModelFromFeature } from \"./CreateModelFrom/feature.js\";\nimport { UpdateModelFeature } from \"./UpdateModel/feature.js\";\nimport { DeleteModelFeature } from \"./DeleteModel/feature.js\";\nimport { GetModelFeature } from \"./GetModel/feature.js\";\nimport { ListModelsFeature } from \"./ListModels/feature.js\";\nimport { ModelToAstConverterFeature } from \"./ModelToAstConverter/feature.js\";\nimport { ModelFieldCompressionFeature } from \"./ModelFieldCompression/feature.js\";\n\nexport const ContentModelFeature = createFeature({\n name: \"ContentModel\",\n register(container) {\n container.registerInstance(ModelCache, createMemoryCache());\n container.register(PluginModelsProvider).inSingletonScope();\n container.register(ModelsFetcher).inSingletonScope();\n\n ModelToAstConverterFeature.register(container);\n\n ModelFieldCompressionFeature.register(container);\n\n // Query features\n GetModelFeature.register(container);\n ListModelsFeature.register(container);\n\n // Command features\n CreateModelFeature.register(container);\n CreateModelFromFeature.register(container);\n UpdateModelFeature.register(container);\n DeleteModelFeature.register(container);\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,iBAAiB;AAC1B,SAASC,oBAAoB;AAC7B,SAASC,UAAU;AACnB,SAASC,aAAa;AACtB,SAASC,kBAAkB;AAC3B,SAASC,sBAAsB;AAC/B,SAASC,kBAAkB;AAC3B,SAASC,kBAAkB;AAC3B,SAASC,eAAe;AACxB,SAASC,iBAAiB;AAC1B,SAASC,0BAA0B;AACnC,SAASC,4BAA4B;AAErC,OAAO,MAAMC,mBAAmB,GAAGb,aAAa,CAAC;EAC7Cc,IAAI,EAAE,cAAc;EACpBC,QAAQA,CAACC,SAAS,EAAE;IAChBA,SAAS,CAACC,gBAAgB,CAACd,UAAU,EAAEF,iBAAiB,CAAC,CAAC,CAAC;IAC3De,SAAS,CAACD,QAAQ,CAACb,oBAAoB,CAAC,CAACgB,gBAAgB,CAAC,CAAC;IAC3DF,SAAS,CAACD,QAAQ,CAACX,aAAa,CAAC,CAACc,gBAAgB,CAAC,CAAC;IAEpDP,0BAA0B,CAACI,QAAQ,CAACC,SAAS,CAAC;IAE9CJ,4BAA4B,CAACG,QAAQ,CAACC,SAAS,CAAC;;IAEhD;IACAP,eAAe,CAACM,QAAQ,CAACC,SAAS,CAAC;IACnCN,iBAAiB,CAACK,QAAQ,CAACC,SAAS,CAAC;;IAErC;IACAX,kBAAkB,CAACU,QAAQ,CAACC,SAAS,CAAC;IACtCV,sBAAsB,CAACS,QAAQ,CAACC,SAAS,CAAC;IAC1CT,kBAAkB,CAACQ,QAAQ,CAACC,SAAS,CAAC;IACtCR,kBAAkB,CAACO,QAAQ,CAACC,SAAS,CAAC;EAC1C;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { CreateModelRepository as RepositoryAbstraction } from "./abstractions.js";
|
|
3
|
-
import { ModelCache } from "../../../features/contentModel/shared/abstractions.js";
|
|
4
|
-
import { PluginModelsProvider } from "../../../features/contentModel/shared/abstractions.js";
|
|
3
|
+
import { ModelCache, PluginModelsProvider } from "../../../features/contentModel/shared/abstractions.js";
|
|
5
4
|
import { ListModelsUseCase } from "../../../features/contentModel/ListModels/index.js";
|
|
6
|
-
import { StorageOperations } from "../../../features/shared/abstractions.js";
|
|
5
|
+
import { CmsContext, StorageOperations } from "../../../features/shared/abstractions.js";
|
|
7
6
|
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
8
|
-
import { CmsContext } from "../../../features/shared/abstractions.js";
|
|
9
7
|
import type { CmsModel } from "../../../types/index.js";
|
|
8
|
+
import { ModelFieldCompression } from "../../../features/contentModel/ModelFieldCompression/index.js";
|
|
10
9
|
/**
|
|
11
10
|
* CreateModelRepository - Validates domain rules and persists a new model.
|
|
12
11
|
*
|
|
@@ -22,13 +21,14 @@ import type { CmsModel } from "../../../types/index.js";
|
|
|
22
21
|
* - Clear ModelCache after successful create
|
|
23
22
|
*/
|
|
24
23
|
declare class CreateModelRepositoryImpl implements RepositoryAbstraction.Interface {
|
|
25
|
-
private modelCache;
|
|
26
|
-
private pluginModelsProvider;
|
|
27
|
-
private listModelsUseCase;
|
|
28
|
-
private storageOperations;
|
|
29
|
-
private tenantContext;
|
|
30
|
-
private cmsContext;
|
|
31
|
-
|
|
24
|
+
private readonly modelCache;
|
|
25
|
+
private readonly pluginModelsProvider;
|
|
26
|
+
private readonly listModelsUseCase;
|
|
27
|
+
private readonly storageOperations;
|
|
28
|
+
private readonly tenantContext;
|
|
29
|
+
private readonly cmsContext;
|
|
30
|
+
private readonly modelFieldCompression;
|
|
31
|
+
constructor(modelCache: ModelCache.Interface, pluginModelsProvider: PluginModelsProvider.Interface, listModelsUseCase: ListModelsUseCase.Interface, storageOperations: StorageOperations.Interface, tenantContext: TenantContext.Interface, cmsContext: CmsContext.Interface, modelFieldCompression: ModelFieldCompression.Interface);
|
|
32
32
|
execute(model: CmsModel): Promise<Result<void, RepositoryAbstraction.Error>>;
|
|
33
33
|
}
|
|
34
34
|
export declare const CreateModelRepository: typeof CreateModelRepositoryImpl & {
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
import camelCase from "lodash/camelCase.js";
|
|
2
2
|
import { Result } from "@webiny/feature/api";
|
|
3
3
|
import { CreateModelRepository as RepositoryAbstraction } from "./abstractions.js";
|
|
4
|
-
import { ModelCache } from "../shared/abstractions.js";
|
|
5
|
-
import { PluginModelsProvider } from "../shared/abstractions.js";
|
|
4
|
+
import { ModelCache, PluginModelsProvider } from "../shared/abstractions.js";
|
|
6
5
|
import { ListModelsUseCase } from "../ListModels/index.js";
|
|
7
|
-
import { ModelAlreadyExistsError } from "../../../domain/contentModel/errors.js";
|
|
8
|
-
import {
|
|
9
|
-
import { ModelValidationError } from "../../../domain/contentModel/errors.js";
|
|
10
|
-
import { StorageOperations } from "../../shared/abstractions.js";
|
|
6
|
+
import { ModelAlreadyExistsError, ModelPersistenceError, ModelValidationError } from "../../../domain/contentModel/errors.js";
|
|
7
|
+
import { CmsContext, StorageOperations } from "../../shared/abstractions.js";
|
|
11
8
|
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
12
|
-
import { CmsContext } from "../../shared/abstractions.js";
|
|
13
9
|
import { validateExistingModelId, validateModelIdAllowed } from "../../../crud/contentModel/validate/modelId.js";
|
|
14
10
|
import { validateEndingAllowed } from "../../../crud/contentModel/validate/endingAllowed.js";
|
|
15
11
|
import { ensureTypeTag } from "../../../domain/contentModel/ensureTypeTag.js";
|
|
16
12
|
import { validateSingularApiName } from "../../../domain/contentModel/validation/singularApiName.js";
|
|
17
13
|
import { validatePluralApiName } from "../../../domain/contentModel/validation/pluralApiName.js";
|
|
18
14
|
import { validateModelFields } from "../../../domain/contentModel/validation/modelFields.js";
|
|
15
|
+
import { ModelFieldCompression } from "../ModelFieldCompression/index.js";
|
|
19
16
|
|
|
20
17
|
/**
|
|
21
18
|
* Generate modelId from model following the exact logic from beforeCreate.ts
|
|
@@ -53,13 +50,14 @@ const getModelId = model => {
|
|
|
53
50
|
* - Clear ModelCache after successful create
|
|
54
51
|
*/
|
|
55
52
|
class CreateModelRepositoryImpl {
|
|
56
|
-
constructor(modelCache, pluginModelsProvider, listModelsUseCase, storageOperations, tenantContext, cmsContext) {
|
|
53
|
+
constructor(modelCache, pluginModelsProvider, listModelsUseCase, storageOperations, tenantContext, cmsContext, modelFieldCompression) {
|
|
57
54
|
this.modelCache = modelCache;
|
|
58
55
|
this.pluginModelsProvider = pluginModelsProvider;
|
|
59
56
|
this.listModelsUseCase = listModelsUseCase;
|
|
60
57
|
this.storageOperations = storageOperations;
|
|
61
58
|
this.tenantContext = tenantContext;
|
|
62
59
|
this.cmsContext = cmsContext;
|
|
60
|
+
this.modelFieldCompression = modelFieldCompression;
|
|
63
61
|
}
|
|
64
62
|
async execute(model) {
|
|
65
63
|
try {
|
|
@@ -146,10 +144,14 @@ class CreateModelRepositoryImpl {
|
|
|
146
144
|
|
|
147
145
|
// TODO: ideally, this will eventually be handled by the Model domain object
|
|
148
146
|
model.tags = ensureTypeTag(model);
|
|
147
|
+
const fields = await this.modelFieldCompression.compress(model.fields);
|
|
149
148
|
|
|
150
149
|
// Persist to storage
|
|
151
150
|
await this.storageOperations.models.create({
|
|
152
|
-
model
|
|
151
|
+
model: {
|
|
152
|
+
...model,
|
|
153
|
+
fields
|
|
154
|
+
}
|
|
153
155
|
});
|
|
154
156
|
|
|
155
157
|
// Clear cache
|
|
@@ -163,7 +165,7 @@ class CreateModelRepositoryImpl {
|
|
|
163
165
|
}
|
|
164
166
|
export const CreateModelRepository = RepositoryAbstraction.createImplementation({
|
|
165
167
|
implementation: CreateModelRepositoryImpl,
|
|
166
|
-
dependencies: [ModelCache, PluginModelsProvider, ListModelsUseCase, StorageOperations, TenantContext, CmsContext]
|
|
168
|
+
dependencies: [ModelCache, PluginModelsProvider, ListModelsUseCase, StorageOperations, TenantContext, CmsContext, ModelFieldCompression]
|
|
167
169
|
});
|
|
168
170
|
|
|
169
171
|
//# sourceMappingURL=CreateModelRepository.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["camelCase","Result","CreateModelRepository","RepositoryAbstraction","ModelCache","PluginModelsProvider","ListModelsUseCase","ModelAlreadyExistsError","ModelPersistenceError","ModelValidationError","StorageOperations","TenantContext","CmsContext","validateExistingModelId","validateModelIdAllowed","validateEndingAllowed","ensureTypeTag","validateSingularApiName","validatePluralApiName","validateModelFields","getModelId","model","modelId","name","value","trim","isModelIdValid","toLowerCase","CreateModelRepositoryImpl","constructor","modelCache","pluginModelsProvider","listModelsUseCase","storageOperations","tenantContext","cmsContext","execute","tenant","getTenant","error","fail","message","data","pluginModels","list","id","pluginModelConflict","find","pm","modelsResult","isFail","models","existingModel","context","tags","create","clear","ok","console","stack","createImplementation","implementation","dependencies"],"sources":["CreateModelRepository.ts"],"sourcesContent":["import camelCase from \"lodash/camelCase.js\";\nimport { Result } from \"@webiny/feature/api\";\nimport { CreateModelRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { ModelCache } from \"~/features/contentModel/shared/abstractions.js\";\nimport { PluginModelsProvider } from \"~/features/contentModel/shared/abstractions.js\";\nimport { ListModelsUseCase } from \"~/features/contentModel/ListModels/index.js\";\nimport { ModelAlreadyExistsError } from \"~/domain/contentModel/errors.js\";\nimport { ModelPersistenceError } from \"~/domain/contentModel/errors.js\";\nimport { ModelValidationError } from \"~/domain/contentModel/errors.js\";\nimport { StorageOperations } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { CmsContext } from \"~/features/shared/abstractions.js\";\nimport {\n validateExistingModelId,\n validateModelIdAllowed\n} from \"~/crud/contentModel/validate/modelId.js\";\nimport { validateEndingAllowed } from \"~/crud/contentModel/validate/endingAllowed.js\";\nimport type { CmsModel } from \"~/types/index.js\";\nimport { ensureTypeTag } from \"~/domain/contentModel/ensureTypeTag.js\";\nimport { validateSingularApiName } from \"~/domain/contentModel/validation/singularApiName.js\";\nimport { validatePluralApiName } from \"~/domain/contentModel/validation/pluralApiName.js\";\nimport { validateModelFields } from \"~/domain/contentModel/validation/modelFields.js\";\n\n/**\n * Generate modelId from model following the exact logic from beforeCreate.ts\n */\nconst getModelId = (model: { modelId?: string; name?: string }): string => {\n const { modelId, name } = model;\n const value = modelId ? modelId.trim() : null;\n if (value) {\n const isModelIdValid = camelCase(value).toLowerCase() === value.toLowerCase();\n if (isModelIdValid) {\n return value;\n }\n return camelCase(value);\n } else if (name) {\n return camelCase(name.trim());\n }\n throw new ModelValidationError(\n `There is no \"modelId\" or \"name\" passed into the create model method.`\n );\n};\n\n/**\n * CreateModelRepository - Validates domain rules and persists a new model.\n *\n * Responsibilities:\n * - Generate modelId from input\n * - Validate modelId is allowed (not in disallowed list)\n * - Validate API name endings\n * - Validate modelId uniqueness (database + plugins)\n * - Validate API name uniqueness (database + plugins)\n * - Validate plugin conflicts\n * - Validate model fields\n * - Persist to storage\n * - Clear ModelCache after successful create\n */\nclass CreateModelRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private modelCache: ModelCache.Interface,\n private pluginModelsProvider: PluginModelsProvider.Interface,\n private listModelsUseCase: ListModelsUseCase.Interface,\n private storageOperations: StorageOperations.Interface,\n private tenantContext: TenantContext.Interface,\n private cmsContext: CmsContext.Interface\n ) {}\n\n async execute(model: CmsModel): Promise<Result<void, RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n\n // TODO: this will eventually become part of the Model domain object.\n const modelId = getModelId(model);\n model.modelId = modelId;\n\n // Validate modelId is allowed (not in disallowed list)\n try {\n validateModelIdAllowed({ model });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({\n message: error.message,\n data: error.data\n })\n );\n }\n\n // Validate API name endings\n try {\n validateEndingAllowed({ model });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({\n message: error.message,\n data: error.data\n })\n );\n }\n\n // Check for plugin model conflicts\n const pluginModels = await this.pluginModelsProvider.list(tenant.id);\n const pluginModelConflict = pluginModels.find(pm => {\n return pm.modelId === model.modelId;\n });\n\n if (pluginModelConflict) {\n return Result.fail(\n new ModelAlreadyExistsError({\n modelId,\n message: `Model \"${modelId}\" is already registered via a plugin.`\n })\n );\n }\n\n // Get all models for further validation\n const modelsResult = await this.listModelsUseCase.execute();\n\n if (modelsResult.isFail()) {\n return Result.fail(new ModelPersistenceError(modelsResult.error));\n }\n\n const models = modelsResult.value;\n\n try {\n /**\n * We need to check for the existence of:\n * - modelId\n * - singularApiName\n * - pluralApiName\n */\n for (const existingModel of models) {\n validateExistingModelId({\n existingModel,\n model\n });\n validateSingularApiName({\n existingModel,\n model\n });\n validatePluralApiName({\n existingModel,\n model\n });\n }\n\n await validateModelFields({\n models,\n model,\n context: this.cmsContext\n });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({ message: error.message, data: error.data })\n );\n }\n\n // TODO: ideally, this will eventually be handled by the Model domain object\n model.tags = ensureTypeTag(model);\n\n // Persist to storage\n await this.storageOperations.models.create({ model });\n\n // Clear cache\n this.modelCache.clear();\n\n return Result.ok();\n } catch (error) {\n console.error(error, error.stack);\n return Result.fail(new ModelPersistenceError(error as Error));\n }\n }\n}\n\nexport const CreateModelRepository = RepositoryAbstraction.createImplementation({\n implementation: CreateModelRepositoryImpl,\n dependencies: [\n ModelCache,\n PluginModelsProvider,\n ListModelsUseCase,\n StorageOperations,\n TenantContext,\n CmsContext\n ]\n});\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,qBAAqB;AAC3C,SAASC,MAAM,QAAQ,qBAAqB;AAC5C,SAASC,qBAAqB,IAAIC,qBAAqB;AACvD,SAASC,UAAU;AACnB,SAASC,oBAAoB;AAC7B,SAASC,iBAAiB;AAC1B,SAASC,uBAAuB;AAChC,SAASC,qBAAqB;AAC9B,SAASC,oBAAoB;AAC7B,SAASC,iBAAiB;AAC1B,SAASC,aAAa,QAAQ,0DAA0D;AACxF,SAASC,UAAU;AACnB,SACIC,uBAAuB,EACvBC,sBAAsB;AAE1B,SAASC,qBAAqB;AAE9B,SAASC,aAAa;AACtB,SAASC,uBAAuB;AAChC,SAASC,qBAAqB;AAC9B,SAASC,mBAAmB;;AAE5B;AACA;AACA;AACA,MAAMC,UAAU,GAAIC,KAA0C,IAAa;EACvE,MAAM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
+
{"version":3,"names":["camelCase","Result","CreateModelRepository","RepositoryAbstraction","ModelCache","PluginModelsProvider","ListModelsUseCase","ModelAlreadyExistsError","ModelPersistenceError","ModelValidationError","CmsContext","StorageOperations","TenantContext","validateExistingModelId","validateModelIdAllowed","validateEndingAllowed","ensureTypeTag","validateSingularApiName","validatePluralApiName","validateModelFields","ModelFieldCompression","getModelId","model","modelId","name","value","trim","isModelIdValid","toLowerCase","CreateModelRepositoryImpl","constructor","modelCache","pluginModelsProvider","listModelsUseCase","storageOperations","tenantContext","cmsContext","modelFieldCompression","execute","tenant","getTenant","error","fail","message","data","pluginModels","list","id","pluginModelConflict","find","pm","modelsResult","isFail","models","existingModel","context","tags","fields","compress","create","clear","ok","console","stack","createImplementation","implementation","dependencies"],"sources":["CreateModelRepository.ts"],"sourcesContent":["import camelCase from \"lodash/camelCase.js\";\nimport { Result } from \"@webiny/feature/api\";\nimport { CreateModelRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { ModelCache, PluginModelsProvider } from \"~/features/contentModel/shared/abstractions.js\";\nimport { ListModelsUseCase } from \"~/features/contentModel/ListModels/index.js\";\nimport {\n ModelAlreadyExistsError,\n ModelPersistenceError,\n ModelValidationError\n} from \"~/domain/contentModel/errors.js\";\nimport { CmsContext, StorageOperations } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport {\n validateExistingModelId,\n validateModelIdAllowed\n} from \"~/crud/contentModel/validate/modelId.js\";\nimport { validateEndingAllowed } from \"~/crud/contentModel/validate/endingAllowed.js\";\nimport type { CmsModel } from \"~/types/index.js\";\nimport { ensureTypeTag } from \"~/domain/contentModel/ensureTypeTag.js\";\nimport { validateSingularApiName } from \"~/domain/contentModel/validation/singularApiName.js\";\nimport { validatePluralApiName } from \"~/domain/contentModel/validation/pluralApiName.js\";\nimport { validateModelFields } from \"~/domain/contentModel/validation/modelFields.js\";\nimport { ModelFieldCompression } from \"~/features/contentModel/ModelFieldCompression/index.js\";\n\n/**\n * Generate modelId from model following the exact logic from beforeCreate.ts\n */\nconst getModelId = (model: { modelId?: string; name?: string }): string => {\n const { modelId, name } = model;\n const value = modelId ? modelId.trim() : null;\n if (value) {\n const isModelIdValid = camelCase(value).toLowerCase() === value.toLowerCase();\n if (isModelIdValid) {\n return value;\n }\n return camelCase(value);\n } else if (name) {\n return camelCase(name.trim());\n }\n throw new ModelValidationError(\n `There is no \"modelId\" or \"name\" passed into the create model method.`\n );\n};\n\n/**\n * CreateModelRepository - Validates domain rules and persists a new model.\n *\n * Responsibilities:\n * - Generate modelId from input\n * - Validate modelId is allowed (not in disallowed list)\n * - Validate API name endings\n * - Validate modelId uniqueness (database + plugins)\n * - Validate API name uniqueness (database + plugins)\n * - Validate plugin conflicts\n * - Validate model fields\n * - Persist to storage\n * - Clear ModelCache after successful create\n */\nclass CreateModelRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private readonly modelCache: ModelCache.Interface,\n private readonly pluginModelsProvider: PluginModelsProvider.Interface,\n private readonly listModelsUseCase: ListModelsUseCase.Interface,\n private readonly storageOperations: StorageOperations.Interface,\n private readonly tenantContext: TenantContext.Interface,\n private readonly cmsContext: CmsContext.Interface,\n private readonly modelFieldCompression: ModelFieldCompression.Interface\n ) {}\n\n async execute(model: CmsModel): Promise<Result<void, RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n\n // TODO: this will eventually become part of the Model domain object.\n const modelId = getModelId(model);\n model.modelId = modelId;\n\n // Validate modelId is allowed (not in disallowed list)\n try {\n validateModelIdAllowed({ model });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({\n message: error.message,\n data: error.data\n })\n );\n }\n\n // Validate API name endings\n try {\n validateEndingAllowed({ model });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({\n message: error.message,\n data: error.data\n })\n );\n }\n\n // Check for plugin model conflicts\n const pluginModels = await this.pluginModelsProvider.list(tenant.id);\n const pluginModelConflict = pluginModels.find(pm => {\n return pm.modelId === model.modelId;\n });\n\n if (pluginModelConflict) {\n return Result.fail(\n new ModelAlreadyExistsError({\n modelId,\n message: `Model \"${modelId}\" is already registered via a plugin.`\n })\n );\n }\n\n // Get all models for further validation\n const modelsResult = await this.listModelsUseCase.execute();\n\n if (modelsResult.isFail()) {\n return Result.fail(new ModelPersistenceError(modelsResult.error));\n }\n\n const models = modelsResult.value;\n\n try {\n /**\n * We need to check for the existence of:\n * - modelId\n * - singularApiName\n * - pluralApiName\n */\n for (const existingModel of models) {\n validateExistingModelId({\n existingModel,\n model\n });\n validateSingularApiName({\n existingModel,\n model\n });\n validatePluralApiName({\n existingModel,\n model\n });\n }\n\n await validateModelFields({\n models,\n model,\n context: this.cmsContext\n });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({ message: error.message, data: error.data })\n );\n }\n\n // TODO: ideally, this will eventually be handled by the Model domain object\n model.tags = ensureTypeTag(model);\n\n const fields = await this.modelFieldCompression.compress(model.fields);\n\n // Persist to storage\n await this.storageOperations.models.create({\n model: {\n ...model,\n fields\n }\n });\n\n // Clear cache\n this.modelCache.clear();\n\n return Result.ok();\n } catch (error) {\n console.error(error, error.stack);\n return Result.fail(new ModelPersistenceError(error as Error));\n }\n }\n}\n\nexport const CreateModelRepository = RepositoryAbstraction.createImplementation({\n implementation: CreateModelRepositoryImpl,\n dependencies: [\n ModelCache,\n PluginModelsProvider,\n ListModelsUseCase,\n StorageOperations,\n TenantContext,\n CmsContext,\n ModelFieldCompression\n ]\n});\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,qBAAqB;AAC3C,SAASC,MAAM,QAAQ,qBAAqB;AAC5C,SAASC,qBAAqB,IAAIC,qBAAqB;AACvD,SAASC,UAAU,EAAEC,oBAAoB;AACzC,SAASC,iBAAiB;AAC1B,SACIC,uBAAuB,EACvBC,qBAAqB,EACrBC,oBAAoB;AAExB,SAASC,UAAU,EAAEC,iBAAiB;AACtC,SAASC,aAAa,QAAQ,0DAA0D;AACx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AC,OAAOpB,KAAK,EAAE;MACZqB,OAAO,CAACrB,KAAK,CAACA,KAAK,EAAEA,KAAK,CAACsB,KAAK,CAAC;MACjC,OAAO9D,MAAM,CAACyC,IAAI,CAAC,IAAIlC,qBAAqB,CAACiC,KAAc,CAAC,CAAC;IACjE;EACJ;AACJ;AAEA,OAAO,MAAMvC,qBAAqB,GAAGC,qBAAqB,CAAC6D,oBAAoB,CAAC;EAC5EC,cAAc,EAAEpC,yBAAyB;EACzCqC,YAAY,EAAE,CACV9D,UAAU,EACVC,oBAAoB,EACpBC,iBAAiB,EACjBK,iBAAiB,EACjBC,aAAa,EACbF,UAAU,EACVU,qBAAqB;AAE7B,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { CreateModelFromRepository as RepositoryAbstraction } from "./abstractions.js";
|
|
3
|
-
import { ModelCache } from "../../../features/contentModel/shared/abstractions.js";
|
|
4
|
-
import {
|
|
5
|
-
import { ModelsFetcher } from "../../../features/contentModel/shared/abstractions.js";
|
|
6
|
-
import { StorageOperations } from "../../../features/shared/abstractions.js";
|
|
3
|
+
import { ModelCache, ModelsFetcher, PluginModelsProvider } from "../../../features/contentModel/shared/abstractions.js";
|
|
4
|
+
import { CmsContext, StorageOperations } from "../../../features/shared/abstractions.js";
|
|
7
5
|
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
8
|
-
import { CmsContext } from "../../../features/shared/abstractions.js";
|
|
9
6
|
import type { CmsModel } from "../../../types/index.js";
|
|
7
|
+
import { ModelFieldCompression } from "../../../features/contentModel/ModelFieldCompression/index.js";
|
|
10
8
|
/**
|
|
11
9
|
* CreateModelFromRepository - Validates domain rules and persists cloned model.
|
|
12
10
|
*
|
|
@@ -22,13 +20,14 @@ import type { CmsModel } from "../../../types/index.js";
|
|
|
22
20
|
* - Clear ModelCache after successful create
|
|
23
21
|
*/
|
|
24
22
|
declare class CreateModelFromRepositoryImpl implements RepositoryAbstraction.Interface {
|
|
25
|
-
private modelCache;
|
|
26
|
-
private pluginModelsProvider;
|
|
27
|
-
private modelsFetcher;
|
|
28
|
-
private storageOperations;
|
|
29
|
-
private tenantContext;
|
|
30
|
-
private cmsContext;
|
|
31
|
-
|
|
23
|
+
private readonly modelCache;
|
|
24
|
+
private readonly pluginModelsProvider;
|
|
25
|
+
private readonly modelsFetcher;
|
|
26
|
+
private readonly storageOperations;
|
|
27
|
+
private readonly tenantContext;
|
|
28
|
+
private readonly cmsContext;
|
|
29
|
+
private readonly modelFieldCompression;
|
|
30
|
+
constructor(modelCache: ModelCache.Interface, pluginModelsProvider: PluginModelsProvider.Interface, modelsFetcher: ModelsFetcher.Interface, storageOperations: StorageOperations.Interface, tenantContext: TenantContext.Interface, cmsContext: CmsContext.Interface, modelFieldCompression: ModelFieldCompression.Interface);
|
|
32
31
|
execute(model: CmsModel): Promise<Result<void, RepositoryAbstraction.Error>>;
|
|
33
32
|
}
|
|
34
33
|
export declare const CreateModelFromRepository: typeof CreateModelFromRepositoryImpl & {
|
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
import camelCase from "lodash/camelCase.js";
|
|
2
2
|
import { Result } from "@webiny/feature/api";
|
|
3
3
|
import { CreateModelFromRepository as RepositoryAbstraction } from "./abstractions.js";
|
|
4
|
-
import { ModelCache } from "../shared/abstractions.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { ModelAlreadyExistsError } from "../../../domain/contentModel/errors.js";
|
|
8
|
-
import { ModelPersistenceError } from "../../../domain/contentModel/errors.js";
|
|
9
|
-
import { ModelValidationError } from "../../../domain/contentModel/errors.js";
|
|
10
|
-
import { StorageOperations } from "../../shared/abstractions.js";
|
|
4
|
+
import { ModelCache, ModelsFetcher, PluginModelsProvider } from "../shared/abstractions.js";
|
|
5
|
+
import { ModelAlreadyExistsError, ModelPersistenceError, ModelValidationError } from "../../../domain/contentModel/errors.js";
|
|
6
|
+
import { CmsContext, StorageOperations } from "../../shared/abstractions.js";
|
|
11
7
|
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
12
|
-
import { CmsContext } from "../../shared/abstractions.js";
|
|
13
8
|
import { validateExistingModelId, validateModelIdAllowed } from "../../../crud/contentModel/validate/modelId.js";
|
|
14
9
|
import { validateEndingAllowed } from "../../../crud/contentModel/validate/endingAllowed.js";
|
|
15
10
|
import { validateSingularApiName } from "../../../domain/contentModel/validation/singularApiName.js";
|
|
16
11
|
import { validatePluralApiName } from "../../../domain/contentModel/validation/pluralApiName.js";
|
|
17
12
|
import { validateModelFields } from "../../../domain/contentModel/validation/modelFields.js";
|
|
18
13
|
import { ensureTypeTag } from "../../../domain/contentModel/ensureTypeTag.js";
|
|
14
|
+
import { ModelFieldCompression } from "../ModelFieldCompression/index.js";
|
|
19
15
|
|
|
20
16
|
/**
|
|
21
17
|
* Generate modelId from model following the exact logic from beforeCreate.ts
|
|
@@ -53,13 +49,14 @@ const getModelId = model => {
|
|
|
53
49
|
* - Clear ModelCache after successful create
|
|
54
50
|
*/
|
|
55
51
|
class CreateModelFromRepositoryImpl {
|
|
56
|
-
constructor(modelCache, pluginModelsProvider, modelsFetcher, storageOperations, tenantContext, cmsContext) {
|
|
52
|
+
constructor(modelCache, pluginModelsProvider, modelsFetcher, storageOperations, tenantContext, cmsContext, modelFieldCompression) {
|
|
57
53
|
this.modelCache = modelCache;
|
|
58
54
|
this.pluginModelsProvider = pluginModelsProvider;
|
|
59
55
|
this.modelsFetcher = modelsFetcher;
|
|
60
56
|
this.storageOperations = storageOperations;
|
|
61
57
|
this.tenantContext = tenantContext;
|
|
62
58
|
this.cmsContext = cmsContext;
|
|
59
|
+
this.modelFieldCompression = modelFieldCompression;
|
|
63
60
|
}
|
|
64
61
|
async execute(model) {
|
|
65
62
|
try {
|
|
@@ -149,10 +146,14 @@ class CreateModelFromRepositoryImpl {
|
|
|
149
146
|
|
|
150
147
|
// Ensure type tags
|
|
151
148
|
model.tags = ensureTypeTag(model);
|
|
149
|
+
const fields = await this.modelFieldCompression.compress(model.fields);
|
|
152
150
|
|
|
153
151
|
// Persist to storage
|
|
154
152
|
await this.storageOperations.models.create({
|
|
155
|
-
model
|
|
153
|
+
model: {
|
|
154
|
+
...model,
|
|
155
|
+
fields
|
|
156
|
+
}
|
|
156
157
|
});
|
|
157
158
|
|
|
158
159
|
// Clear cache
|
|
@@ -165,7 +166,7 @@ class CreateModelFromRepositoryImpl {
|
|
|
165
166
|
}
|
|
166
167
|
export const CreateModelFromRepository = RepositoryAbstraction.createImplementation({
|
|
167
168
|
implementation: CreateModelFromRepositoryImpl,
|
|
168
|
-
dependencies: [ModelCache, PluginModelsProvider, ModelsFetcher, StorageOperations, TenantContext, CmsContext]
|
|
169
|
+
dependencies: [ModelCache, PluginModelsProvider, ModelsFetcher, StorageOperations, TenantContext, CmsContext, ModelFieldCompression]
|
|
169
170
|
});
|
|
170
171
|
|
|
171
172
|
//# sourceMappingURL=CreateModelFromRepository.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["camelCase","Result","CreateModelFromRepository","RepositoryAbstraction","ModelCache","PluginModelsProvider","ModelsFetcher","ModelAlreadyExistsError","ModelPersistenceError","ModelValidationError","StorageOperations","TenantContext","CmsContext","validateExistingModelId","validateModelIdAllowed","validateEndingAllowed","validateSingularApiName","validatePluralApiName","validateModelFields","ensureTypeTag","getModelId","model","modelId","name","value","trim","isModelIdValid","toLowerCase","CreateModelFromRepositoryImpl","constructor","modelCache","pluginModelsProvider","modelsFetcher","storageOperations","tenantContext","cmsContext","execute","tenant","getTenant","error","fail","message","data","modelsResult","fetchAll","isFail","existingModel","find","m","pluginModels","list","id","pluginModelConflict","pm","singularApiName","pluralApiName","models","context","tags","create","clear","ok","createImplementation","implementation","dependencies"],"sources":["CreateModelFromRepository.ts"],"sourcesContent":["import camelCase from \"lodash/camelCase.js\";\nimport { Result } from \"@webiny/feature/api\";\nimport { CreateModelFromRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { ModelCache } from \"~/features/contentModel/shared/abstractions.js\";\nimport { PluginModelsProvider } from \"~/features/contentModel/shared/abstractions.js\";\nimport { ModelsFetcher } from \"~/features/contentModel/shared/abstractions.js\";\nimport { ModelAlreadyExistsError } from \"~/domain/contentModel/errors.js\";\nimport { ModelPersistenceError } from \"~/domain/contentModel/errors.js\";\nimport { ModelValidationError } from \"~/domain/contentModel/errors.js\";\nimport { StorageOperations } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { CmsContext } from \"~/features/shared/abstractions.js\";\nimport {\n validateExistingModelId,\n validateModelIdAllowed\n} from \"~/crud/contentModel/validate/modelId.js\";\nimport { validateEndingAllowed } from \"~/crud/contentModel/validate/endingAllowed.js\";\nimport { validateSingularApiName } from \"~/domain/contentModel/validation/singularApiName.js\";\nimport { validatePluralApiName } from \"~/domain/contentModel/validation/pluralApiName.js\";\nimport { validateModelFields } from \"~/domain/contentModel/validation/modelFields.js\";\nimport type { CmsModel } from \"~/types/index.js\";\nimport { ensureTypeTag } from \"~/domain/contentModel/ensureTypeTag.js\";\n\n/**\n * Generate modelId from model following the exact logic from beforeCreate.ts\n */\nconst getModelId = (model: { modelId?: string; name?: string }): string => {\n const { modelId, name } = model;\n const value = modelId ? modelId.trim() : null;\n if (value) {\n const isModelIdValid = camelCase(value).toLowerCase() === value.toLowerCase();\n if (isModelIdValid) {\n return value;\n }\n return camelCase(value);\n } else if (name) {\n return camelCase(name.trim());\n }\n throw new ModelValidationError(\n `There is no \"modelId\" or \"name\" passed into the create model from method.`\n );\n};\n\n/**\n * CreateModelFromRepository - Validates domain rules and persists cloned model.\n *\n * Responsibilities:\n * - Generate modelId from input\n * - Validate modelId is allowed (not in disallowed list)\n * - Validate API name endings\n * - Validate modelId uniqueness (database + plugins)\n * - Validate API name uniqueness (database + plugins)\n * - Validate plugin conflicts\n * - Validate model fields\n * - Persist to storage\n * - Clear ModelCache after successful create\n */\nclass CreateModelFromRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private modelCache: ModelCache.Interface,\n private pluginModelsProvider: PluginModelsProvider.Interface,\n private modelsFetcher: ModelsFetcher.Interface,\n private storageOperations: StorageOperations.Interface,\n private tenantContext: TenantContext.Interface,\n private cmsContext: CmsContext.Interface\n ) {}\n\n async execute(model: CmsModel): Promise<Result<void, RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n\n // Generate modelId using the exact logic from beforeCreate.ts\n const modelId = getModelId(model);\n model.modelId = modelId;\n\n // Validate modelId is allowed (not in disallowed list)\n try {\n validateModelIdAllowed({ model });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({ message: error.message, data: error.data })\n );\n }\n\n // Validate API name endings\n try {\n validateEndingAllowed({ model });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({ message: error.message, data: error.data })\n );\n }\n\n // Validate modelId uniqueness (database)\n const modelsResult = await this.modelsFetcher.fetchAll();\n if (modelsResult.isFail()) {\n return Result.fail(new ModelPersistenceError(modelsResult.error));\n }\n\n const existingModel = modelsResult.value.find(m => m.modelId === modelId);\n if (existingModel) {\n return Result.fail(new ModelAlreadyExistsError({ modelId }));\n }\n\n // Check for plugin model conflicts\n const pluginModels = await this.pluginModelsProvider.list(tenant.id);\n const pluginModelConflict = pluginModels.find(pm => {\n return (\n pm.modelId === model.modelId ||\n pm.singularApiName === model.singularApiName ||\n pm.pluralApiName === model.pluralApiName\n );\n });\n\n if (pluginModelConflict) {\n return Result.fail(\n new ModelAlreadyExistsError({\n modelId,\n message: `Model \"${modelId}\" is already registered via a plugin.`\n })\n );\n }\n\n const models = modelsResult.value;\n\n try {\n // Validate uniqueness\n for (const existingModel of models) {\n validateExistingModelId({\n existingModel,\n model\n });\n validateSingularApiName({\n existingModel,\n model\n });\n validatePluralApiName({\n existingModel,\n model\n });\n }\n\n // Validate model fields\n await validateModelFields({\n models,\n model,\n context: this.cmsContext\n });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({ message: error.message, data: error.data })\n );\n }\n\n // Ensure type tags\n model.tags = ensureTypeTag(model);\n\n // Persist to storage\n await this.storageOperations.models.create({ model });\n\n // Clear cache\n this.modelCache.clear();\n\n return Result.ok();\n } catch (error) {\n return Result.fail(new ModelPersistenceError(error as Error));\n }\n }\n}\n\nexport const CreateModelFromRepository = RepositoryAbstraction.createImplementation({\n implementation: CreateModelFromRepositoryImpl,\n dependencies: [\n ModelCache,\n PluginModelsProvider,\n ModelsFetcher,\n StorageOperations,\n TenantContext,\n CmsContext\n ]\n});\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,qBAAqB;AAC3C,SAASC,MAAM,QAAQ,qBAAqB;AAC5C,SAASC,yBAAyB,IAAIC,qBAAqB;AAC3D,SAASC,UAAU;AACnB,SAASC,oBAAoB;AAC7B,SAASC,aAAa;AACtB,SAASC,uBAAuB;AAChC,SAASC,qBAAqB;AAC9B,SAASC,oBAAoB;AAC7B,SAASC,iBAAiB;AAC1B,SAASC,aAAa,QAAQ,0DAA0D;AACxF,SAASC,UAAU;AACnB,SACIC,uBAAuB,EACvBC,sBAAsB;AAE1B,SAASC,qBAAqB;AAC9B,SAASC,uBAAuB;AAChC,SAASC,qBAAqB;AAC9B,SAASC,mBAAmB;AAE5B,SAASC,aAAa;;AAEtB;AACA;AACA;AACA,MAAMC,UAAU,GAAIC,KAA0C,IAAa;EACvE,MAAM;IAAEC,OAAO;IAAEC;EAAK,CAAC,GAAGF,KAAK;EAC/B,MAAMG,KAAK,GAAGF,OAAO,GAAGA,OAAO,CAACG,IAAI,CAAC,CAAC,GAAG,IAAI;EAC7C,IAAID,KAAK,EAAE;IACP,MAAME,cAAc,GAAG1B,SAAS,CAACwB,KAAK,CAAC,CAACG,WAAW,CAAC,CAAC,KAAKH,KAAK,CAACG,WAAW,CAAC,CAAC;IAC7E,IAAID,cAAc,EAAE;MAChB,OAAOF,KAAK;IAChB;IACA,OAAO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AIU,MAAM,EAAE;UAChC3C,uBAAuB,CAAC;YACpBiC,aAAa;YACbzB;UACJ,CAAC,CAAC;UACFL,uBAAuB,CAAC;YACpB8B,aAAa;YACbzB;UACJ,CAAC,CAAC;UACFJ,qBAAqB,CAAC;YAClB6B,aAAa;YACbzB;UACJ,CAAC,CAAC;QACN;;QAEA;QACA,MAAMH,mBAAmB,CAAC;UACtBsC,MAAM;UACNnC,KAAK;UACLoC,OAAO,EAAE,IAAI,CAACtB;QAClB,CAAC,CAAC;MACN,CAAC,CAAC,OAAOI,KAAK,EAAE;QACZ,OAAOtC,MAAM,CAACuC,IAAI,CACd,IAAI/B,oBAAoB,CAAC;UAAEgC,OAAO,EAAEF,KAAK,CAACE,OAAO;UAAEC,IAAI,EAAEH,KAAK,CAACG;QAAK,CAAC,CACzE,CAAC;MACL;;MAEA;MACArB,KAAK,CAACqC,IAAI,GAAGvC,aAAa,CAACE,KAAK,CAAC;;MAEjC;MACA,MAAM,IAAI,CAACY,iBAAiB,CAACuB,MAAM,CAACG,MAAM,CAAC;QAAEtC;MAAM,CAAC,CAAC;;MAErD;MACA,IAAI,CAACS,UAAU,CAAC8B,KAAK,CAAC,CAAC;MAEvB,OAAO3D,MAAM,CAAC4D,EAAE,CAAC,CAAC;IACtB,CAAC,CAAC,OAAOtB,KAAK,EAAE;MACZ,OAAOtC,MAAM,CAACuC,IAAI,CAAC,IAAIhC,qBAAqB,CAAC+B,KAAc,CAAC,CAAC;IACjE;EACJ;AACJ;AAEA,OAAO,MAAMrC,yBAAyB,GAAGC,qBAAqB,CAAC2D,oBAAoB,CAAC;EAChFC,cAAc,EAAEnC,6BAA6B;EAC7CoC,YAAY,EAAE,CACV5D,UAAU,EACVC,oBAAoB,EACpBC,aAAa,EACbI,iBAAiB,EACjBC,aAAa,EACbC,UAAU;AAElB,CAAC,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["camelCase","Result","CreateModelFromRepository","RepositoryAbstraction","ModelCache","ModelsFetcher","PluginModelsProvider","ModelAlreadyExistsError","ModelPersistenceError","ModelValidationError","CmsContext","StorageOperations","TenantContext","validateExistingModelId","validateModelIdAllowed","validateEndingAllowed","validateSingularApiName","validatePluralApiName","validateModelFields","ensureTypeTag","ModelFieldCompression","getModelId","model","modelId","name","value","trim","isModelIdValid","toLowerCase","CreateModelFromRepositoryImpl","constructor","modelCache","pluginModelsProvider","modelsFetcher","storageOperations","tenantContext","cmsContext","modelFieldCompression","execute","tenant","getTenant","error","fail","message","data","modelsResult","fetchAll","isFail","existingModel","find","m","pluginModels","list","id","pluginModelConflict","pm","singularApiName","pluralApiName","models","context","tags","fields","compress","create","clear","ok","createImplementation","implementation","dependencies"],"sources":["CreateModelFromRepository.ts"],"sourcesContent":["import camelCase from \"lodash/camelCase.js\";\nimport { Result } from \"@webiny/feature/api\";\nimport { CreateModelFromRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport {\n ModelCache,\n ModelsFetcher,\n PluginModelsProvider\n} from \"~/features/contentModel/shared/abstractions.js\";\nimport {\n ModelAlreadyExistsError,\n ModelPersistenceError,\n ModelValidationError\n} from \"~/domain/contentModel/errors.js\";\nimport { CmsContext, StorageOperations } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport {\n validateExistingModelId,\n validateModelIdAllowed\n} from \"~/crud/contentModel/validate/modelId.js\";\nimport { validateEndingAllowed } from \"~/crud/contentModel/validate/endingAllowed.js\";\nimport { validateSingularApiName } from \"~/domain/contentModel/validation/singularApiName.js\";\nimport { validatePluralApiName } from \"~/domain/contentModel/validation/pluralApiName.js\";\nimport { validateModelFields } from \"~/domain/contentModel/validation/modelFields.js\";\nimport type { CmsModel } from \"~/types/index.js\";\nimport { ensureTypeTag } from \"~/domain/contentModel/ensureTypeTag.js\";\nimport { ModelFieldCompression } from \"~/features/contentModel/ModelFieldCompression/index.js\";\n\n/**\n * Generate modelId from model following the exact logic from beforeCreate.ts\n */\nconst getModelId = (model: { modelId?: string; name?: string }): string => {\n const { modelId, name } = model;\n const value = modelId ? modelId.trim() : null;\n if (value) {\n const isModelIdValid = camelCase(value).toLowerCase() === value.toLowerCase();\n if (isModelIdValid) {\n return value;\n }\n return camelCase(value);\n } else if (name) {\n return camelCase(name.trim());\n }\n throw new ModelValidationError(\n `There is no \"modelId\" or \"name\" passed into the create model from method.`\n );\n};\n\n/**\n * CreateModelFromRepository - Validates domain rules and persists cloned model.\n *\n * Responsibilities:\n * - Generate modelId from input\n * - Validate modelId is allowed (not in disallowed list)\n * - Validate API name endings\n * - Validate modelId uniqueness (database + plugins)\n * - Validate API name uniqueness (database + plugins)\n * - Validate plugin conflicts\n * - Validate model fields\n * - Persist to storage\n * - Clear ModelCache after successful create\n */\nclass CreateModelFromRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private readonly modelCache: ModelCache.Interface,\n private readonly pluginModelsProvider: PluginModelsProvider.Interface,\n private readonly modelsFetcher: ModelsFetcher.Interface,\n private readonly storageOperations: StorageOperations.Interface,\n private readonly tenantContext: TenantContext.Interface,\n private readonly cmsContext: CmsContext.Interface,\n private readonly modelFieldCompression: ModelFieldCompression.Interface\n ) {}\n\n async execute(model: CmsModel): Promise<Result<void, RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant();\n\n // Generate modelId using the exact logic from beforeCreate.ts\n const modelId = getModelId(model);\n model.modelId = modelId;\n\n // Validate modelId is allowed (not in disallowed list)\n try {\n validateModelIdAllowed({ model });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({ message: error.message, data: error.data })\n );\n }\n\n // Validate API name endings\n try {\n validateEndingAllowed({ model });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({ message: error.message, data: error.data })\n );\n }\n\n // Validate modelId uniqueness (database)\n const modelsResult = await this.modelsFetcher.fetchAll();\n if (modelsResult.isFail()) {\n return Result.fail(new ModelPersistenceError(modelsResult.error));\n }\n\n const existingModel = modelsResult.value.find(m => m.modelId === modelId);\n if (existingModel) {\n return Result.fail(new ModelAlreadyExistsError({ modelId }));\n }\n\n // Check for plugin model conflicts\n const pluginModels = await this.pluginModelsProvider.list(tenant.id);\n const pluginModelConflict = pluginModels.find(pm => {\n return (\n pm.modelId === model.modelId ||\n pm.singularApiName === model.singularApiName ||\n pm.pluralApiName === model.pluralApiName\n );\n });\n\n if (pluginModelConflict) {\n return Result.fail(\n new ModelAlreadyExistsError({\n modelId,\n message: `Model \"${modelId}\" is already registered via a plugin.`\n })\n );\n }\n\n const models = modelsResult.value;\n\n try {\n // Validate uniqueness\n for (const existingModel of models) {\n validateExistingModelId({\n existingModel,\n model\n });\n validateSingularApiName({\n existingModel,\n model\n });\n validatePluralApiName({\n existingModel,\n model\n });\n }\n\n // Validate model fields\n await validateModelFields({\n models,\n model,\n context: this.cmsContext\n });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({ message: error.message, data: error.data })\n );\n }\n\n // Ensure type tags\n model.tags = ensureTypeTag(model);\n\n const fields = await this.modelFieldCompression.compress(model.fields);\n\n // Persist to storage\n await this.storageOperations.models.create({\n model: {\n ...model,\n fields\n }\n });\n\n // Clear cache\n this.modelCache.clear();\n\n return Result.ok();\n } catch (error) {\n return Result.fail(new ModelPersistenceError(error as Error));\n }\n }\n}\n\nexport const CreateModelFromRepository = RepositoryAbstraction.createImplementation({\n implementation: CreateModelFromRepositoryImpl,\n dependencies: [\n ModelCache,\n PluginModelsProvider,\n ModelsFetcher,\n StorageOperations,\n TenantContext,\n CmsContext,\n ModelFieldCompression\n ]\n});\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,qBAAqB;AAC3C,SAASC,MAAM,QAAQ,qBAAqB;AAC5C,SAASC,yBAAyB,IAAIC,qBAAqB;AAC3D,SACIC,UAAU,EACVC,aAAa,EACbC,oBAAoB;AAExB,SACIC,uBAAuB,EACvBC,qBAAqB,EACrBC,oBAAoB;AAExB,SAASC,UAAU,EAAEC,iBAAiB;AACtC,SAASC,aAAa,QAAQ,0DA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AM,IAAI,CAACxB,qBAAqB,CAACyB,QAAQ,CAACxC,KAAK,CAACuC,MAAM,CAAC;;MAEtE;MACA,MAAM,IAAI,CAAC3B,iBAAiB,CAACwB,MAAM,CAACK,MAAM,CAAC;QACvCzC,KAAK,EAAE;UACH,GAAGA,KAAK;UACRuC;QACJ;MACJ,CAAC,CAAC;;MAEF;MACA,IAAI,CAAC9B,UAAU,CAACiC,KAAK,CAAC,CAAC;MAEvB,OAAO/D,MAAM,CAACgE,EAAE,CAAC,CAAC;IACtB,CAAC,CAAC,OAAOxB,KAAK,EAAE;MACZ,OAAOxC,MAAM,CAACyC,IAAI,CAAC,IAAIlC,qBAAqB,CAACiC,KAAc,CAAC,CAAC;IACjE;EACJ;AACJ;AAEA,OAAO,MAAMvC,yBAAyB,GAAGC,qBAAqB,CAAC+D,oBAAoB,CAAC;EAChFC,cAAc,EAAEtC,6BAA6B;EAC7CuC,YAAY,EAAE,CACVhE,UAAU,EACVE,oBAAoB,EACpBD,aAAa,EACbM,iBAAiB,EACjBC,aAAa,EACbF,UAAU,EACVU,qBAAqB;AAE7B,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CompressionHandler } from "@webiny/utils/exports/api.js";
|
|
2
|
+
import { ModelFieldCompression as ModelFieldCompressionAbstraction } from "./abstractions.js";
|
|
3
|
+
import type { CmsModelField } from "../../../types/index.js";
|
|
4
|
+
import { BuildParams } from "@webiny/api-core/features/buildParams/index.js";
|
|
5
|
+
declare class ModelFieldCompressionImpl implements ModelFieldCompressionAbstraction.Interface {
|
|
6
|
+
private readonly compressionHandler;
|
|
7
|
+
private readonly buildParams;
|
|
8
|
+
constructor(compressionHandler: CompressionHandler.Interface, buildParams: BuildParams.Interface);
|
|
9
|
+
compress(fields: CmsModelField[]): ModelFieldCompressionAbstraction.CompressResponse;
|
|
10
|
+
decompress(data: ModelFieldCompressionAbstraction.DecompressParams): ModelFieldCompressionAbstraction.DecompressResponse;
|
|
11
|
+
}
|
|
12
|
+
export declare const ModelFieldCompression: typeof ModelFieldCompressionImpl & {
|
|
13
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IModelFieldCompression>;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CompressionHandler } from "@webiny/utils/exports/api.js";
|
|
2
|
+
import { ModelFieldCompression as ModelFieldCompressionAbstraction } from "./abstractions.js";
|
|
3
|
+
import { BuildParams } from "@webiny/api-core/features/buildParams/index.js";
|
|
4
|
+
class ModelFieldCompressionImpl {
|
|
5
|
+
constructor(compressionHandler, buildParams) {
|
|
6
|
+
this.compressionHandler = compressionHandler;
|
|
7
|
+
this.buildParams = buildParams;
|
|
8
|
+
}
|
|
9
|
+
async compress(fields) {
|
|
10
|
+
if (!this.buildParams.get("ContentModelFieldCompression")) {
|
|
11
|
+
return fields;
|
|
12
|
+
}
|
|
13
|
+
return this.compressionHandler.compress(fields);
|
|
14
|
+
}
|
|
15
|
+
async decompress(data) {
|
|
16
|
+
if (Array.isArray(data)) {
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
return this.compressionHandler.decompress(data);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export const ModelFieldCompression = ModelFieldCompressionAbstraction.createImplementation({
|
|
23
|
+
implementation: ModelFieldCompressionImpl,
|
|
24
|
+
dependencies: [CompressionHandler, BuildParams]
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=ModelFieldCompression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["CompressionHandler","ModelFieldCompression","ModelFieldCompressionAbstraction","BuildParams","ModelFieldCompressionImpl","constructor","compressionHandler","buildParams","compress","fields","get","decompress","data","Array","isArray","createImplementation","implementation","dependencies"],"sources":["ModelFieldCompression.ts"],"sourcesContent":["import { CompressionHandler } from \"@webiny/utils/exports/api.js\";\nimport { ModelFieldCompression as ModelFieldCompressionAbstraction } from \"./abstractions.js\";\nimport type { CmsModelField } from \"~/types/index.js\";\nimport { BuildParams } from \"@webiny/api-core/features/buildParams/index.js\";\n\nclass ModelFieldCompressionImpl implements ModelFieldCompressionAbstraction.Interface {\n public constructor(\n private readonly compressionHandler: CompressionHandler.Interface,\n private readonly buildParams: BuildParams.Interface\n ) {}\n\n public async compress(\n fields: CmsModelField[]\n ): ModelFieldCompressionAbstraction.CompressResponse {\n if (!this.buildParams.get<boolean>(\"ContentModelFieldCompression\")) {\n return fields;\n }\n return this.compressionHandler.compress(fields);\n }\n\n public async decompress(\n data: ModelFieldCompressionAbstraction.DecompressParams\n ): ModelFieldCompressionAbstraction.DecompressResponse {\n if (Array.isArray(data)) {\n return data as CmsModelField[];\n }\n return this.compressionHandler.decompress<CmsModelField[]>(data);\n }\n}\n\nexport const ModelFieldCompression = ModelFieldCompressionAbstraction.createImplementation({\n implementation: ModelFieldCompressionImpl,\n dependencies: [CompressionHandler, BuildParams]\n});\n"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,8BAA8B;AACjE,SAASC,qBAAqB,IAAIC,gCAAgC;AAElE,SAASC,WAAW,QAAQ,gDAAgD;AAE5E,MAAMC,yBAAyB,CAAuD;EAC3EC,WAAWA,CACGC,kBAAgD,EAChDC,WAAkC,EACrD;IAAA,KAFmBD,kBAAgD,GAAhDA,kBAAgD;IAAA,KAChDC,WAAkC,GAAlCA,WAAkC;EACpD;EAEH,MAAaC,QAAQA,CACjBC,MAAuB,EAC0B;IACjD,IAAI,CAAC,IAAI,CAACF,WAAW,CAACG,GAAG,CAAU,8BAA8B,CAAC,EAAE;MAChE,OAAOD,MAAM;IACjB;IACA,OAAO,IAAI,CAACH,kBAAkB,CAACE,QAAQ,CAACC,MAAM,CAAC;EACnD;EAEA,MAAaE,UAAUA,CACnBC,IAAuD,EACJ;IACnD,IAAIC,KAAK,CAACC,OAAO,CAACF,IAAI,CAAC,EAAE;MACrB,OAAOA,IAAI;IACf;IACA,OAAO,IAAI,CAACN,kBAAkB,CAACK,UAAU,CAAkBC,IAAI,CAAC;EACpE;AACJ;AAEA,OAAO,MAAMX,qBAAqB,GAAGC,gCAAgC,CAACa,oBAAoB,CAAC;EACvFC,cAAc,EAAEZ,yBAAyB;EACzCa,YAAY,EAAE,CAACjB,kBAAkB,EAAEG,WAAW;AAClD,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CmsModelField } from "../../../types/index.js";
|
|
2
|
+
export interface IModelFieldCompressionCompressResult {
|
|
3
|
+
compression: string;
|
|
4
|
+
value: string;
|
|
5
|
+
}
|
|
6
|
+
export interface IModelFieldCompression {
|
|
7
|
+
compress(fields: CmsModelField[]): Promise<IModelFieldCompressionCompressResult | CmsModelField[]>;
|
|
8
|
+
decompress(data: IModelFieldCompressionCompressResult | CmsModelField[] | unknown): Promise<CmsModelField[]>;
|
|
9
|
+
}
|
|
10
|
+
export declare const ModelFieldCompression: import("@webiny/di").Abstraction<IModelFieldCompression>;
|
|
11
|
+
export declare namespace ModelFieldCompression {
|
|
12
|
+
type Interface = IModelFieldCompression;
|
|
13
|
+
type CompressParams = CmsModelField[];
|
|
14
|
+
type CompressResponse = Promise<IModelFieldCompressionCompressResult | CmsModelField[]>;
|
|
15
|
+
type DecompressParams = IModelFieldCompressionCompressResult | CmsModelField[] | unknown;
|
|
16
|
+
type DecompressResponse = Promise<CmsModelField[]>;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createAbstraction","ModelFieldCompression"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api/index.js\";\nimport type { CmsModelField } from \"~/types/index.js\";\n\nexport interface IModelFieldCompressionCompressResult {\n compression: string;\n value: string;\n}\n\nexport interface IModelFieldCompression {\n compress(\n fields: CmsModelField[]\n ): Promise<IModelFieldCompressionCompressResult | CmsModelField[]>;\n decompress(\n data: IModelFieldCompressionCompressResult | CmsModelField[] | unknown\n ): Promise<CmsModelField[]>;\n}\n\nexport const ModelFieldCompression = createAbstraction<IModelFieldCompression>(\n \"Cms/Model/FieldCompression\"\n);\n\nexport namespace ModelFieldCompression {\n export type Interface = IModelFieldCompression;\n export type CompressParams = CmsModelField[];\n export type CompressResponse = Promise<IModelFieldCompressionCompressResult | CmsModelField[]>;\n export type DecompressParams = IModelFieldCompressionCompressResult | CmsModelField[] | unknown;\n export type DecompressResponse = Promise<CmsModelField[]>;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,8BAA8B;AAiBhE,OAAO,MAAMC,qBAAqB,GAAGD,iBAAiB,CAClD,4BACJ,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { ModelFieldCompression } from "./ModelFieldCompression.js";
|
|
3
|
+
export const ModelFieldCompressionFeature = createFeature({
|
|
4
|
+
name: "Cms/ModelFieldCompression",
|
|
5
|
+
register(container) {
|
|
6
|
+
container.register(ModelFieldCompression).inSingletonScope();
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createFeature","ModelFieldCompression","ModelFieldCompressionFeature","name","register","container","inSingletonScope"],"sources":["feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ModelFieldCompression } from \"./ModelFieldCompression.js\";\n\nexport const ModelFieldCompressionFeature = createFeature({\n name: \"Cms/ModelFieldCompression\",\n register(container) {\n container.register(ModelFieldCompression).inSingletonScope();\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,qBAAqB;AAE9B,OAAO,MAAMC,4BAA4B,GAAGF,aAAa,CAAC;EACtDG,IAAI,EAAE,2BAA2B;EACjCC,QAAQA,CAACC,SAAS,EAAE;IAChBA,SAAS,CAACD,QAAQ,CAACH,qBAAqB,CAAC,CAACK,gBAAgB,CAAC,CAAC;EAChE;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ModelFieldCompression } from "./abstractions.js";
|