@webiny/api-headless-cms 6.5.0-beta.0 → 6.5.0-beta.1
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/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromUseCase.d.ts +1 -3
- package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromUseCase.js +4 -12
- 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/PublishEntry/PublishEntryUseCase.d.ts +1 -3
- package/features/contentEntry/PublishEntry/PublishEntryUseCase.js +4 -10
- package/features/contentEntry/PublishEntry/PublishEntryUseCase.js.map +1 -1
- package/features/contentEntry/RepublishEntry/RepublishEntryUseCase.js +3 -1
- package/features/contentEntry/RepublishEntry/RepublishEntryUseCase.js.map +1 -1
- package/features/contentEntry/UnpublishEntry/UnpublishEntryUseCase.js +3 -1
- package/features/contentEntry/UnpublishEntry/UnpublishEntryUseCase.js.map +1 -1
- package/features/contentEntry/UpdateEntry/UpdateEntryUseCase.js +3 -1
- package/features/contentEntry/UpdateEntry/UpdateEntryUseCase.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/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/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/package.json +18 -18
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","C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AAS,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,M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,YAAY,SAAS;YAChE,SAASoB,YAAYzB,SAAS,OAAO,EAAEqB,gBAAgB,OAAO;YAC9D,YAAYI,YAAYzB,SAAS,UAAU,EAAEqB,gBAAgB,UAAU;YACvE,WAAWI,YAAYzB,SAAS,SAAS,EAAEK,YAAY,SAAS;YAChE,YAAYoB,YAAYzB,SAAS,UAAU,EAAEK,YAAY,UAAU;YACnE,kBAAkBoB,YAAYzB,SAAS,gBAAgB,EAAEK,YAAY,gBAAgB;YACrF,iBAAiBoB,YAAYzB,SAAS,eAAe,EAAEK,YAAY,eAAe;YAClFS;YACA,QAAQtB,qBAAqBS,cAAc,MAAM;YACjD,QAAQyB,UAAU;gBACd,OAAO1B;gBACP,UAAUC;YACd;YACA,MAAMA,cAAc,IAAI;YACxB,WAAW0B,aAAa;gBAAE,WAAW3B,SAAS,SAAS;YAAC,GAAGC;QAC/D;QAEA,MAAM2B,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"}
|
|
@@ -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"}
|
|
@@ -2,7 +2,7 @@ import { ValuesSelectionGenerator } from "./abstractions.js";
|
|
|
2
2
|
import { ModelToAstConverter } from "../ModelToAstConverter/abstractions.js";
|
|
3
3
|
import { createTypeName } from "../../../utils/createTypeName.js";
|
|
4
4
|
const REF_SELECTION = "{ id modelId }";
|
|
5
|
-
const ASSET_SELECTION = "{ id src url name
|
|
5
|
+
const ASSET_SELECTION = "{ id src url name mimeType size width height image { width height crop { top left bottom right } focalPoint { x y } alt caption } document { pages } video { autoplay poster } }";
|
|
6
6
|
class ValuesSelectionGeneratorImpl {
|
|
7
7
|
constructor(modelToAst){
|
|
8
8
|
this.modelToAst = modelToAst;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentModel/ValuesSelectionGenerator/ValuesSelectionGenerator.js","sources":["../../../../src/features/contentModel/ValuesSelectionGenerator/ValuesSelectionGenerator.ts"],"sourcesContent":["import {\n ValuesSelectionGenerator as Abstraction,\n type IValuesSelectionGenerator\n} from \"./abstractions.js\";\nimport { ModelToAstConverter } from \"../ModelToAstConverter/abstractions.js\";\nimport type {\n CmsModel,\n CmsModelAst,\n CmsModelFieldAstNode,\n CmsModelFieldAstNodeCollection,\n CmsModelFieldAstNodeField\n} from \"~/types/index.js\";\nimport { createTypeName } from \"~/utils/createTypeName.js\";\n\nconst REF_SELECTION = \"{ id modelId }\";\n\nconst ASSET_SELECTION = [\n \"{ id src url name
|
|
1
|
+
{"version":3,"file":"features/contentModel/ValuesSelectionGenerator/ValuesSelectionGenerator.js","sources":["../../../../src/features/contentModel/ValuesSelectionGenerator/ValuesSelectionGenerator.ts"],"sourcesContent":["import {\n ValuesSelectionGenerator as Abstraction,\n type IValuesSelectionGenerator\n} from \"./abstractions.js\";\nimport { ModelToAstConverter } from \"../ModelToAstConverter/abstractions.js\";\nimport type {\n CmsModel,\n CmsModelAst,\n CmsModelFieldAstNode,\n CmsModelFieldAstNodeCollection,\n CmsModelFieldAstNodeField\n} from \"~/types/index.js\";\nimport { createTypeName } from \"~/utils/createTypeName.js\";\n\nconst REF_SELECTION = \"{ id modelId }\";\n\nconst ASSET_SELECTION = [\n \"{ id src url name mimeType size width height\",\n \"image { width height crop { top left bottom right } focalPoint { x y } alt caption }\",\n \"document { pages }\",\n \"video { autoplay poster } }\"\n].join(\" \");\n\nclass ValuesSelectionGeneratorImpl implements IValuesSelectionGenerator {\n constructor(private readonly modelToAst: ModelToAstConverter.Interface) {}\n\n generate(model: CmsModel): string {\n const ast = this.modelToAst.toAst(model);\n const selection = this.walkRoot(ast, model.singularApiName);\n return selection || \"_empty\";\n }\n\n private walkRoot(ast: CmsModelAst, typePrefix: string): string {\n return ast.children\n .map(node => this.walkNode(node, typePrefix))\n .filter(Boolean)\n .join(\"\\n\");\n }\n\n private walkNode(node: CmsModelFieldAstNode, typePrefix: string): string | null {\n if (node.type === \"field\") {\n return this.walkFieldNode(node, typePrefix);\n }\n if (node.type === \"collection\") {\n return this.walkCollectionNode(node, typePrefix);\n }\n return null;\n }\n\n private walkFieldNode(node: CmsModelFieldAstNodeField, typePrefix: string): string | null {\n const { field, children } = node;\n\n if (field.type === \"ref\") {\n return `${field.fieldId} ${REF_SELECTION}`;\n }\n\n if (field.type === \"asset\") {\n return `${field.fieldId} ${ASSET_SELECTION}`;\n }\n\n if (children.length === 0) {\n if (field.type === \"object\" || field.type === \"dynamicZone\") {\n return null;\n }\n return field.fieldId;\n }\n\n const nestedPrefix = `${typePrefix}_${createTypeName(field.fieldId)}`;\n const childSelection = children\n .map(child => this.walkNode(child, nestedPrefix))\n .filter(Boolean)\n .join(\"\\n\");\n\n if (!childSelection) {\n return null;\n }\n\n const idSelection = field.type === \"object\" ? \"_id \" : \"\";\n return `${field.fieldId} { ${idSelection}${childSelection} }`;\n }\n\n private walkCollectionNode(\n node: CmsModelFieldAstNodeCollection,\n typePrefix: string\n ): string | null {\n const { collection, children } = node;\n const gqlTypeName = collection.gqlTypeName;\n\n if (!gqlTypeName) {\n return null;\n }\n\n const templateType = `${typePrefix}_${gqlTypeName}`;\n const childSelection = children\n .map(child => this.walkNode(child, templateType))\n .filter(Boolean)\n .join(\"\\n\");\n\n return `...on ${templateType} { ${childSelection} _templateId _id __typename }`;\n }\n}\n\nexport const ValuesSelectionGenerator = Abstraction.createImplementation({\n implementation: ValuesSelectionGeneratorImpl,\n dependencies: [ModelToAstConverter]\n});\n"],"names":["REF_SELECTION","ASSET_SELECTION","ValuesSelectionGeneratorImpl","modelToAst","model","ast","selection","typePrefix","node","Boolean","field","children","nestedPrefix","createTypeName","childSelection","child","idSelection","collection","gqlTypeName","templateType","ValuesSelectionGenerator","Abstraction","ModelToAstConverter"],"mappings":";;;AAcA,MAAMA,gBAAgB;AAEtB,MAAMC,kBAAkB;AAOxB,MAAMC;IACF,YAA6BC,UAAyC,CAAE;aAA3CA,UAAU,GAAVA;IAA4C;IAEzE,SAASC,KAAe,EAAU;QAC9B,MAAMC,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAACD;QAClC,MAAME,YAAY,IAAI,CAAC,QAAQ,CAACD,KAAKD,MAAM,eAAe;QAC1D,OAAOE,aAAa;IACxB;IAEQ,SAASD,GAAgB,EAAEE,UAAkB,EAAU;QAC3D,OAAOF,IAAI,QAAQ,CACd,GAAG,CAACG,CAAAA,OAAQ,IAAI,CAAC,QAAQ,CAACA,MAAMD,aAChC,MAAM,CAACE,SACP,IAAI,CAAC;IACd;IAEQ,SAASD,IAA0B,EAAED,UAAkB,EAAiB;QAC5E,IAAIC,AAAc,YAAdA,KAAK,IAAI,EACT,OAAO,IAAI,CAAC,aAAa,CAACA,MAAMD;QAEpC,IAAIC,AAAc,iBAAdA,KAAK,IAAI,EACT,OAAO,IAAI,CAAC,kBAAkB,CAACA,MAAMD;QAEzC,OAAO;IACX;IAEQ,cAAcC,IAA+B,EAAED,UAAkB,EAAiB;QACtF,MAAM,EAAEG,KAAK,EAAEC,QAAQ,EAAE,GAAGH;QAE5B,IAAIE,AAAe,UAAfA,MAAM,IAAI,EACV,OAAO,GAAGA,MAAM,OAAO,CAAC,CAAC,EAAEV,eAAe;QAG9C,IAAIU,AAAe,YAAfA,MAAM,IAAI,EACV,OAAO,GAAGA,MAAM,OAAO,CAAC,CAAC,EAAET,iBAAiB;QAGhD,IAAIU,AAAoB,MAApBA,SAAS,MAAM,EAAQ;YACvB,IAAID,AAAe,aAAfA,MAAM,IAAI,IAAiBA,AAAe,kBAAfA,MAAM,IAAI,EACrC,OAAO;YAEX,OAAOA,MAAM,OAAO;QACxB;QAEA,MAAME,eAAe,GAAGL,WAAW,CAAC,EAAEM,eAAeH,MAAM,OAAO,GAAG;QACrE,MAAMI,iBAAiBH,SAClB,GAAG,CAACI,CAAAA,QAAS,IAAI,CAAC,QAAQ,CAACA,OAAOH,eAClC,MAAM,CAACH,SACP,IAAI,CAAC;QAEV,IAAI,CAACK,gBACD,OAAO;QAGX,MAAME,cAAcN,AAAe,aAAfA,MAAM,IAAI,GAAgB,SAAS;QACvD,OAAO,GAAGA,MAAM,OAAO,CAAC,GAAG,EAAEM,cAAcF,eAAe,EAAE,CAAC;IACjE;IAEQ,mBACJN,IAAoC,EACpCD,UAAkB,EACL;QACb,MAAM,EAAEU,UAAU,EAAEN,QAAQ,EAAE,GAAGH;QACjC,MAAMU,cAAcD,WAAW,WAAW;QAE1C,IAAI,CAACC,aACD,OAAO;QAGX,MAAMC,eAAe,GAAGZ,WAAW,CAAC,EAAEW,aAAa;QACnD,MAAMJ,iBAAiBH,SAClB,GAAG,CAACI,CAAAA,QAAS,IAAI,CAAC,QAAQ,CAACA,OAAOI,eAClC,MAAM,CAACV,SACP,IAAI,CAAC;QAEV,OAAO,CAAC,MAAM,EAAEU,aAAa,GAAG,EAAEL,eAAe,6BAA6B,CAAC;IACnF;AACJ;AAEO,MAAMM,oDAA2BC,yBAAAA,oBAAgC,CAAC;IACrE,gBAAgBnB;IAChB,cAAc;QAACoB;KAAoB;AACvC"}
|
|
@@ -70,8 +70,11 @@ const baseTypeDefs = `
|
|
|
70
70
|
src: String!
|
|
71
71
|
url: String
|
|
72
72
|
name: String!
|
|
73
|
-
|
|
73
|
+
mimeType: String!
|
|
74
74
|
size: Number!
|
|
75
|
+
# Same as image.width/image.height, kept at the root for 6.4 frontends.
|
|
76
|
+
width: Number
|
|
77
|
+
height: Number
|
|
75
78
|
image: FmAssetImage
|
|
76
79
|
document: FmAssetDocument
|
|
77
80
|
video: FmAssetVideo
|
|
@@ -83,8 +86,10 @@ const baseTypeDefs = `
|
|
|
83
86
|
# TODO: figure out how to remove this from here, as this is a derived read-only value.
|
|
84
87
|
url: String
|
|
85
88
|
name: String!
|
|
86
|
-
|
|
89
|
+
mimeType: String!
|
|
87
90
|
size: Number!
|
|
91
|
+
width: Number
|
|
92
|
+
height: Number
|
|
88
93
|
image: FmAssetImageInput
|
|
89
94
|
document: FmAssetDocumentInput
|
|
90
95
|
video: FmAssetVideoInput
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/graphql/fields/base/AssetToGraphQL.js","sources":["../../../../../src/features/graphql/fields/base/AssetToGraphQL.ts"],"sourcesContent":["import { CmsModelFieldToGraphQL } from \"../abstractions/CmsModelFieldToGraphQL.js\";\nimport type { CmsModelFieldType } from \"~/types/modelField.js\";\nimport type { GraphQLSchemaDefinition } from \"@webiny/handler-graphql/types.js\";\nimport type { CmsContext } from \"~/types/types.js\";\nimport { createGraphQLInputField } from \"./utils/createGraphQLInputField.js\";\nimport { resolveAssetUrl } from \"../../../modelBuilder/fields/resolveAssetUrl.js\";\n\n// --- Image sub-type (self-contained block for future registry extraction) ---\n\nconst imageTypeDefs = /* GraphQL */ `\n type FmAssetCrop {\n top: Number\n left: Number\n bottom: Number\n right: Number\n }\n\n type FmAssetFocalPoint {\n x: Number\n y: Number\n }\n\n type FmAssetImage {\n width: Number\n height: Number\n crop: FmAssetCrop\n focalPoint: FmAssetFocalPoint\n alt: String\n caption: String\n }\n\n input FmAssetCropInput {\n top: Number\n left: Number\n bottom: Number\n right: Number\n }\n\n input FmAssetFocalPointInput {\n x: Number\n y: Number\n }\n\n input FmAssetImageInput {\n width: Number\n height: Number\n crop: FmAssetCropInput\n focalPoint: FmAssetFocalPointInput\n alt: String\n caption: String\n }\n`;\n\n// --- Document sub-type ---\n\nconst documentTypeDefs = /* GraphQL */ `\n type FmAssetDocument {\n pages: Number\n }\n\n input FmAssetDocumentInput {\n pages: Number\n }\n`;\n\n// --- Video sub-type ---\n\nconst videoTypeDefs = /* GraphQL */ `\n type FmAssetVideo {\n autoplay: Boolean\n poster: String\n }\n\n input FmAssetVideoInput {\n autoplay: Boolean\n poster: String\n }\n`;\n\n// --- Base asset type ---\n\nconst baseTypeDefs = /* GraphQL */ `\n type FmAsset {\n id: String!\n src: String!\n url: String\n name: String!\n
|
|
1
|
+
{"version":3,"file":"features/graphql/fields/base/AssetToGraphQL.js","sources":["../../../../../src/features/graphql/fields/base/AssetToGraphQL.ts"],"sourcesContent":["import { CmsModelFieldToGraphQL } from \"../abstractions/CmsModelFieldToGraphQL.js\";\nimport type { CmsModelFieldType } from \"~/types/modelField.js\";\nimport type { GraphQLSchemaDefinition } from \"@webiny/handler-graphql/types.js\";\nimport type { CmsContext } from \"~/types/types.js\";\nimport { createGraphQLInputField } from \"./utils/createGraphQLInputField.js\";\nimport { resolveAssetUrl } from \"../../../modelBuilder/fields/resolveAssetUrl.js\";\n\n// --- Image sub-type (self-contained block for future registry extraction) ---\n\nconst imageTypeDefs = /* GraphQL */ `\n type FmAssetCrop {\n top: Number\n left: Number\n bottom: Number\n right: Number\n }\n\n type FmAssetFocalPoint {\n x: Number\n y: Number\n }\n\n type FmAssetImage {\n width: Number\n height: Number\n crop: FmAssetCrop\n focalPoint: FmAssetFocalPoint\n alt: String\n caption: String\n }\n\n input FmAssetCropInput {\n top: Number\n left: Number\n bottom: Number\n right: Number\n }\n\n input FmAssetFocalPointInput {\n x: Number\n y: Number\n }\n\n input FmAssetImageInput {\n width: Number\n height: Number\n crop: FmAssetCropInput\n focalPoint: FmAssetFocalPointInput\n alt: String\n caption: String\n }\n`;\n\n// --- Document sub-type ---\n\nconst documentTypeDefs = /* GraphQL */ `\n type FmAssetDocument {\n pages: Number\n }\n\n input FmAssetDocumentInput {\n pages: Number\n }\n`;\n\n// --- Video sub-type ---\n\nconst videoTypeDefs = /* GraphQL */ `\n type FmAssetVideo {\n autoplay: Boolean\n poster: String\n }\n\n input FmAssetVideoInput {\n autoplay: Boolean\n poster: String\n }\n`;\n\n// --- Base asset type ---\n\nconst baseTypeDefs = /* GraphQL */ `\n type FmAsset {\n id: String!\n src: String!\n url: String\n name: String!\n mimeType: String!\n size: Number!\n # Same as image.width/image.height, kept at the root for 6.4 frontends.\n width: Number\n height: Number\n image: FmAssetImage\n document: FmAssetDocument\n video: FmAssetVideo\n }\n\n input FmAssetInput {\n id: String!\n src: String!\n # TODO: figure out how to remove this from here, as this is a derived read-only value.\n url: String\n name: String!\n mimeType: String!\n size: Number!\n width: Number\n height: Number\n image: FmAssetImageInput\n document: FmAssetDocumentInput\n video: FmAssetVideoInput\n }\n`;\n\nconst allTypeDefs = [imageTypeDefs, documentTypeDefs, videoTypeDefs, baseTypeDefs].join(\"\\n\");\n\nclass ReadApi implements CmsModelFieldToGraphQL.ReadApi {\n public createTypeField({ field }: CmsModelFieldToGraphQL.TypeFieldParams): string {\n if (field.list) {\n return `${field.fieldId}: [FmAsset]`;\n }\n return `${field.fieldId}: FmAsset`;\n }\n\n public createResolver(): CmsModelFieldToGraphQL.Resolver {\n return {\n resolver: null,\n typeResolvers: {\n FmAsset: {\n url: (parent: any) => resolveAssetUrl(parent)\n }\n }\n };\n }\n\n public createSchema(): GraphQLSchemaDefinition<CmsContext> {\n return {\n typeDefs: allTypeDefs,\n resolvers: {}\n };\n }\n}\n\nclass ManageApi extends ReadApi implements CmsModelFieldToGraphQL.ManageApi {\n public createInputField({ field }: CmsModelFieldToGraphQL.TypeFieldParams): string {\n return createGraphQLInputField(field, \"FmAssetInput\");\n }\n}\n\nclass AssetToGraphQL implements CmsModelFieldToGraphQL.Interface {\n public readonly read = new ReadApi();\n public readonly manage = new ManageApi();\n\n public readonly fieldType: CmsModelFieldType = \"asset\";\n public readonly isSearchable: boolean = false;\n public readonly isSortable: boolean = false;\n public readonly isFullTextSearchable: boolean = false;\n\n public getReadApi(): CmsModelFieldToGraphQL.ReadApi {\n return this.read;\n }\n\n public getManageApi(): CmsModelFieldToGraphQL.ManageApi {\n return this.manage;\n }\n}\n\nexport const AssetFieldToGraphQL = CmsModelFieldToGraphQL.createImplementation({\n implementation: AssetToGraphQL,\n dependencies: []\n});\n"],"names":["imageTypeDefs","documentTypeDefs","videoTypeDefs","baseTypeDefs","allTypeDefs","ReadApi","field","parent","resolveAssetUrl","ManageApi","createGraphQLInputField","AssetToGraphQL","AssetFieldToGraphQL","CmsModelFieldToGraphQL"],"mappings":";;;AASA,MAAMA,gBAA8B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CrC,CAAC;AAID,MAAMC,mBAAiC,CAAC;;;;;;;;AAQxC,CAAC;AAID,MAAMC,gBAA8B,CAAC;;;;;;;;;;AAUrC,CAAC;AAID,MAAMC,eAA6B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BpC,CAAC;AAED,MAAMC,cAAc;IAACJ;IAAeC;IAAkBC;IAAeC;CAAa,CAAC,IAAI,CAAC;AAExF,MAAME;IACK,gBAAgB,EAAEC,KAAK,EAA0C,EAAU;QAC9E,IAAIA,MAAM,IAAI,EACV,OAAO,GAAGA,MAAM,OAAO,CAAC,WAAW,CAAC;QAExC,OAAO,GAAGA,MAAM,OAAO,CAAC,SAAS,CAAC;IACtC;IAEO,iBAAkD;QACrD,OAAO;YACH,UAAU;YACV,eAAe;gBACX,SAAS;oBACL,KAAK,CAACC,SAAgBC,gBAAgBD;gBAC1C;YACJ;QACJ;IACJ;IAEO,eAAoD;QACvD,OAAO;YACH,UAAUH;YACV,WAAW,CAAC;QAChB;IACJ;AACJ;AAEA,MAAMK,kBAAkBJ;IACb,iBAAiB,EAAEC,KAAK,EAA0C,EAAU;QAC/E,OAAOI,wBAAwBJ,OAAO;IAC1C;AACJ;AAEA,MAAMK;IASK,aAA6C;QAChD,OAAO,IAAI,CAAC,IAAI;IACpB;IAEO,eAAiD;QACpD,OAAO,IAAI,CAAC,MAAM;IACtB;;aAdgB,IAAI,GAAG,IAAIN;aACX,MAAM,GAAG,IAAII;aAEb,SAAS,GAAsB;aAC/B,YAAY,GAAY;aACxB,UAAU,GAAY;aACtB,oBAAoB,GAAY;;AASpD;AAEO,MAAMG,sBAAsBC,uBAAuB,oBAAoB,CAAC;IAC3E,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-headless-cms",
|
|
3
|
-
"version": "6.5.0-beta.
|
|
3
|
+
"version": "6.5.0-beta.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -25,19 +25,19 @@
|
|
|
25
25
|
"@babel/code-frame": "8.0.0",
|
|
26
26
|
"@graphql-tools/merge": "9.2.2",
|
|
27
27
|
"@graphql-tools/schema": "10.0.38",
|
|
28
|
-
"@webiny/api": "6.5.0-beta.
|
|
29
|
-
"@webiny/api-core": "6.5.0-beta.
|
|
28
|
+
"@webiny/api": "6.5.0-beta.1",
|
|
29
|
+
"@webiny/api-core": "6.5.0-beta.1",
|
|
30
30
|
"@webiny/di": "1.0.2",
|
|
31
|
-
"@webiny/error": "6.5.0-beta.
|
|
32
|
-
"@webiny/feature": "6.5.0-beta.
|
|
33
|
-
"@webiny/handler": "6.5.0-beta.
|
|
34
|
-
"@webiny/handler-aws": "6.5.0-beta.
|
|
35
|
-
"@webiny/handler-db": "6.5.0-beta.
|
|
36
|
-
"@webiny/handler-graphql": "6.5.0-beta.
|
|
37
|
-
"@webiny/plugins": "6.5.0-beta.
|
|
38
|
-
"@webiny/project": "6.5.0-beta.
|
|
39
|
-
"@webiny/utils": "6.5.0-beta.
|
|
40
|
-
"@webiny/validation": "6.5.0-beta.
|
|
31
|
+
"@webiny/error": "6.5.0-beta.1",
|
|
32
|
+
"@webiny/feature": "6.5.0-beta.1",
|
|
33
|
+
"@webiny/handler": "6.5.0-beta.1",
|
|
34
|
+
"@webiny/handler-aws": "6.5.0-beta.1",
|
|
35
|
+
"@webiny/handler-db": "6.5.0-beta.1",
|
|
36
|
+
"@webiny/handler-graphql": "6.5.0-beta.1",
|
|
37
|
+
"@webiny/plugins": "6.5.0-beta.1",
|
|
38
|
+
"@webiny/project": "6.5.0-beta.1",
|
|
39
|
+
"@webiny/utils": "6.5.0-beta.1",
|
|
40
|
+
"@webiny/validation": "6.5.0-beta.1",
|
|
41
41
|
"dot-prop-immutable": "2.1.1",
|
|
42
42
|
"graphql": "16.14.2",
|
|
43
43
|
"graphql-tag": "2.12.7",
|
|
@@ -50,11 +50,11 @@
|
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/pluralize": "0.0.33",
|
|
53
|
-
"@webiny/build-tools": "6.5.0-beta.
|
|
54
|
-
"@webiny/handler-db": "6.5.0-beta.
|
|
55
|
-
"@webiny/project-utils": "6.5.0-beta.
|
|
56
|
-
"@webiny/sdk": "6.5.0-beta.
|
|
57
|
-
"@webiny/wcp": "6.5.0-beta.
|
|
53
|
+
"@webiny/build-tools": "6.5.0-beta.1",
|
|
54
|
+
"@webiny/handler-db": "6.5.0-beta.1",
|
|
55
|
+
"@webiny/project-utils": "6.5.0-beta.1",
|
|
56
|
+
"@webiny/sdk": "6.5.0-beta.1",
|
|
57
|
+
"@webiny/wcp": "6.5.0-beta.1",
|
|
58
58
|
"apollo-graphql": "0.9.7",
|
|
59
59
|
"graphql": "16.14.2",
|
|
60
60
|
"oxfmt": "0.59.0",
|