@webiny/api-headless-cms 6.5.0-beta.0 → 6.5.0-beta.10
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/entryDataValidation.js +3 -4
- package/crud/contentEntry/entryDataValidation.js.map +1 -1
- package/crud/contentModel/validate/endingAllowed.js +1 -1
- package/crud/contentModel/validate/endingAllowed.js.map +1 -1
- package/crud/contentModel/validate/pluralApiName.js +1 -1
- package/crud/contentModel/validate/pluralApiName.js.map +1 -1
- package/crud/contentModel/validate/singularApiName.js +1 -1
- package/crud/contentModel/validate/singularApiName.js.map +1 -1
- package/crud/contentModel/validation.js +2 -2
- package/crud/contentModel/validation.js.map +1 -1
- package/domain/contentModel/validation/endingAllowed.js +1 -1
- package/domain/contentModel/validation/endingAllowed.js.map +1 -1
- package/domain/contentModel/validation/pluralApiName.js +1 -1
- package/domain/contentModel/validation/pluralApiName.js.map +1 -1
- package/domain/contentModel/validation/singularApiName.js +1 -1
- package/domain/contentModel/validation/singularApiName.js.map +1 -1
- package/export/crud/exporting.js +2 -2
- package/export/crud/exporting.js.map +1 -1
- package/export/crud/imports/importGroups.js +1 -2
- package/export/crud/imports/importGroups.js.map +1 -1
- package/export/crud/imports/validateModels.js +1 -1
- package/export/crud/imports/validateModels.js.map +1 -1
- package/exports/api/cms/entry.d.ts +2 -0
- package/exports/api/cms/entry.js +2 -0
- package/exports/api/cms/model.d.ts +2 -0
- package/exports/api/cms/model.js +2 -0
- package/features/contentEntry/ContentEntriesFeature.js +4 -0
- package/features/contentEntry/ContentEntriesFeature.js.map +1 -1
- package/features/contentEntry/CreateEntry/CreateEntryUseCase.d.ts +2 -2
- package/features/contentEntry/CreateEntry/CreateEntryUseCase.js +2 -2
- package/features/contentEntry/CreateEntry/CreateEntryUseCase.js.map +1 -1
- package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromUseCase.d.ts +2 -4
- package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromUseCase.js +6 -14
- package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromUseCase.js.map +1 -1
- package/features/contentEntry/CreateEntryRevisionFrom/abstractions.d.ts +2 -0
- package/features/contentEntry/CreateEntryRevisionFrom/abstractions.js.map +1 -1
- package/features/contentEntry/DeleteEntry/DeleteEntryUseCase.d.ts +2 -2
- package/features/contentEntry/DeleteEntry/DeleteEntryUseCase.js +2 -2
- package/features/contentEntry/DeleteEntry/DeleteEntryUseCase.js.map +1 -1
- package/features/contentEntry/DeleteEntry/MoveEntryToBinUseCase.d.ts +2 -2
- package/features/contentEntry/DeleteEntry/MoveEntryToBinUseCase.js +2 -2
- package/features/contentEntry/DeleteEntry/MoveEntryToBinUseCase.js.map +1 -1
- package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionUseCase.d.ts +2 -2
- package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionUseCase.js +2 -2
- package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionUseCase.js.map +1 -1
- package/features/contentEntry/DeleteMultipleEntries/DeleteMultipleEntriesUseCase.d.ts +2 -2
- package/features/contentEntry/DeleteMultipleEntries/DeleteMultipleEntriesUseCase.js +2 -2
- package/features/contentEntry/DeleteMultipleEntries/DeleteMultipleEntriesUseCase.js.map +1 -1
- package/features/contentEntry/DuplicateEntry/DuplicateEntryUseCase.d.ts +17 -0
- package/features/contentEntry/DuplicateEntry/DuplicateEntryUseCase.js +83 -0
- package/features/contentEntry/DuplicateEntry/DuplicateEntryUseCase.js.map +1 -0
- package/features/contentEntry/DuplicateEntry/abstractions.d.ts +47 -0
- package/features/contentEntry/DuplicateEntry/abstractions.js +5 -0
- package/features/contentEntry/DuplicateEntry/abstractions.js.map +1 -0
- package/features/contentEntry/DuplicateEntry/events.d.ts +41 -0
- package/features/contentEntry/DuplicateEntry/events.js +32 -0
- package/features/contentEntry/DuplicateEntry/events.js.map +1 -0
- package/features/contentEntry/DuplicateEntry/feature.d.ts +4 -0
- package/features/contentEntry/DuplicateEntry/feature.js +11 -0
- package/features/contentEntry/DuplicateEntry/feature.js.map +1 -0
- package/features/contentEntry/DuplicateEntry/index.d.ts +2 -0
- package/features/contentEntry/DuplicateEntry/index.js +2 -0
- package/features/contentEntry/DuplicateEntry/prepareDuplicateValues.d.ts +7 -0
- package/features/contentEntry/DuplicateEntry/prepareDuplicateValues.js +12 -0
- package/features/contentEntry/DuplicateEntry/prepareDuplicateValues.js.map +1 -0
- package/features/contentEntry/EntryEventPublisher/EntryEventPublisher.d.ts +10 -0
- package/features/contentEntry/EntryEventPublisher/EntryEventPublisher.js +25 -0
- package/features/contentEntry/EntryEventPublisher/EntryEventPublisher.js.map +1 -0
- package/features/contentEntry/EntryEventPublisher/abstractions.d.ts +16 -0
- package/features/contentEntry/EntryEventPublisher/abstractions.js +5 -0
- package/features/contentEntry/EntryEventPublisher/abstractions.js.map +1 -0
- package/features/contentEntry/EntryEventPublisher/feature.d.ts +4 -0
- package/features/contentEntry/EntryEventPublisher/feature.js +11 -0
- package/features/contentEntry/EntryEventPublisher/feature.js.map +1 -0
- package/features/contentEntry/EntryEventPublisher/index.d.ts +2 -0
- package/features/contentEntry/EntryEventPublisher/index.js +2 -0
- package/features/contentEntry/MoveEntry/MoveEntryUseCase.d.ts +2 -2
- package/features/contentEntry/MoveEntry/MoveEntryUseCase.js +2 -2
- package/features/contentEntry/MoveEntry/MoveEntryUseCase.js.map +1 -1
- package/features/contentEntry/PublishEntry/PublishEntryUseCase.d.ts +2 -4
- package/features/contentEntry/PublishEntry/PublishEntryUseCase.js +6 -12
- package/features/contentEntry/PublishEntry/PublishEntryUseCase.js.map +1 -1
- package/features/contentEntry/RepublishEntry/RepublishEntryUseCase.d.ts +2 -2
- package/features/contentEntry/RepublishEntry/RepublishEntryUseCase.js +5 -3
- package/features/contentEntry/RepublishEntry/RepublishEntryUseCase.js.map +1 -1
- package/features/contentEntry/RestoreEntryFromBin/RestoreEntryFromBinUseCase.d.ts +2 -2
- package/features/contentEntry/RestoreEntryFromBin/RestoreEntryFromBinUseCase.js +2 -2
- package/features/contentEntry/RestoreEntryFromBin/RestoreEntryFromBinUseCase.js.map +1 -1
- package/features/contentEntry/UnpublishEntry/UnpublishEntryUseCase.d.ts +2 -2
- package/features/contentEntry/UnpublishEntry/UnpublishEntryUseCase.js +5 -3
- package/features/contentEntry/UnpublishEntry/UnpublishEntryUseCase.js.map +1 -1
- package/features/contentEntry/UpdateEntry/UpdateEntryUseCase.d.ts +2 -2
- package/features/contentEntry/UpdateEntry/UpdateEntryUseCase.js +5 -3
- package/features/contentEntry/UpdateEntry/UpdateEntryUseCase.js.map +1 -1
- package/features/contentEntry/UpdateRevisionDescription/UpdateRevisionDescriptionUseCase.d.ts +2 -2
- package/features/contentEntry/UpdateRevisionDescription/UpdateRevisionDescriptionUseCase.js +2 -2
- package/features/contentEntry/UpdateRevisionDescription/UpdateRevisionDescriptionUseCase.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.d.ts +5 -3
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js +40 -14
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/abstractions.d.ts +17 -1
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/abstractions.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/CreatePublishEntryDataFactory.d.ts +5 -3
- package/features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/CreatePublishEntryDataFactory.js +22 -16
- package/features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/CreatePublishEntryDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/abstractions.d.ts +15 -1
- package/features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/abstractions.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/CreateRepublishEntryDataFactory.d.ts +5 -3
- package/features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/CreateRepublishEntryDataFactory.js +17 -13
- package/features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/CreateRepublishEntryDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/abstractions.d.ts +13 -1
- package/features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/abstractions.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/CreateUnpublishEntryDataFactory.d.ts +6 -6
- package/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/CreateUnpublishEntryDataFactory.js +17 -18
- package/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/CreateUnpublishEntryDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/abstractions.d.ts +14 -2
- package/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/abstractions.js.map +1 -1
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.d.ts +5 -3
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js +66 -29
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/abstractions.d.ts +15 -1
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/abstractions.js.map +1 -1
- package/features/contentEntry/entryDataFactories/expiresAt.js +2 -2
- package/features/contentEntry/entryDataFactories/expiresAt.js.map +1 -1
- package/features/contentEntry/entryDataFactories/hasEntryContentChanged.d.ts +24 -0
- package/features/contentEntry/entryDataFactories/hasEntryContentChanged.js +13 -0
- package/features/contentEntry/entryDataFactories/hasEntryContentChanged.js.map +1 -0
- package/features/contentModel/CreateModel/CreateModelRepository.js +1 -2
- package/features/contentModel/CreateModel/CreateModelRepository.js.map +1 -1
- package/features/contentModel/CreateModelFrom/CreateModelFromRepository.js +1 -2
- package/features/contentModel/CreateModelFrom/CreateModelFromRepository.js.map +1 -1
- package/features/contentModel/ValuesSelectionGenerator/ValuesSelectionGenerator.js +1 -1
- package/features/contentModel/ValuesSelectionGenerator/ValuesSelectionGenerator.js.map +1 -1
- package/features/graphql/fields/base/AssetToGraphQL.js +7 -2
- package/features/graphql/fields/base/AssetToGraphQL.js.map +1 -1
- package/features/modelBuilder/abstractions.d.ts +4 -0
- package/features/modelBuilder/abstractions.js.map +1 -1
- package/features/modelBuilder/fields/DateTimeFieldType.js +1 -0
- package/features/modelBuilder/fields/DateTimeFieldType.js.map +1 -1
- package/features/modelBuilder/models/ModelBuilder.d.ts +8 -0
- package/features/modelBuilder/models/ModelBuilder.js +1 -0
- package/features/modelBuilder/models/ModelBuilder.js.map +1 -1
- package/features/modelBuilder/models/PrivateModelBuilder.d.ts +5 -0
- package/features/modelBuilder/models/PrivateModelBuilder.js +12 -1
- package/features/modelBuilder/models/PrivateModelBuilder.js.map +1 -1
- package/features/storage/fields/CompressedTextStorageTransform.js +1 -1
- package/features/storage/fields/CompressedTextStorageTransform.js.map +1 -1
- package/features/storage/fields/DateStorageTransform.js +3 -4
- package/features/storage/fields/DateStorageTransform.js.map +1 -1
- package/features/storage/fields/DynamicZoneStorageTransform.js +2 -2
- package/features/storage/fields/DynamicZoneStorageTransform.js.map +1 -1
- package/features/storage/fields/JsonStorageTransform.js +1 -1
- package/features/storage/fields/JsonStorageTransform.js.map +1 -1
- package/features/storage/fields/LongTextStorageTransform.js +1 -1
- package/features/storage/fields/LongTextStorageTransform.js.map +1 -1
- package/features/storage/fields/RichTextStorageTransform.js +1 -1
- package/features/storage/fields/RichTextStorageTransform.js.map +1 -1
- package/features/validation/validators/DateGteValidator.js +1 -1
- package/features/validation/validators/DateGteValidator.js.map +1 -1
- package/features/validation/validators/DateLteValidator.js +1 -1
- package/features/validation/validators/DateLteValidator.js.map +1 -1
- package/features/whereMapper/WhereMapper.js +3 -5
- package/features/whereMapper/WhereMapper.js.map +1 -1
- package/graphql/getSchema/generateCacheKey.js +1 -1
- package/graphql/getSchema/generateCacheKey.js.map +1 -1
- package/graphql/scalars/RevisionId.js +1 -1
- package/graphql/scalars/RevisionId.js.map +1 -1
- package/graphql/schema/createFieldResolvers.js +1 -1
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphql/schema/createManageResolvers.js +3 -1
- package/graphql/schema/createManageResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.js +2 -0
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveDuplicate.d.ts +7 -0
- package/graphql/schema/resolvers/manage/resolveDuplicate.js +11 -0
- package/graphql/schema/resolvers/manage/resolveDuplicate.js.map +1 -0
- package/package.json +26 -26
- package/plugins/CmsModelPlugin.js +9 -10
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/utils/caching/Cache.js +1 -1
- package/utils/caching/Cache.js.map +1 -1
- package/utils/date.js +1 -1
- package/utils/date.js.map +1 -1
- package/utils/entryStorage.js +1 -1
- package/utils/entryStorage.js.map +1 -1
- package/utils/renderFields.js +1 -1
- package/utils/renderFields.js.map +1 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { CreateUnpublishEntryDataFactory as FactoryAbstraction, type ICreateUnpublishEntryDataFactory } from "./abstractions.js";
|
|
2
|
+
import type { CmsEntry, CmsEntryValues, CmsModel } from "../../../../types/index.js";
|
|
3
|
+
import { GetLatestRevisionByEntryIdUseCase } from "../../../../features/contentEntry/GetLatestRevisionByEntryId/index.js";
|
|
4
4
|
declare class CreateUnpublishEntryDataFactoryImpl implements ICreateUnpublishEntryDataFactory {
|
|
5
|
-
private readonly
|
|
6
|
-
constructor(
|
|
7
|
-
create<TValues extends CmsEntryValues = CmsEntryValues>(originalEntry: CmsEntry<TValues>): Promise<
|
|
5
|
+
private readonly getLatestRevision;
|
|
6
|
+
constructor(getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface);
|
|
7
|
+
create<TValues extends CmsEntryValues = CmsEntryValues>(model: CmsModel, originalEntry: CmsEntry<TValues>): Promise<FactoryAbstraction.Return<TValues>>;
|
|
8
8
|
}
|
|
9
9
|
export declare const CreateUnpublishEntryDataFactory: import("@webiny/di").Implementation<typeof CreateUnpublishEntryDataFactoryImpl>;
|
|
10
10
|
export {};
|
|
@@ -1,39 +1,38 @@
|
|
|
1
|
-
import { createImplementation } from "@webiny/feature/api";
|
|
1
|
+
import { Result, createImplementation } from "@webiny/feature/api";
|
|
2
2
|
import { CreateUnpublishEntryDataFactory } from "./abstractions.js";
|
|
3
|
-
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
4
3
|
import { STATUS_UNPUBLISHED } from "../statuses.js";
|
|
5
4
|
import { getIdentity } from "../../../../utils/identity.js";
|
|
6
5
|
import { getDate } from "../../../../utils/date.js";
|
|
6
|
+
import { GetLatestRevisionByEntryIdUseCase } from "../../GetLatestRevisionByEntryId/index.js";
|
|
7
7
|
class CreateUnpublishEntryDataFactoryImpl {
|
|
8
|
-
constructor(
|
|
9
|
-
this.
|
|
8
|
+
constructor(getLatestRevision){
|
|
9
|
+
this.getLatestRevision = getLatestRevision;
|
|
10
10
|
}
|
|
11
|
-
async create(originalEntry) {
|
|
12
|
-
const
|
|
13
|
-
|
|
11
|
+
async create(model, originalEntry) {
|
|
12
|
+
const latestResult = await this.getLatestRevision.execute(model, {
|
|
13
|
+
id: originalEntry.entryId
|
|
14
|
+
});
|
|
15
|
+
if (latestResult.isFail()) return Result.fail(latestResult.error);
|
|
16
|
+
const latestEntry = latestResult.value;
|
|
14
17
|
const entry = {
|
|
15
18
|
...originalEntry,
|
|
16
19
|
status: STATUS_UNPUBLISHED,
|
|
17
|
-
savedOn: getDate(
|
|
18
|
-
modifiedOn: getDate(
|
|
19
|
-
savedBy: getIdentity(
|
|
20
|
-
modifiedBy: getIdentity(
|
|
21
|
-
revisionSavedOn: getDate(currentDateTime),
|
|
22
|
-
revisionModifiedOn: getDate(currentDateTime),
|
|
23
|
-
revisionSavedBy: getIdentity(currentIdentity),
|
|
24
|
-
revisionModifiedBy: getIdentity(currentIdentity),
|
|
20
|
+
savedOn: getDate(latestEntry.savedOn, originalEntry.savedOn),
|
|
21
|
+
modifiedOn: getDate(latestEntry.modifiedOn),
|
|
22
|
+
savedBy: getIdentity(latestEntry.savedBy, originalEntry.savedBy),
|
|
23
|
+
modifiedBy: getIdentity(latestEntry.modifiedBy),
|
|
25
24
|
live: null
|
|
26
25
|
};
|
|
27
|
-
return {
|
|
26
|
+
return Result.ok({
|
|
28
27
|
entry
|
|
29
|
-
};
|
|
28
|
+
});
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
const CreateUnpublishEntryDataFactory_CreateUnpublishEntryDataFactory = createImplementation({
|
|
33
32
|
abstraction: CreateUnpublishEntryDataFactory,
|
|
34
33
|
implementation: CreateUnpublishEntryDataFactoryImpl,
|
|
35
34
|
dependencies: [
|
|
36
|
-
|
|
35
|
+
GetLatestRevisionByEntryIdUseCase
|
|
37
36
|
]
|
|
38
37
|
});
|
|
39
38
|
export { CreateUnpublishEntryDataFactory_CreateUnpublishEntryDataFactory as CreateUnpublishEntryDataFactory };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/CreateUnpublishEntryDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/CreateUnpublishEntryDataFactory.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport {\n CreateUnpublishEntryDataFactory as FactoryAbstraction,\n type ICreateUnpublishEntryDataFactory
|
|
1
|
+
{"version":3,"file":"features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/CreateUnpublishEntryDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/CreateUnpublishEntryDataFactory.ts"],"sourcesContent":["import { createImplementation, Result } from \"@webiny/feature/api\";\nimport {\n CreateUnpublishEntryDataFactory as FactoryAbstraction,\n type ICreateUnpublishEntryDataFactory\n} from \"./abstractions.js\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\nimport { STATUS_UNPUBLISHED } from \"../statuses.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { GetLatestRevisionByEntryIdUseCase } from \"~/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\n\nclass CreateUnpublishEntryDataFactoryImpl implements ICreateUnpublishEntryDataFactory {\n public constructor(\n private readonly getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface\n ) {}\n\n public async create<TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n originalEntry: CmsEntry<TValues>\n ): Promise<FactoryAbstraction.Return<TValues>> {\n const latestResult = await this.getLatestRevision.execute<TValues>(model, {\n id: originalEntry.entryId\n });\n if (latestResult.isFail()) {\n return Result.fail(latestResult.error);\n }\n const latestEntry = latestResult.value;\n\n /**\n * Unpublishing is not a content modification, so saved/modified meta fields are kept.\n * Entry-level values are taken from the latest revision, because storage copies them\n * onto the latest revision when a non-latest revision is unpublished. Revision-level\n * values are the unpublished revision's own, and come from `originalEntry`.\n */\n const entry: CmsEntry<TValues> = {\n ...originalEntry,\n status: STATUS_UNPUBLISHED,\n savedOn: getDate(latestEntry.savedOn, originalEntry.savedOn),\n modifiedOn: getDate(latestEntry.modifiedOn),\n savedBy: getIdentity(latestEntry.savedBy, originalEntry.savedBy),\n modifiedBy: getIdentity(latestEntry.modifiedBy),\n live: null\n };\n\n return Result.ok({ entry });\n }\n}\n\nexport const CreateUnpublishEntryDataFactory = createImplementation({\n abstraction: FactoryAbstraction,\n implementation: CreateUnpublishEntryDataFactoryImpl,\n dependencies: [GetLatestRevisionByEntryIdUseCase]\n});\n"],"names":["CreateUnpublishEntryDataFactoryImpl","getLatestRevision","model","originalEntry","latestResult","Result","latestEntry","entry","STATUS_UNPUBLISHED","getDate","getIdentity","CreateUnpublishEntryDataFactory","createImplementation","FactoryAbstraction","GetLatestRevisionByEntryIdUseCase"],"mappings":";;;;;;AAWA,MAAMA;IACF,YACqBC,iBAA8D,CACjF;aADmBA,iBAAiB,GAAjBA;IAClB;IAEH,MAAa,OACTC,KAAe,EACfC,aAAgC,EACW;QAC3C,MAAMC,eAAe,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAUF,OAAO;YACtE,IAAIC,cAAc,OAAO;QAC7B;QACA,IAAIC,aAAa,MAAM,IACnB,OAAOC,OAAO,IAAI,CAACD,aAAa,KAAK;QAEzC,MAAME,cAAcF,aAAa,KAAK;QAQtC,MAAMG,QAA2B;YAC7B,GAAGJ,aAAa;YAChB,QAAQK;YACR,SAASC,QAAQH,YAAY,OAAO,EAAEH,cAAc,OAAO;YAC3D,YAAYM,QAAQH,YAAY,UAAU;YAC1C,SAASI,YAAYJ,YAAY,OAAO,EAAEH,cAAc,OAAO;YAC/D,YAAYO,YAAYJ,YAAY,UAAU;YAC9C,MAAM;QACV;QAEA,OAAOD,OAAO,EAAE,CAAC;YAAEE;QAAM;IAC7B;AACJ;AAEO,MAAMI,kEAAkCC,qBAAqB;IAChE,aAAaC;IACb,gBAAgBb;IAChB,cAAc;QAACc;KAAkC;AACrD"}
|
package/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/abstractions.d.ts
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type Result } from "@webiny/feature/api";
|
|
2
|
+
import type { GetLatestRevisionByEntryIdUseCase } from "../../../../features/contentEntry/GetLatestRevisionByEntryId/index.js";
|
|
3
|
+
import type { CmsEntry, CmsEntryValues, CmsModel } from "../../../../types/index.js";
|
|
2
4
|
export interface ICreateUnpublishEntryDataResponse<TValues extends CmsEntryValues = CmsEntryValues> {
|
|
3
5
|
entry: CmsEntry<TValues>;
|
|
4
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Expected failures of building the data of an entry being unpublished.
|
|
9
|
+
*/
|
|
10
|
+
export interface ICreateUnpublishEntryDataFactoryErrors {
|
|
11
|
+
latest: GetLatestRevisionByEntryIdUseCase.Error;
|
|
12
|
+
}
|
|
13
|
+
type FactoryError = ICreateUnpublishEntryDataFactoryErrors[keyof ICreateUnpublishEntryDataFactoryErrors];
|
|
5
14
|
export interface ICreateUnpublishEntryDataFactory {
|
|
6
|
-
create<TValues extends CmsEntryValues = CmsEntryValues>(originalEntry: CmsEntry<TValues>): Promise<ICreateUnpublishEntryDataResponse<TValues>>;
|
|
15
|
+
create<TValues extends CmsEntryValues = CmsEntryValues>(model: CmsModel, originalEntry: CmsEntry<TValues>): Promise<Result<ICreateUnpublishEntryDataResponse<TValues>, FactoryError>>;
|
|
7
16
|
}
|
|
8
17
|
export declare const CreateUnpublishEntryDataFactory: import("@webiny/di").Abstraction<ICreateUnpublishEntryDataFactory>;
|
|
9
18
|
export declare namespace CreateUnpublishEntryDataFactory {
|
|
10
19
|
type Interface = ICreateUnpublishEntryDataFactory;
|
|
20
|
+
type Error = FactoryError;
|
|
21
|
+
type Return<TValues extends CmsEntryValues = CmsEntryValues> = Result<ICreateUnpublishEntryDataResponse<TValues>, FactoryError>;
|
|
11
22
|
type Response<TValues extends CmsEntryValues = CmsEntryValues> = ICreateUnpublishEntryDataResponse<TValues>;
|
|
12
23
|
}
|
|
24
|
+
export {};
|
package/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/abstractions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/abstractions.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { CmsEntry, CmsEntryValues } from \"~/types/index.js\";\n\nexport interface ICreateUnpublishEntryDataResponse<\n TValues extends CmsEntryValues = CmsEntryValues\n> {\n entry: CmsEntry<TValues>;\n}\n\nexport interface ICreateUnpublishEntryDataFactory {\n create<TValues extends CmsEntryValues = CmsEntryValues>(\n originalEntry: CmsEntry<TValues>\n ): Promise<ICreateUnpublishEntryDataResponse<TValues>>;\n}\n\nexport const CreateUnpublishEntryDataFactory = createAbstraction<ICreateUnpublishEntryDataFactory>(\n \"Cms/Entry/CreateUnpublishEntryDataFactory\"\n);\n\nexport namespace CreateUnpublishEntryDataFactory {\n export type Interface = ICreateUnpublishEntryDataFactory;\n export type Response<TValues extends CmsEntryValues = CmsEntryValues> =\n ICreateUnpublishEntryDataResponse<TValues>;\n}\n"],"names":["CreateUnpublishEntryDataFactory","createAbstraction"],"mappings":";
|
|
1
|
+
{"version":3,"file":"features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/abstractions.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/abstractions.ts"],"sourcesContent":["import { createAbstraction, type Result } from \"@webiny/feature/api\";\nimport type { GetLatestRevisionByEntryIdUseCase } from \"~/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\n\nexport interface ICreateUnpublishEntryDataResponse<\n TValues extends CmsEntryValues = CmsEntryValues\n> {\n entry: CmsEntry<TValues>;\n}\n\n/**\n * Expected failures of building the data of an entry being unpublished.\n */\nexport interface ICreateUnpublishEntryDataFactoryErrors {\n latest: GetLatestRevisionByEntryIdUseCase.Error;\n}\n\ntype FactoryError =\n ICreateUnpublishEntryDataFactoryErrors[keyof ICreateUnpublishEntryDataFactoryErrors];\n\nexport interface ICreateUnpublishEntryDataFactory {\n create<TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n originalEntry: CmsEntry<TValues>\n ): Promise<Result<ICreateUnpublishEntryDataResponse<TValues>, FactoryError>>;\n}\n\nexport const CreateUnpublishEntryDataFactory = createAbstraction<ICreateUnpublishEntryDataFactory>(\n \"Cms/Entry/CreateUnpublishEntryDataFactory\"\n);\n\nexport namespace CreateUnpublishEntryDataFactory {\n export type Interface = ICreateUnpublishEntryDataFactory;\n export type Error = FactoryError;\n export type Return<TValues extends CmsEntryValues = CmsEntryValues> = Result<\n ICreateUnpublishEntryDataResponse<TValues>,\n FactoryError\n >;\n export type Response<TValues extends CmsEntryValues = CmsEntryValues> =\n ICreateUnpublishEntryDataResponse<TValues>;\n}\n"],"names":["CreateUnpublishEntryDataFactory","createAbstraction"],"mappings":";AA2BO,MAAMA,kCAAkCC,kBAC3C"}
|
package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { type IUpdateEntryDataFactory,
|
|
1
|
+
import { type IUpdateEntryDataFactory, UpdateEntryDataFactory as FactoryAbstraction } from "./abstractions.js";
|
|
2
2
|
import { CmsContext } from "../../../../features/shared/abstractions.js";
|
|
3
3
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
4
4
|
import type { CmsEntry, CmsEntryValues, CmsModel, UpdateCmsEntryInput, UpdateCmsEntryOptionsInput } from "../../../../types/index.js";
|
|
5
5
|
import { ModelToAstConverter } from "../../../../features/contentModel/ModelToAstConverter/abstractions.js";
|
|
6
|
+
import { GetLatestRevisionByEntryIdUseCase } from "../../../../features/contentEntry/GetLatestRevisionByEntryId/index.js";
|
|
6
7
|
declare class UpdateEntryDataFactoryImpl implements IUpdateEntryDataFactory {
|
|
7
8
|
private readonly cmsContext;
|
|
8
9
|
private readonly identityContext;
|
|
9
10
|
private readonly modelToAstConverter;
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
private readonly getLatestRevision;
|
|
12
|
+
constructor(cmsContext: CmsContext.Interface, identityContext: IdentityContext.Interface, modelToAstConverter: ModelToAstConverter.Interface, getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface);
|
|
13
|
+
create<TValues extends CmsEntryValues = CmsEntryValues>(model: CmsModel, rawInput: UpdateCmsEntryInput<TValues>, originalEntry: CmsEntry<TValues>, options?: UpdateCmsEntryOptionsInput): Promise<FactoryAbstraction.Return<TValues>>;
|
|
12
14
|
}
|
|
13
15
|
export declare const UpdateEntryDataFactory: import("@webiny/di").Implementation<typeof UpdateEntryDataFactoryImpl>;
|
|
14
16
|
export {};
|
package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import { createImplementation } from "@webiny/feature/api";
|
|
1
|
+
import { Result, createImplementation } from "@webiny/feature/api";
|
|
2
2
|
import { UpdateEntryDataFactory } from "./abstractions.js";
|
|
3
3
|
import { CmsContext } from "../../../shared/abstractions.js";
|
|
4
4
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
5
5
|
import { getDate } from "../../../../utils/date.js";
|
|
6
6
|
import { getIdentity } from "../../../../utils/identity.js";
|
|
7
|
-
import {
|
|
7
|
+
import { validateModelEntryData } from "../../../../crud/contentEntry/entryDataValidation.js";
|
|
8
|
+
import { EntryValidationError } from "../../../../domain/contentEntry/errors.js";
|
|
8
9
|
import { referenceFieldsMapping } from "../../../../crud/contentEntry/referenceFieldsMapping.js";
|
|
9
10
|
import { mapAndCleanUpdatedInputData } from "../mapAndCleanUpdatedInputData.js";
|
|
10
11
|
import { getSystem } from "../system.js";
|
|
11
12
|
import { getExpiresAt } from "../expiresAt.js";
|
|
12
13
|
import { ModelToAstConverter } from "../../../contentModel/ModelToAstConverter/abstractions.js";
|
|
13
14
|
import { ensureItemIds } from "../../ensureItemIds.js";
|
|
15
|
+
import { hasEntryContentChanged } from "../hasEntryContentChanged.js";
|
|
16
|
+
import { GetLatestRevisionByEntryIdUseCase } from "../../GetLatestRevisionByEntryId/index.js";
|
|
14
17
|
const allowedEntryStatus = [
|
|
15
18
|
"draft",
|
|
16
19
|
"published",
|
|
@@ -18,20 +21,27 @@ const allowedEntryStatus = [
|
|
|
18
21
|
];
|
|
19
22
|
const transformEntryStatus = (status)=>allowedEntryStatus.includes(status) ? status : "draft";
|
|
20
23
|
class UpdateEntryDataFactoryImpl {
|
|
21
|
-
constructor(cmsContext, identityContext, modelToAstConverter){
|
|
24
|
+
constructor(cmsContext, identityContext, modelToAstConverter, getLatestRevision){
|
|
22
25
|
this.cmsContext = cmsContext;
|
|
23
26
|
this.identityContext = identityContext;
|
|
24
27
|
this.modelToAstConverter = modelToAstConverter;
|
|
28
|
+
this.getLatestRevision = getLatestRevision;
|
|
25
29
|
}
|
|
26
30
|
async create(model, rawInput, originalEntry, options) {
|
|
31
|
+
const latestResult = await this.getLatestRevision.execute(model, {
|
|
32
|
+
id: originalEntry.entryId
|
|
33
|
+
});
|
|
34
|
+
if (latestResult.isFail()) return Result.fail(latestResult.error);
|
|
35
|
+
const latestEntry = latestResult.value;
|
|
27
36
|
const cleanedValues = mapAndCleanUpdatedInputData(model, rawInput?.values || {});
|
|
28
|
-
await
|
|
37
|
+
const invalidFields = await validateModelEntryData({
|
|
29
38
|
context: this.cmsContext,
|
|
30
39
|
model,
|
|
31
40
|
values: cleanedValues,
|
|
32
41
|
entry: originalEntry,
|
|
33
42
|
skipValidation: options?.skipValidation
|
|
34
43
|
});
|
|
44
|
+
if (invalidFields.length > 0) return Result.fail(new EntryValidationError("Validation failed.", invalidFields));
|
|
35
45
|
const mergedValues = {
|
|
36
46
|
...originalEntry.values,
|
|
37
47
|
...cleanedValues
|
|
@@ -46,36 +56,62 @@ class UpdateEntryDataFactoryImpl {
|
|
|
46
56
|
});
|
|
47
57
|
const currentIdentity = this.identityContext.getIdentity();
|
|
48
58
|
const currentDateTime = new Date();
|
|
59
|
+
const contentChanged = hasEntryContentChanged({
|
|
60
|
+
values,
|
|
61
|
+
baselineValues: originalEntry.values
|
|
62
|
+
});
|
|
63
|
+
const entryLevelSaved = contentChanged ? {
|
|
64
|
+
savedOn: currentDateTime,
|
|
65
|
+
modifiedOn: currentDateTime,
|
|
66
|
+
savedBy: currentIdentity,
|
|
67
|
+
modifiedBy: currentIdentity
|
|
68
|
+
} : {
|
|
69
|
+
savedOn: latestEntry.savedOn,
|
|
70
|
+
modifiedOn: latestEntry.modifiedOn,
|
|
71
|
+
savedBy: latestEntry.savedBy,
|
|
72
|
+
modifiedBy: latestEntry.modifiedBy
|
|
73
|
+
};
|
|
74
|
+
const revisionLevelSaved = contentChanged ? {
|
|
75
|
+
revisionSavedOn: currentDateTime,
|
|
76
|
+
revisionModifiedOn: currentDateTime,
|
|
77
|
+
revisionSavedBy: currentIdentity,
|
|
78
|
+
revisionModifiedBy: currentIdentity
|
|
79
|
+
} : {
|
|
80
|
+
revisionSavedOn: originalEntry.revisionSavedOn,
|
|
81
|
+
revisionModifiedOn: originalEntry.revisionModifiedOn,
|
|
82
|
+
revisionSavedBy: originalEntry.revisionSavedBy,
|
|
83
|
+
revisionModifiedBy: originalEntry.revisionModifiedBy
|
|
84
|
+
};
|
|
49
85
|
const entry = {
|
|
50
86
|
...originalEntry,
|
|
51
87
|
revisionCreatedOn: getDate(rawInput.revisionCreatedOn, originalEntry.revisionCreatedOn),
|
|
52
|
-
revisionModifiedOn: getDate(rawInput.revisionModifiedOn,
|
|
53
|
-
revisionSavedOn: getDate(rawInput.revisionSavedOn,
|
|
54
|
-
revisionDeletedOn: getDate(rawInput.revisionDeletedOn,
|
|
55
|
-
revisionRestoredOn: getDate(rawInput.revisionRestoredOn,
|
|
88
|
+
revisionModifiedOn: getDate(rawInput.revisionModifiedOn, revisionLevelSaved.revisionModifiedOn),
|
|
89
|
+
revisionSavedOn: getDate(rawInput.revisionSavedOn, revisionLevelSaved.revisionSavedOn),
|
|
90
|
+
revisionDeletedOn: getDate(rawInput.revisionDeletedOn, originalEntry.revisionDeletedOn),
|
|
91
|
+
revisionRestoredOn: getDate(rawInput.revisionRestoredOn, originalEntry.revisionRestoredOn),
|
|
56
92
|
revisionFirstPublishedOn: getDate(rawInput.revisionFirstPublishedOn, originalEntry.revisionFirstPublishedOn),
|
|
57
93
|
revisionLastPublishedOn: getDate(rawInput.revisionLastPublishedOn, originalEntry.revisionLastPublishedOn),
|
|
58
94
|
revisionCreatedBy: getIdentity(rawInput.revisionCreatedBy, originalEntry.revisionCreatedBy),
|
|
59
|
-
revisionModifiedBy: getIdentity(rawInput.revisionModifiedBy,
|
|
60
|
-
revisionSavedBy: getIdentity(rawInput.revisionSavedBy,
|
|
61
|
-
revisionDeletedBy: getIdentity(rawInput.
|
|
62
|
-
revisionRestoredBy: getIdentity(rawInput.revisionRestoredBy,
|
|
95
|
+
revisionModifiedBy: getIdentity(rawInput.revisionModifiedBy, revisionLevelSaved.revisionModifiedBy),
|
|
96
|
+
revisionSavedBy: getIdentity(rawInput.revisionSavedBy, revisionLevelSaved.revisionSavedBy),
|
|
97
|
+
revisionDeletedBy: getIdentity(rawInput.revisionDeletedBy, originalEntry.revisionDeletedBy),
|
|
98
|
+
revisionRestoredBy: getIdentity(rawInput.revisionRestoredBy, originalEntry.revisionRestoredBy),
|
|
63
99
|
revisionFirstPublishedBy: getIdentity(rawInput.revisionFirstPublishedBy, originalEntry.revisionFirstPublishedBy),
|
|
64
100
|
revisionLastPublishedBy: getIdentity(rawInput.revisionLastPublishedBy, originalEntry.revisionLastPublishedBy),
|
|
65
|
-
createdOn: getDate(rawInput.createdOn,
|
|
66
|
-
savedOn: getDate(rawInput.savedOn,
|
|
67
|
-
modifiedOn: getDate(rawInput.modifiedOn,
|
|
68
|
-
deletedOn: getDate(rawInput.deletedOn,
|
|
69
|
-
restoredOn: getDate(rawInput.restoredOn,
|
|
70
|
-
firstPublishedOn: getDate(rawInput.firstPublishedOn,
|
|
71
|
-
lastPublishedOn: getDate(rawInput.lastPublishedOn,
|
|
72
|
-
createdBy: getIdentity(rawInput.createdBy,
|
|
73
|
-
savedBy: getIdentity(rawInput.savedBy,
|
|
74
|
-
modifiedBy: getIdentity(rawInput.modifiedBy,
|
|
75
|
-
deletedBy: getIdentity(rawInput.deletedBy,
|
|
76
|
-
restoredBy: getIdentity(rawInput.restoredBy,
|
|
77
|
-
firstPublishedBy: getIdentity(rawInput.firstPublishedBy,
|
|
78
|
-
lastPublishedBy: getIdentity(rawInput.lastPublishedBy,
|
|
101
|
+
createdOn: getDate(rawInput.createdOn, latestEntry.createdOn),
|
|
102
|
+
savedOn: getDate(rawInput.savedOn, entryLevelSaved.savedOn),
|
|
103
|
+
modifiedOn: getDate(rawInput.modifiedOn, entryLevelSaved.modifiedOn),
|
|
104
|
+
deletedOn: getDate(rawInput.deletedOn, latestEntry.deletedOn),
|
|
105
|
+
restoredOn: getDate(rawInput.restoredOn, latestEntry.restoredOn),
|
|
106
|
+
firstPublishedOn: getDate(rawInput.firstPublishedOn, latestEntry.firstPublishedOn),
|
|
107
|
+
lastPublishedOn: getDate(rawInput.lastPublishedOn, latestEntry.lastPublishedOn),
|
|
108
|
+
createdBy: getIdentity(rawInput.createdBy, latestEntry.createdBy),
|
|
109
|
+
savedBy: getIdentity(rawInput.savedBy, entryLevelSaved.savedBy),
|
|
110
|
+
modifiedBy: getIdentity(rawInput.modifiedBy, entryLevelSaved.modifiedBy),
|
|
111
|
+
deletedBy: getIdentity(rawInput.deletedBy, latestEntry.deletedBy),
|
|
112
|
+
restoredBy: getIdentity(rawInput.restoredBy, latestEntry.restoredBy),
|
|
113
|
+
firstPublishedBy: getIdentity(rawInput.firstPublishedBy, latestEntry.firstPublishedBy),
|
|
114
|
+
lastPublishedBy: getIdentity(rawInput.lastPublishedBy, latestEntry.lastPublishedBy),
|
|
79
115
|
values,
|
|
80
116
|
status: transformEntryStatus(originalEntry.status),
|
|
81
117
|
system: getSystem({
|
|
@@ -91,13 +127,13 @@ class UpdateEntryDataFactoryImpl {
|
|
|
91
127
|
if (folderId) entry.location = {
|
|
92
128
|
folderId
|
|
93
129
|
};
|
|
94
|
-
return {
|
|
130
|
+
return Result.ok({
|
|
95
131
|
entry,
|
|
96
132
|
input: {
|
|
97
133
|
...rawInput,
|
|
98
134
|
values: structuredClone(values)
|
|
99
135
|
}
|
|
100
|
-
};
|
|
136
|
+
});
|
|
101
137
|
}
|
|
102
138
|
}
|
|
103
139
|
const UpdateEntryDataFactory_UpdateEntryDataFactory = createImplementation({
|
|
@@ -106,7 +142,8 @@ const UpdateEntryDataFactory_UpdateEntryDataFactory = createImplementation({
|
|
|
106
142
|
dependencies: [
|
|
107
143
|
CmsContext,
|
|
108
144
|
IdentityContext,
|
|
109
|
-
ModelToAstConverter
|
|
145
|
+
ModelToAstConverter,
|
|
146
|
+
GetLatestRevisionByEntryIdUseCase
|
|
110
147
|
]
|
|
111
148
|
});
|
|
112
149
|
export { UpdateEntryDataFactory_UpdateEntryDataFactory as UpdateEntryDataFactory };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport {\n type IUpdateEntryDataFactory,\n type IUpdateEntryDataResponse,\n UpdateEntryDataFactory as FactoryAbstraction\n} from \"./abstractions.js\";\nimport { CmsContext } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type {\n CmsEntry,\n CmsEntryStatus,\n CmsEntryValues,\n CmsModel,\n UpdateCmsEntryInput,\n UpdateCmsEntryOptionsInput\n} from \"~/types/index.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport { validateModelEntryDataOrThrow } from \"~/crud/contentEntry/entryDataValidation.js\";\nimport { referenceFieldsMapping } from \"~/crud/contentEntry/referenceFieldsMapping.js\";\nimport { mapAndCleanUpdatedInputData } from \"../mapAndCleanUpdatedInputData.js\";\nimport { getSystem } from \"../system.js\";\nimport { getExpiresAt } from \"../expiresAt.js\";\nimport { ModelToAstConverter } from \"~/features/contentModel/ModelToAstConverter/abstractions.js\";\nimport { ensureItemIds } from \"../../ensureItemIds.js\";\n\nconst allowedEntryStatus: string[] = [\"draft\", \"published\", \"unpublished\"];\n\nconst transformEntryStatus = (status: CmsEntryStatus | string): CmsEntryStatus => {\n return allowedEntryStatus.includes(status) ? (status as CmsEntryStatus) : \"draft\";\n};\n\nclass UpdateEntryDataFactoryImpl implements IUpdateEntryDataFactory {\n public constructor(\n private readonly cmsContext: CmsContext.Interface,\n private readonly identityContext: IdentityContext.Interface,\n private readonly modelToAstConverter: ModelToAstConverter.Interface\n ) {}\n\n public async create<TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n rawInput: UpdateCmsEntryInput<TValues>,\n originalEntry: CmsEntry<TValues>,\n options?: UpdateCmsEntryOptionsInput\n ): Promise<IUpdateEntryDataResponse<TValues>> {\n const cleanedValues = mapAndCleanUpdatedInputData<TValues>(\n model,\n rawInput?.values || ({} as TValues)\n );\n\n await validateModelEntryDataOrThrow({\n context: this.cmsContext,\n model,\n values: cleanedValues,\n entry: originalEntry,\n skipValidation: options?.skipValidation\n });\n\n const mergedValues: TValues = {\n ...originalEntry.values,\n ...cleanedValues\n };\n\n const modelAst = this.modelToAstConverter.toAst(model);\n await ensureItemIds(modelAst, mergedValues);\n\n const values = await referenceFieldsMapping<TValues>({\n context: this.cmsContext,\n model,\n values: mergedValues,\n validateEntries: false\n });\n\n const currentIdentity = this.identityContext.getIdentity();\n const currentDateTime = new Date();\n\n const entry: CmsEntry<TValues> = {\n ...originalEntry,\n revisionCreatedOn: getDate(rawInput.revisionCreatedOn, originalEntry.revisionCreatedOn),\n revisionModifiedOn: getDate(rawInput.revisionModifiedOn, currentDateTime),\n revisionSavedOn: getDate(rawInput.revisionSavedOn, currentDateTime),\n revisionDeletedOn: getDate(rawInput.revisionDeletedOn, null),\n revisionRestoredOn: getDate(rawInput.revisionRestoredOn, null),\n revisionFirstPublishedOn: getDate(\n rawInput.revisionFirstPublishedOn,\n originalEntry.revisionFirstPublishedOn\n ),\n revisionLastPublishedOn: getDate(\n rawInput.revisionLastPublishedOn,\n originalEntry.revisionLastPublishedOn\n ),\n revisionCreatedBy: getIdentity(\n rawInput.revisionCreatedBy,\n originalEntry.revisionCreatedBy\n )!,\n revisionModifiedBy: getIdentity(rawInput.revisionModifiedBy, currentIdentity),\n revisionSavedBy: getIdentity(rawInput.revisionSavedBy, currentIdentity)!,\n revisionDeletedBy: getIdentity(rawInput.revisionSavedBy, null),\n revisionRestoredBy: getIdentity(rawInput.revisionRestoredBy, null),\n revisionFirstPublishedBy: getIdentity(\n rawInput.revisionFirstPublishedBy,\n originalEntry.revisionFirstPublishedBy\n ),\n revisionLastPublishedBy: getIdentity(\n rawInput.revisionLastPublishedBy,\n originalEntry.revisionLastPublishedBy\n ),\n createdOn: getDate(rawInput.createdOn, originalEntry.createdOn),\n savedOn: getDate(rawInput.savedOn, currentDateTime),\n modifiedOn: getDate(rawInput.modifiedOn, currentDateTime),\n deletedOn: getDate(rawInput.deletedOn, null),\n restoredOn: getDate(rawInput.restoredOn, null),\n firstPublishedOn: getDate(rawInput.firstPublishedOn, originalEntry.firstPublishedOn),\n lastPublishedOn: getDate(rawInput.lastPublishedOn, originalEntry.lastPublishedOn),\n createdBy: getIdentity(rawInput.createdBy, originalEntry.createdBy)!,\n savedBy: getIdentity(rawInput.savedBy, currentIdentity)!,\n modifiedBy: getIdentity(rawInput.modifiedBy, currentIdentity),\n deletedBy: getIdentity(rawInput.deletedBy, null),\n restoredBy: getIdentity(rawInput.restoredBy, null),\n firstPublishedBy: getIdentity(\n rawInput.firstPublishedBy,\n originalEntry.firstPublishedBy\n ),\n lastPublishedBy: getIdentity(rawInput.lastPublishedBy, originalEntry.lastPublishedBy),\n values,\n status: transformEntryStatus(originalEntry.status),\n system: getSystem({\n input: rawInput,\n original: originalEntry\n }),\n live: originalEntry.live,\n expiresAt: getExpiresAt({ expiresAt: rawInput.expiresAt }, originalEntry)\n };\n\n const folderId = rawInput.wbyAco_location?.folderId;\n if (folderId) {\n entry.location = {\n folderId\n };\n }\n\n return {\n entry,\n input: {\n ...rawInput,\n values: structuredClone(values)\n }\n };\n }\n}\n\nexport const UpdateEntryDataFactory = createImplementation({\n abstraction: FactoryAbstraction,\n implementation: UpdateEntryDataFactoryImpl,\n dependencies: [CmsContext, IdentityContext, ModelToAstConverter]\n});\n"],"names":["allowedEntryStatus","transformEntryStatus","status","UpdateEntryDataFactoryImpl","cmsContext","identityContext","modelToAstConverter","model","rawInput","originalEntry","options","cleanedValues","mapAndCleanUpdatedInputData","validateModelEntryDataOrThrow","mergedValues","modelAst","ensureItemIds","values","referenceFieldsMapping","currentIdentity","currentDateTime","Date","entry","getDate","getIdentity","getSystem","getExpiresAt","folderId","structuredClone","UpdateEntryDataFactory","createImplementation","FactoryAbstraction","CmsContext","IdentityContext","ModelToAstConverter"],"mappings":";;;;;;;;;;;;;AA0BA,MAAMA,qBAA+B;IAAC;IAAS;IAAa;CAAc;AAE1E,MAAMC,uBAAuB,CAACC,SACnBF,mBAAmB,QAAQ,CAACE,UAAWA,SAA4B;AAG9E,MAAMC;IACF,YACqBC,UAAgC,EAChCC,eAA0C,EAC1CC,mBAAkD,CACrE;aAHmBF,UAAU,GAAVA;aACAC,eAAe,GAAfA;aACAC,mBAAmB,GAAnBA;IAClB;IAEH,MAAa,OACTC,KAAe,EACfC,QAAsC,EACtCC,aAAgC,EAChCC,OAAoC,EACM;QAC1C,MAAMC,gBAAgBC,4BAClBL,OACAC,UAAU,UAAW,CAAC;QAG1B,MAAMK,8BAA8B;YAChC,SAAS,IAAI,CAAC,UAAU;YACxBN;YACA,QAAQI;YACR,OAAOF;YACP,gBAAgBC,SAAS;QAC7B;QAE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zC,WAAWG,QAAQf,SAAS,SAAS,EAAE;YACvC,YAAYe,QAAQf,SAAS,UAAU,EAAE;YACzC,kBAAkBe,QAAQf,SAAS,gBAAgB,EAAEC,cAAc,gBAAgB;YACnF,iBAAiBc,QAAQf,SAAS,eAAe,EAAEC,cAAc,eAAe;YAChF,WAAWe,YAAYhB,SAAS,SAAS,EAAEC,cAAc,SAAS;YAClE,SAASe,YAAYhB,SAAS,OAAO,EAAEW;YACvC,YAAYK,YAAYhB,SAAS,UAAU,EAAEW;YAC7C,WAAWK,YAAYhB,SAAS,SAAS,EAAE;YAC3C,YAAYgB,YAAYhB,SAAS,UAAU,EAAE;YAC7C,kBAAkBgB,YACdhB,SAAS,gBAAgB,EACzBC,cAAc,gBAAgB;YAElC,iBAAiBe,YAAYhB,SAAS,eAAe,EAAEC,cAAc,eAAe;YACpFQ;YACA,QAAQhB,qBAAqBQ,cAAc,MAAM;YACjD,QAAQgB,UAAU;gBACd,OAAOjB;gBACP,UAAUC;YACd;YACA,MAAMA,cAAc,IAAI;YACxB,WAAWiB,aAAa;gBAAE,WAAWlB,SAAS,SAAS;YAAC,GAAGC;QAC/D;QAEA,MAAMkB,WAAWnB,SAAS,eAAe,EAAE;QAC3C,IAAImB,UACAL,MAAM,QAAQ,GAAG;YACbK;QACJ;QAGJ,OAAO;YACHL;YACA,OAAO;gBACH,GAAGd,QAAQ;gBACX,QAAQoB,gBAAgBX;YAC5B;QACJ;IACJ;AACJ;AAEO,MAAMY,gDAAyBC,qBAAqB;IACvD,aAAaC;IACb,gBAAgB5B;IAChB,cAAc;QAAC6B;QAAYC;QAAiBC;KAAoB;AACpE"}
|
|
1
|
+
{"version":3,"file":"features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.ts"],"sourcesContent":["import { createImplementation, Result } from \"@webiny/feature/api\";\nimport {\n type IUpdateEntryDataFactory,\n UpdateEntryDataFactory as FactoryAbstraction\n} from \"./abstractions.js\";\nimport { CmsContext } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type {\n CmsEntry,\n CmsEntryStatus,\n CmsEntryValues,\n CmsModel,\n UpdateCmsEntryInput,\n UpdateCmsEntryOptionsInput\n} from \"~/types/index.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport { validateModelEntryData } from \"~/crud/contentEntry/entryDataValidation.js\";\nimport { EntryValidationError } from \"~/domain/contentEntry/errors.js\";\nimport { referenceFieldsMapping } from \"~/crud/contentEntry/referenceFieldsMapping.js\";\nimport { mapAndCleanUpdatedInputData } from \"../mapAndCleanUpdatedInputData.js\";\nimport { getSystem } from \"../system.js\";\nimport { getExpiresAt } from \"../expiresAt.js\";\nimport { ModelToAstConverter } from \"~/features/contentModel/ModelToAstConverter/abstractions.js\";\nimport { ensureItemIds } from \"../../ensureItemIds.js\";\nimport { hasEntryContentChanged } from \"../hasEntryContentChanged.js\";\nimport { GetLatestRevisionByEntryIdUseCase } from \"~/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\n\nconst allowedEntryStatus: string[] = [\"draft\", \"published\", \"unpublished\"];\n\nconst transformEntryStatus = (status: CmsEntryStatus | string): CmsEntryStatus => {\n return allowedEntryStatus.includes(status) ? (status as CmsEntryStatus) : \"draft\";\n};\n\nclass UpdateEntryDataFactoryImpl implements IUpdateEntryDataFactory {\n public constructor(\n private readonly cmsContext: CmsContext.Interface,\n private readonly identityContext: IdentityContext.Interface,\n private readonly modelToAstConverter: ModelToAstConverter.Interface,\n private readonly getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface\n ) {}\n\n public async create<TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n rawInput: UpdateCmsEntryInput<TValues>,\n originalEntry: CmsEntry<TValues>,\n options?: UpdateCmsEntryOptionsInput\n ): Promise<FactoryAbstraction.Return<TValues>> {\n const latestResult = await this.getLatestRevision.execute<TValues>(model, {\n id: originalEntry.entryId\n });\n if (latestResult.isFail()) {\n return Result.fail(latestResult.error);\n }\n const latestEntry = latestResult.value;\n\n const cleanedValues = mapAndCleanUpdatedInputData<TValues>(\n model,\n rawInput?.values || ({} as TValues)\n );\n\n const invalidFields = await validateModelEntryData({\n context: this.cmsContext,\n model,\n values: cleanedValues,\n entry: originalEntry,\n skipValidation: options?.skipValidation\n });\n if (invalidFields.length > 0) {\n return Result.fail(new EntryValidationError(\"Validation failed.\", invalidFields));\n }\n\n const mergedValues: TValues = {\n ...originalEntry.values,\n ...cleanedValues\n };\n\n const modelAst = this.modelToAstConverter.toAst(model);\n await ensureItemIds(modelAst, mergedValues);\n\n const values = await referenceFieldsMapping<TValues>({\n context: this.cmsContext,\n model,\n values: mergedValues,\n validateEntries: false\n });\n\n const currentIdentity = this.identityContext.getIdentity();\n const currentDateTime = new Date();\n\n /**\n * Saving without changing the content (e.g. clicking \"Save\" without editing anything) is\n * not a modification, so the saved/modified meta fields are kept. Entry-level values are\n * then taken from the latest revision, because storage copies them onto the latest\n * revision when a non-latest revision is updated. Revision-level values are this\n * revision's own. Explicitly provided meta field values always take precedence.\n */\n const contentChanged = hasEntryContentChanged({\n values,\n baselineValues: originalEntry.values\n });\n\n const entryLevelSaved = contentChanged\n ? {\n savedOn: currentDateTime,\n modifiedOn: currentDateTime,\n savedBy: currentIdentity,\n modifiedBy: currentIdentity\n }\n : {\n savedOn: latestEntry.savedOn,\n modifiedOn: latestEntry.modifiedOn,\n savedBy: latestEntry.savedBy,\n modifiedBy: latestEntry.modifiedBy\n };\n\n const revisionLevelSaved = contentChanged\n ? {\n revisionSavedOn: currentDateTime,\n revisionModifiedOn: currentDateTime,\n revisionSavedBy: currentIdentity,\n revisionModifiedBy: currentIdentity\n }\n : {\n revisionSavedOn: originalEntry.revisionSavedOn,\n revisionModifiedOn: originalEntry.revisionModifiedOn,\n revisionSavedBy: originalEntry.revisionSavedBy,\n revisionModifiedBy: originalEntry.revisionModifiedBy\n };\n\n const entry: CmsEntry<TValues> = {\n ...originalEntry,\n revisionCreatedOn: getDate(rawInput.revisionCreatedOn, originalEntry.revisionCreatedOn),\n revisionModifiedOn: getDate(\n rawInput.revisionModifiedOn,\n revisionLevelSaved.revisionModifiedOn\n ),\n revisionSavedOn: getDate(rawInput.revisionSavedOn, revisionLevelSaved.revisionSavedOn),\n revisionDeletedOn: getDate(rawInput.revisionDeletedOn, originalEntry.revisionDeletedOn),\n revisionRestoredOn: getDate(\n rawInput.revisionRestoredOn,\n originalEntry.revisionRestoredOn\n ),\n revisionFirstPublishedOn: getDate(\n rawInput.revisionFirstPublishedOn,\n originalEntry.revisionFirstPublishedOn\n ),\n revisionLastPublishedOn: getDate(\n rawInput.revisionLastPublishedOn,\n originalEntry.revisionLastPublishedOn\n ),\n revisionCreatedBy: getIdentity(\n rawInput.revisionCreatedBy,\n originalEntry.revisionCreatedBy\n )!,\n revisionModifiedBy: getIdentity(\n rawInput.revisionModifiedBy,\n revisionLevelSaved.revisionModifiedBy\n ),\n revisionSavedBy: getIdentity(\n rawInput.revisionSavedBy,\n revisionLevelSaved.revisionSavedBy\n )!,\n revisionDeletedBy: getIdentity(\n rawInput.revisionDeletedBy,\n originalEntry.revisionDeletedBy\n ),\n revisionRestoredBy: getIdentity(\n rawInput.revisionRestoredBy,\n originalEntry.revisionRestoredBy\n ),\n revisionFirstPublishedBy: getIdentity(\n rawInput.revisionFirstPublishedBy,\n originalEntry.revisionFirstPublishedBy\n ),\n revisionLastPublishedBy: getIdentity(\n rawInput.revisionLastPublishedBy,\n originalEntry.revisionLastPublishedBy\n ),\n createdOn: getDate(rawInput.createdOn, latestEntry.createdOn),\n savedOn: getDate(rawInput.savedOn, entryLevelSaved.savedOn),\n modifiedOn: getDate(rawInput.modifiedOn, entryLevelSaved.modifiedOn),\n deletedOn: getDate(rawInput.deletedOn, latestEntry.deletedOn),\n restoredOn: getDate(rawInput.restoredOn, latestEntry.restoredOn),\n firstPublishedOn: getDate(rawInput.firstPublishedOn, latestEntry.firstPublishedOn),\n lastPublishedOn: getDate(rawInput.lastPublishedOn, latestEntry.lastPublishedOn),\n createdBy: getIdentity(rawInput.createdBy, latestEntry.createdBy)!,\n savedBy: getIdentity(rawInput.savedBy, entryLevelSaved.savedBy)!,\n modifiedBy: getIdentity(rawInput.modifiedBy, entryLevelSaved.modifiedBy),\n deletedBy: getIdentity(rawInput.deletedBy, latestEntry.deletedBy),\n restoredBy: getIdentity(rawInput.restoredBy, latestEntry.restoredBy),\n firstPublishedBy: getIdentity(rawInput.firstPublishedBy, latestEntry.firstPublishedBy),\n lastPublishedBy: getIdentity(rawInput.lastPublishedBy, latestEntry.lastPublishedBy),\n values,\n status: transformEntryStatus(originalEntry.status),\n system: getSystem({\n input: rawInput,\n original: originalEntry\n }),\n live: originalEntry.live,\n expiresAt: getExpiresAt({ expiresAt: rawInput.expiresAt }, originalEntry)\n };\n\n const folderId = rawInput.wbyAco_location?.folderId;\n if (folderId) {\n entry.location = {\n folderId\n };\n }\n\n return Result.ok({\n entry,\n input: {\n ...rawInput,\n values: structuredClone(values)\n }\n });\n }\n}\n\nexport const UpdateEntryDataFactory = createImplementation({\n abstraction: FactoryAbstraction,\n implementation: UpdateEntryDataFactoryImpl,\n dependencies: [\n CmsContext,\n IdentityContext,\n ModelToAstConverter,\n GetLatestRevisionByEntryIdUseCase\n ]\n});\n"],"names":["allowedEntryStatus","transformEntryStatus","status","UpdateEntryDataFactoryImpl","cmsContext","identityContext","modelToAstConverter","getLatestRevision","model","rawInput","originalEntry","options","latestResult","Result","latestEntry","cleanedValues","mapAndCleanUpdatedInputData","invalidFields","validateModelEntryData","EntryValidationError","mergedValues","modelAst","ensureItemIds","values","referenceFieldsMapping","currentIdentity","currentDateTime","Date","contentChanged","hasEntryContentChanged","entryLevelSaved","revisionLevelSaved","entry","getDate","getIdentity","getSystem","getExpiresAt","folderId","structuredClone","UpdateEntryDataFactory","createImplementation","FactoryAbstraction","CmsContext","IdentityContext","ModelToAstConverter","GetLatestRevisionByEntryIdUseCase"],"mappings":";;;;;;;;;;;;;;;;AA4BA,MAAMA,qBAA+B;IAAC;IAAS;IAAa;CAAc;AAE1E,MAAMC,uBAAuB,CAACC,SACnBF,mBAAmB,QAAQ,CAACE,UAAWA,SAA4B;AAG9E,MAAMC;IACF,YACqBC,UAAgC,EAChCC,eAA0C,EAC1CC,mBAAkD,EAClDC,iBAA8D,CACjF;aAJmBH,UAAU,GAAVA;aACAC,eAAe,GAAfA;aACAC,mBAAmB,GAAnBA;aACAC,iBAAiB,GAAjBA;IAClB;IAEH,MAAa,OACTC,KAAe,EACfC,QAAsC,EACtCC,aAAgC,EAChCC,OAAoC,EACO;QAC3C,MAAMC,eAAe,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAUJ,OAAO;YACtE,IAAIE,cAAc,OAAO;QAC7B;QACA,IAAIE,aAAa,MAAM,IACnB,OAAOC,OAAO,IAAI,CAACD,aAAa,KAAK;QAEzC,MAAME,cAAcF,aAAa,KAAK;QAEtC,MAAMG,gBAAgBC,4BAClBR,OACAC,UAAU,UAAW,CAAC;QAG1B,MAAMQ,gBAAgB,MAAMC,uBAAuB;YAC/C,SAAS,IAAI,CAAC,UAAU;YACxBV;YACA,QAAQO;YACR,OAAOL;YACP,gBAAgBC,SAAS;QAC7B;QACA,IAAIM,cAAc,MAAM,GAAG,GACvB,OAAOJ,OAAO,IAAI,CAAC,IAAIM,qBAAqB,sBAAsBF;QAGtE,MAAMG,eAAwB;YAC1B,GAAGV,cAAc,MAAM;YACvB,GAAGK,aAAa;QACpB;QAEA,MAAMM,WAAW,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAACb;QAChD,MAAMc,cAAcD,UAAUD;QAE9B,MAAMG,SAAS,MAAMC,uBAAgC;YACjD,SAAS,IAAI,CAAC,UAAU;YACxBhB;YACA,QAAQY;YACR,iBAAiB;QACrB;QAEA,MAAMK,kBAAkB,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B,WAAW5B,SAAS,eAAe,EAAE;QAC3C,IAAI4B,UACAL,MAAM,QAAQ,GAAG;YACbK;QACJ;QAGJ,OAAOxB,OAAO,EAAE,CAAC;YACbmB;YACA,OAAO;gBACH,GAAGvB,QAAQ;gBACX,QAAQ6B,gBAAgBf;YAC5B;QACJ;IACJ;AACJ;AAEO,MAAMgB,gDAAyBC,qBAAqB;IACvD,aAAaC;IACb,gBAAgBtC;IAChB,cAAc;QACVuC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -1,13 +1,27 @@
|
|
|
1
|
+
import { type Result } from "@webiny/feature/api";
|
|
2
|
+
import type { GetLatestRevisionByEntryIdUseCase } from "../../../../features/contentEntry/GetLatestRevisionByEntryId/index.js";
|
|
3
|
+
import type { EntryValidationError } from "../../../../domain/contentEntry/errors.js";
|
|
1
4
|
import type { CmsEntry, CmsEntryValues, CmsModel, UpdateCmsEntryInput, UpdateCmsEntryOptionsInput } from "../../../../types/index.js";
|
|
2
5
|
export interface IUpdateEntryDataResponse<TValues extends CmsEntryValues = CmsEntryValues> {
|
|
3
6
|
entry: CmsEntry<TValues>;
|
|
4
7
|
input: UpdateCmsEntryInput<TValues>;
|
|
5
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Expected failures of building the data of an entry being updated.
|
|
11
|
+
*/
|
|
12
|
+
export interface IUpdateEntryDataFactoryErrors {
|
|
13
|
+
latest: GetLatestRevisionByEntryIdUseCase.Error;
|
|
14
|
+
validation: EntryValidationError;
|
|
15
|
+
}
|
|
16
|
+
type FactoryError = IUpdateEntryDataFactoryErrors[keyof IUpdateEntryDataFactoryErrors];
|
|
6
17
|
export interface IUpdateEntryDataFactory {
|
|
7
|
-
create<TValues extends CmsEntryValues = CmsEntryValues>(model: CmsModel, rawInput: UpdateCmsEntryInput<TValues>, originalEntry: CmsEntry<TValues>, options?: UpdateCmsEntryOptionsInput): Promise<IUpdateEntryDataResponse<TValues>>;
|
|
18
|
+
create<TValues extends CmsEntryValues = CmsEntryValues>(model: CmsModel, rawInput: UpdateCmsEntryInput<TValues>, originalEntry: CmsEntry<TValues>, options?: UpdateCmsEntryOptionsInput): Promise<Result<IUpdateEntryDataResponse<TValues>, FactoryError>>;
|
|
8
19
|
}
|
|
9
20
|
export declare const UpdateEntryDataFactory: import("@webiny/di").Abstraction<IUpdateEntryDataFactory>;
|
|
10
21
|
export declare namespace UpdateEntryDataFactory {
|
|
11
22
|
type Interface = IUpdateEntryDataFactory;
|
|
23
|
+
type Error = FactoryError;
|
|
24
|
+
type Return<TValues extends CmsEntryValues = CmsEntryValues> = Result<IUpdateEntryDataResponse<TValues>, FactoryError>;
|
|
12
25
|
type Response<TValues extends CmsEntryValues = CmsEntryValues> = IUpdateEntryDataResponse<TValues>;
|
|
13
26
|
}
|
|
27
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/entryDataFactories/UpdateEntryDataFactory/abstractions.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n UpdateCmsEntryInput,\n UpdateCmsEntryOptionsInput\n} from \"~/types/index.js\";\n\nexport interface IUpdateEntryDataResponse<TValues extends CmsEntryValues = CmsEntryValues> {\n entry: CmsEntry<TValues>;\n input: UpdateCmsEntryInput<TValues>;\n}\n\nexport interface IUpdateEntryDataFactory {\n create<TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n rawInput: UpdateCmsEntryInput<TValues>,\n originalEntry: CmsEntry<TValues>,\n options?: UpdateCmsEntryOptionsInput\n ): Promise<IUpdateEntryDataResponse<TValues>>;\n}\n\nexport const UpdateEntryDataFactory = createAbstraction<IUpdateEntryDataFactory>(\n \"Cms/Entry/UpdateEntryDataFactory\"\n);\n\nexport namespace UpdateEntryDataFactory {\n export type Interface = IUpdateEntryDataFactory;\n export type Response<TValues extends CmsEntryValues = CmsEntryValues> =\n IUpdateEntryDataResponse<TValues>;\n}\n"],"names":["UpdateEntryDataFactory","createAbstraction"],"mappings":";
|
|
1
|
+
{"version":3,"file":"features/contentEntry/entryDataFactories/UpdateEntryDataFactory/abstractions.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/abstractions.ts"],"sourcesContent":["import { createAbstraction, type Result } from \"@webiny/feature/api\";\nimport type { GetLatestRevisionByEntryIdUseCase } from \"~/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\nimport type { EntryValidationError } from \"~/domain/contentEntry/errors.js\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n UpdateCmsEntryInput,\n UpdateCmsEntryOptionsInput\n} from \"~/types/index.js\";\n\nexport interface IUpdateEntryDataResponse<TValues extends CmsEntryValues = CmsEntryValues> {\n entry: CmsEntry<TValues>;\n input: UpdateCmsEntryInput<TValues>;\n}\n\n/**\n * Expected failures of building the data of an entry being updated.\n */\nexport interface IUpdateEntryDataFactoryErrors {\n latest: GetLatestRevisionByEntryIdUseCase.Error;\n validation: EntryValidationError;\n}\n\ntype FactoryError = IUpdateEntryDataFactoryErrors[keyof IUpdateEntryDataFactoryErrors];\n\nexport interface IUpdateEntryDataFactory {\n create<TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n rawInput: UpdateCmsEntryInput<TValues>,\n originalEntry: CmsEntry<TValues>,\n options?: UpdateCmsEntryOptionsInput\n ): Promise<Result<IUpdateEntryDataResponse<TValues>, FactoryError>>;\n}\n\nexport const UpdateEntryDataFactory = createAbstraction<IUpdateEntryDataFactory>(\n \"Cms/Entry/UpdateEntryDataFactory\"\n);\n\nexport namespace UpdateEntryDataFactory {\n export type Interface = IUpdateEntryDataFactory;\n export type Error = FactoryError;\n export type Return<TValues extends CmsEntryValues = CmsEntryValues> = Result<\n IUpdateEntryDataResponse<TValues>,\n FactoryError\n >;\n export type Response<TValues extends CmsEntryValues = CmsEntryValues> =\n IUpdateEntryDataResponse<TValues>;\n}\n"],"names":["UpdateEntryDataFactory","createAbstraction"],"mappings":";AAmCO,MAAMA,yBAAyBC,kBAClC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const getExpiresAt = (input, original)=>{
|
|
2
2
|
if (void 0 === input.expiresAt) return original?.expiresAt ?? null;
|
|
3
|
-
if (input.expiresAt instanceof Date) return input.expiresAt.getTime() / 1000;
|
|
4
|
-
if ("number" == typeof input.expiresAt && !isNaN(input.expiresAt) && input.expiresAt > 0) return input.expiresAt;
|
|
3
|
+
else if (input.expiresAt instanceof Date) return input.expiresAt.getTime() / 1000;
|
|
4
|
+
else if ("number" == typeof input.expiresAt && !isNaN(input.expiresAt) && input.expiresAt > 0) return input.expiresAt;
|
|
5
5
|
return null;
|
|
6
6
|
};
|
|
7
7
|
export { getExpiresAt };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/entryDataFactories/expiresAt.js","sources":["../../../../src/features/contentEntry/entryDataFactories/expiresAt.ts"],"sourcesContent":["import type { CmsEntry } from \"~/types/index.js\";\n\nexport interface IRawInput {\n expiresAt: Date | number | null | undefined;\n}\n\nexport const getExpiresAt = (input: IRawInput, original?: CmsEntry): number | null => {\n if (input.expiresAt === undefined) {\n return original?.expiresAt ?? null;\n } else if (input.expiresAt instanceof Date) {\n return input.expiresAt.getTime() / 1000;\n } else if (\n typeof input.expiresAt === \"number\" &&\n !isNaN(input.expiresAt) &&\n input.expiresAt > 0\n ) {\n return input.expiresAt;\n }\n return null;\n};\n"],"names":["getExpiresAt","input","original","undefined","Date","isNaN"],"mappings":"AAMO,MAAMA,eAAe,CAACC,OAAkBC;IAC3C,IAAID,AAAoBE,WAApBF,MAAM,SAAS,EACf,OAAOC,UAAU,aAAa;
|
|
1
|
+
{"version":3,"file":"features/contentEntry/entryDataFactories/expiresAt.js","sources":["../../../../src/features/contentEntry/entryDataFactories/expiresAt.ts"],"sourcesContent":["import type { CmsEntry } from \"~/types/index.js\";\n\nexport interface IRawInput {\n expiresAt: Date | number | null | undefined;\n}\n\nexport const getExpiresAt = (input: IRawInput, original?: CmsEntry): number | null => {\n if (input.expiresAt === undefined) {\n return original?.expiresAt ?? null;\n } else if (input.expiresAt instanceof Date) {\n return input.expiresAt.getTime() / 1000;\n } else if (\n typeof input.expiresAt === \"number\" &&\n !isNaN(input.expiresAt) &&\n input.expiresAt > 0\n ) {\n return input.expiresAt;\n }\n return null;\n};\n"],"names":["getExpiresAt","input","original","undefined","Date","isNaN"],"mappings":"AAMO,MAAMA,eAAe,CAACC,OAAkBC;IAC3C,IAAID,AAAoBE,WAApBF,MAAM,SAAS,EACf,OAAOC,UAAU,aAAa;SAC3B,IAAID,MAAM,SAAS,YAAYG,MAClC,OAAOH,MAAM,SAAS,CAAC,OAAO,KAAK;SAChC,IACH,AAA2B,YAA3B,OAAOA,MAAM,SAAS,IACtB,CAACI,MAAMJ,MAAM,SAAS,KACtBA,MAAM,SAAS,GAAG,GAElB,OAAOA,MAAM,SAAS;IAE1B,OAAO;AACX"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CmsEntryValues } from "../../../types/index.js";
|
|
2
|
+
export interface IHasEntryContentChangedParams<TValues extends CmsEntryValues = CmsEntryValues> {
|
|
3
|
+
/**
|
|
4
|
+
* The values as they will be stored (normalized).
|
|
5
|
+
*/
|
|
6
|
+
values: TValues;
|
|
7
|
+
/**
|
|
8
|
+
* The values to compare against, as currently stored.
|
|
9
|
+
*/
|
|
10
|
+
baselineValues: TValues;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Decides whether saving `values` changes the content of an entry. Used to keep the
|
|
14
|
+
* saved/modified meta fields untouched when an entry is saved without actual changes, e.g. when
|
|
15
|
+
* the "Save" button is clicked without editing anything.
|
|
16
|
+
*
|
|
17
|
+
* Only the content counts: moving an entry to another folder is not a content change, the same
|
|
18
|
+
* as with the dedicated move operation.
|
|
19
|
+
*
|
|
20
|
+
* Values must already be normalized the same way as the stored ones (item IDs assigned, reference
|
|
21
|
+
* fields mapped). A value that does not normalize identically is treated as a change, which only
|
|
22
|
+
* means the meta fields get updated, exactly as they did before this check existed.
|
|
23
|
+
*/
|
|
24
|
+
export declare const hasEntryContentChanged: <TValues extends CmsEntryValues = CmsEntryValues>(params: IHasEntryContentChangedParams<TValues>) => boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import isEqual from "lodash/isEqual.js";
|
|
2
|
+
const withoutEmptyKeys = (value)=>{
|
|
3
|
+
if (Array.isArray(value)) return value.map(withoutEmptyKeys);
|
|
4
|
+
if (null === value || "object" != typeof value || value instanceof Date) return value;
|
|
5
|
+
return Object.entries(value).reduce((result, [key, item])=>{
|
|
6
|
+
if (null != item) result[key] = withoutEmptyKeys(item);
|
|
7
|
+
return result;
|
|
8
|
+
}, {});
|
|
9
|
+
};
|
|
10
|
+
const hasEntryContentChanged = (params)=>!isEqual(withoutEmptyKeys(params.values), withoutEmptyKeys(params.baselineValues));
|
|
11
|
+
export { hasEntryContentChanged };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=hasEntryContentChanged.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/contentEntry/entryDataFactories/hasEntryContentChanged.js","sources":["../../../../src/features/contentEntry/entryDataFactories/hasEntryContentChanged.ts"],"sourcesContent":["import lodashIsEqual from \"lodash/isEqual.js\";\nimport type { CmsEntryValues } from \"~/types/index.js\";\n\n/**\n * Removes object keys with `null` or `undefined` values, recursively, so that a field that was\n * never set and a field that is explicitly empty compare as equal.\n */\nconst withoutEmptyKeys = (value: unknown): unknown => {\n if (Array.isArray(value)) {\n return value.map(withoutEmptyKeys);\n }\n if (value === null || typeof value !== \"object\" || value instanceof Date) {\n return value;\n }\n return Object.entries(value).reduce<Record<string, unknown>>((result, [key, item]) => {\n if (item !== null && item !== undefined) {\n result[key] = withoutEmptyKeys(item);\n }\n return result;\n }, {});\n};\n\nexport interface IHasEntryContentChangedParams<TValues extends CmsEntryValues = CmsEntryValues> {\n /**\n * The values as they will be stored (normalized).\n */\n values: TValues;\n /**\n * The values to compare against, as currently stored.\n */\n baselineValues: TValues;\n}\n\n/**\n * Decides whether saving `values` changes the content of an entry. Used to keep the\n * saved/modified meta fields untouched when an entry is saved without actual changes, e.g. when\n * the \"Save\" button is clicked without editing anything.\n *\n * Only the content counts: moving an entry to another folder is not a content change, the same\n * as with the dedicated move operation.\n *\n * Values must already be normalized the same way as the stored ones (item IDs assigned, reference\n * fields mapped). A value that does not normalize identically is treated as a change, which only\n * means the meta fields get updated, exactly as they did before this check existed.\n */\nexport const hasEntryContentChanged = <TValues extends CmsEntryValues = CmsEntryValues>(\n params: IHasEntryContentChangedParams<TValues>\n): boolean => {\n return !lodashIsEqual(withoutEmptyKeys(params.values), withoutEmptyKeys(params.baselineValues));\n};\n"],"names":["withoutEmptyKeys","value","Array","Date","Object","result","key","item","hasEntryContentChanged","params","lodashIsEqual"],"mappings":";AAOA,MAAMA,mBAAmB,CAACC;IACtB,IAAIC,MAAM,OAAO,CAACD,QACd,OAAOA,MAAM,GAAG,CAACD;IAErB,IAAIC,AAAU,SAAVA,SAAkB,AAAiB,YAAjB,OAAOA,SAAsBA,iBAAiBE,MAChE,OAAOF;IAEX,OAAOG,OAAO,OAAO,CAACH,OAAO,MAAM,CAA0B,CAACI,QAAQ,CAACC,KAAKC,KAAK;QAC7E,IAAIA,QAAAA,MACAF,MAAM,CAACC,IAAI,GAAGN,iBAAiBO;QAEnC,OAAOF;IACX,GAAG,CAAC;AACR;AAyBO,MAAMG,yBAAyB,CAClCC,SAEO,CAACC,QAAcV,iBAAiBS,OAAO,MAAM,GAAGT,iBAAiBS,OAAO,cAAc"}
|
|
@@ -21,8 +21,7 @@ const getModelId = (model)=>{
|
|
|
21
21
|
const isModelIdValid = camelCase(value).toLowerCase() === value.toLowerCase();
|
|
22
22
|
if (isModelIdValid) return value;
|
|
23
23
|
return camelCase(value);
|
|
24
|
-
}
|
|
25
|
-
if (name) return camelCase(name.trim());
|
|
24
|
+
} else if (name) return camelCase(name.trim());
|
|
26
25
|
throw new ModelValidationError('There is no "modelId" or "name" passed into the create model method.');
|
|
27
26
|
};
|
|
28
27
|
class CreateModelRepositoryImpl {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentModel/CreateModel/CreateModelRepository.js","sources":["../../../../src/features/contentModel/CreateModel/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\";\nimport { RuntimeTenant } from \"~/features/runtimeTenant/abstractions.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 private readonly runtimeTenant: RuntimeTenant.Interface\n ) {}\n\n async execute(initialModel: CmsModel): Promise<Result<CmsModel, RepositoryAbstraction.Error>> {\n const model = this.runtimeTenant.assign(initialModel);\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(model);\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 RuntimeTenant\n ]\n});\n"],"names":["getModelId","model","modelId","name","value","isModelIdValid","camelCase","ModelValidationError","CreateModelRepositoryImpl","modelCache","pluginModelsProvider","listModelsUseCase","storageOperations","tenantContext","cmsContext","modelFieldCompression","runtimeTenant","initialModel","tenant","validateModelIdAllowed","error","Result","validateEndingAllowed","pluginModels","pluginModelConflict","pm","ModelAlreadyExistsError","modelsResult","ModelPersistenceError","models","existingModel","validateExistingModelId","validateSingularApiName","validatePluralApiName","validateModelFields","ensureTypeTag","fields","console","CreateModelRepository","RepositoryAbstraction","ModelCache","PluginModelsProvider","ListModelsUseCase","StorageOperations","TenantContext","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E,OAAOmB,OAAO;YACZiB,QAAQ,KAAK,CAACjB,OAAOA,MAAM,KAAK;YAChC,OAAOC,OAAO,IAAI,CAAC,IAAIO,sBAAsBR;QACjD;IACJ;AACJ;AAEO,MAAMkB,8CAAwBC,sBAAAA,oBAA0C,CAAC;IAC5E,gBAAgB/B;IAChB,cAAc;QACVgC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
1
|
+
{"version":3,"file":"features/contentModel/CreateModel/CreateModelRepository.js","sources":["../../../../src/features/contentModel/CreateModel/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\";\nimport { RuntimeTenant } from \"~/features/runtimeTenant/abstractions.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 private readonly runtimeTenant: RuntimeTenant.Interface\n ) {}\n\n async execute(initialModel: CmsModel): Promise<Result<CmsModel, RepositoryAbstraction.Error>> {\n const model = this.runtimeTenant.assign(initialModel);\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(model);\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 RuntimeTenant\n ]\n});\n"],"names":["getModelId","model","modelId","name","value","isModelIdValid","camelCase","ModelValidationError","CreateModelRepositoryImpl","modelCache","pluginModelsProvider","listModelsUseCase","storageOperations","tenantContext","cmsContext","modelFieldCompression","runtimeTenant","initialModel","tenant","validateModelIdAllowed","error","Result","validateEndingAllowed","pluginModels","pluginModelConflict","pm","ModelAlreadyExistsError","modelsResult","ModelPersistenceError","models","existingModel","validateExistingModelId","validateSingularApiName","validatePluralApiName","validateModelFields","ensureTypeTag","fields","console","CreateModelRepository","RepositoryAbstraction","ModelCache","PluginModelsProvider","ListModelsUseCase","StorageOperations","TenantContext","CmsContext","ModelFieldCompression","RuntimeTenant"],"mappings":";;;;;;;;;;;;;;;;AA4BA,MAAMA,aAAa,CAACC;IAChB,MAAM,EAAEC,OAAO,EAAEC,IAAI,EAAE,GAAGF;IAC1B,MAAMG,QAAQF,UAAUA,QAAQ,IAAI,KAAK;IACzC,IAAIE,OAAO;QACP,MAAMC,iBAAiBC,UAAUF,OAAO,WAAW,OAAOA,MAAM,WAAW;QAC3E,IAAIC,gBACA,OAAOD;QAEX,OAAOE,UAAUF;IACrB,OAAO,IAAID,MACP,OAAOG,UAAUH,KAAK,IAAI;IAE9B,MAAM,IAAII,qBACN;AAER;AAgBA,MAAMC;IACF,YACqBC,UAAgC,EAChCC,oBAAoD,EACpDC,iBAA8C,EAC9CC,iBAA8C,EAC9CC,aAAsC,EACtCC,UAAgC,EAChCC,qBAAsD,EACtDC,aAAsC,CACzD;aARmBP,UAAU,GAAVA;aACAC,oBAAoB,GAApBA;aACAC,iBAAiB,GAAjBA;aACAC,iBAAiB,GAAjBA;aACAC,aAAa,GAAbA;aACAC,UAAU,GAAVA;aACAC,qBAAqB,GAArBA;aACAC,aAAa,GAAbA;IAClB;IAEH,MAAM,QAAQC,YAAsB,EAA0D;QAC1F,MAAMhB,QAAQ,IAAI,CAAC,aAAa,CAAC,MAAM,CAACgB;QACxC,IAAI;YACA,MAAMC,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;YAG3C,MAAMhB,UAAUF,WAAWC;YAC3BA,MAAM,OAAO,GAAGC;YAGhB,IAAI;gBACAiB,uBAAuB;oBAAElB;gBAAM;YACnC,EAAE,OAAOmB,OAAO;gBACZ,OAAOC,OAAO,IAAI,CACd,IAAId,qBAAqB;oBACrB,SAASa,MAAM,OAAO;oBACtB,MAAMA,MAAM,IAAI;gBACpB;YAER;YAGA,IAAI;gBACAE,sBAAsB;oBAAErB;gBAAM;YAClC,E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AGA,IAAI,CAAC,UAAU,CAAC,KAAK;YAErB,OAAOf,OAAO,EAAE,CAACpB;QACrB,EAAE,OAAOmB,OAAO;YACZiB,QAAQ,KAAK,CAACjB,OAAOA,MAAM,KAAK;YAChC,OAAOC,OAAO,IAAI,CAAC,IAAIO,sBAAsBR;QACjD;IACJ;AACJ;AAEO,MAAMkB,8CAAwBC,sBAAAA,oBAA0C,CAAC;IAC5E,gBAAgB/B;IAChB,cAAc;QACVgC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -20,8 +20,7 @@ const getModelId = (model)=>{
|
|
|
20
20
|
const isModelIdValid = camelCase(value).toLowerCase() === value.toLowerCase();
|
|
21
21
|
if (isModelIdValid) return value;
|
|
22
22
|
return camelCase(value);
|
|
23
|
-
}
|
|
24
|
-
if (name) return camelCase(name.trim());
|
|
23
|
+
} else if (name) return camelCase(name.trim());
|
|
25
24
|
throw new ModelValidationError('There is no "modelId" or "name" passed into the create model from method.');
|
|
26
25
|
};
|
|
27
26
|
class CreateModelFromRepositoryImpl {
|