@webiny/api-headless-cms 6.4.12-beta.5 → 6.5.0-beta.0
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.d.ts +1 -1
- package/crud/contentEntry/entryDataValidation.js +33 -18
- package/crud/contentEntry/entryDataValidation.js.map +1 -1
- package/crud/contentEntry.crud.js +12 -39
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/defaultFields.js +3 -2
- package/crud/contentModel/defaultFields.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/schemas.d.ts +4 -0
- package/domain/contentModel/schemas.js +5 -2
- package/domain/contentModel/schemas.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 +2 -1
- 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/model.d.ts +4 -1
- package/exports/api/cms/model.js +2 -0
- package/extension.d.ts +3 -0
- package/extension.js +19 -0
- package/extension.js.map +1 -0
- package/features/contentEntry/ContentEntriesFeature.js +2 -0
- package/features/contentEntry/ContentEntriesFeature.js.map +1 -1
- package/features/contentEntry/CreateEntry/CreateEntryUseCase.js +1 -2
- package/features/contentEntry/CreateEntry/CreateEntryUseCase.js.map +1 -1
- package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromUseCase.js.map +1 -1
- package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionRepository.js +1 -0
- package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionRepository.js.map +1 -1
- package/features/contentEntry/GetSingletonEntry/GetSingletonEntryUseCase.js +1 -3
- package/features/contentEntry/GetSingletonEntry/GetSingletonEntryUseCase.js.map +1 -1
- package/features/contentEntry/PublishEntry/PublishEntryUseCase.js.map +1 -1
- package/features/contentEntry/UpdateRevision/UpdateRevisionRepository.d.ts +14 -0
- package/features/contentEntry/UpdateRevision/UpdateRevisionRepository.js +34 -0
- package/features/contentEntry/UpdateRevision/UpdateRevisionRepository.js.map +1 -0
- package/features/contentEntry/UpdateRevision/abstractions.d.ts +10 -0
- package/features/contentEntry/UpdateRevision/abstractions.js +5 -0
- package/features/contentEntry/UpdateRevision/abstractions.js.map +1 -0
- package/features/contentEntry/UpdateRevision/feature.d.ts +4 -0
- package/features/contentEntry/UpdateRevision/feature.js +11 -0
- package/features/contentEntry/UpdateRevision/feature.js.map +1 -0
- package/features/contentEntry/UpdateRevision/index.d.ts +1 -0
- package/features/contentEntry/UpdateRevision/index.js +1 -0
- 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/ensureItemIds.d.ts +13 -0
- package/features/contentEntry/ensureItemIds.js +22 -0
- package/features/contentEntry/ensureItemIds.js.map +1 -0
- package/features/contentEntry/entryDataFactories/CreateEntryDataFactory/CreateEntryDataFactory.d.ts +3 -1
- package/features/contentEntry/entryDataFactories/CreateEntryDataFactory/CreateEntryDataFactory.js +9 -3
- package/features/contentEntry/entryDataFactories/CreateEntryDataFactory/CreateEntryDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.d.ts +3 -3
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js +10 -6
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.d.ts +3 -1
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js +9 -3
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/expiresAt.js +2 -2
- package/features/contentEntry/entryDataFactories/expiresAt.js.map +1 -1
- package/features/contentModel/ComponentMapGenerator/ComponentMapGenerator.d.ts +14 -0
- package/features/contentModel/ComponentMapGenerator/ComponentMapGenerator.js +32 -0
- package/features/contentModel/ComponentMapGenerator/ComponentMapGenerator.js.map +1 -0
- package/features/contentModel/ComponentMapGenerator/abstractions.d.ts +8 -0
- package/features/contentModel/ComponentMapGenerator/abstractions.js +5 -0
- package/features/contentModel/ComponentMapGenerator/abstractions.js.map +1 -0
- package/features/contentModel/ComponentMapGenerator/feature.d.ts +4 -0
- package/features/contentModel/ComponentMapGenerator/feature.js +11 -0
- package/features/contentModel/ComponentMapGenerator/feature.js.map +1 -0
- package/features/contentModel/ComponentMapGenerator/index.d.ts +2 -0
- package/features/contentModel/ComponentMapGenerator/index.js +2 -0
- package/features/contentModel/ContentModelFeature.js +6 -0
- package/features/contentModel/ContentModelFeature.js.map +1 -1
- package/features/contentModel/CreateModel/CreateModelRepository.js +2 -1
- package/features/contentModel/CreateModel/CreateModelRepository.js.map +1 -1
- package/features/contentModel/CreateModelFrom/CreateModelFromRepository.js +2 -1
- package/features/contentModel/CreateModelFrom/CreateModelFromRepository.js.map +1 -1
- package/features/contentModel/RefModelsGenerator/RefModelsGenerator.d.ts +19 -0
- package/features/contentModel/RefModelsGenerator/RefModelsGenerator.js +56 -0
- package/features/contentModel/RefModelsGenerator/RefModelsGenerator.js.map +1 -0
- package/features/contentModel/RefModelsGenerator/abstractions.d.ts +11 -0
- package/features/contentModel/RefModelsGenerator/abstractions.js +5 -0
- package/features/contentModel/RefModelsGenerator/abstractions.js.map +1 -0
- package/features/contentModel/RefModelsGenerator/feature.d.ts +4 -0
- package/features/contentModel/RefModelsGenerator/feature.js +11 -0
- package/features/contentModel/RefModelsGenerator/feature.js.map +1 -0
- package/features/contentModel/RefModelsGenerator/index.d.ts +2 -0
- package/features/contentModel/RefModelsGenerator/index.js +2 -0
- package/features/contentModel/ValuesSelectionGenerator/ValuesSelectionGenerator.d.ts +16 -0
- package/features/contentModel/ValuesSelectionGenerator/ValuesSelectionGenerator.js +54 -0
- package/features/contentModel/ValuesSelectionGenerator/ValuesSelectionGenerator.js.map +1 -0
- package/features/contentModel/ValuesSelectionGenerator/abstractions.d.ts +8 -0
- package/features/contentModel/ValuesSelectionGenerator/abstractions.js +5 -0
- package/features/contentModel/ValuesSelectionGenerator/abstractions.js.map +1 -0
- package/features/contentModel/ValuesSelectionGenerator/feature.d.ts +4 -0
- package/features/contentModel/ValuesSelectionGenerator/feature.js +11 -0
- package/features/contentModel/ValuesSelectionGenerator/feature.js.map +1 -0
- package/features/contentModel/ValuesSelectionGenerator/index.d.ts +1 -0
- package/features/contentModel/ValuesSelectionGenerator/index.js +1 -0
- package/features/graphql/feature.js +2 -0
- package/features/graphql/feature.js.map +1 -1
- package/features/graphql/fields/base/AssetToGraphQL.d.ts +26 -0
- package/features/graphql/fields/base/AssetToGraphQL.js +148 -0
- package/features/graphql/fields/base/AssetToGraphQL.js.map +1 -0
- package/features/graphql/fields/base/DynamicZoneToGraphQL.js +12 -2
- package/features/graphql/fields/base/DynamicZoneToGraphQL.js.map +1 -1
- package/features/graphql/fields/base/ObjectToGraphQL.js +8 -5
- package/features/graphql/fields/base/ObjectToGraphQL.js.map +1 -1
- package/features/modelBuilder/abstractions.d.ts +9 -0
- package/features/modelBuilder/abstractions.js.map +1 -1
- package/features/modelBuilder/feature.js +2 -0
- package/features/modelBuilder/feature.js.map +1 -1
- package/features/modelBuilder/fields/AssetFieldType.d.ts +20 -0
- package/features/modelBuilder/fields/AssetFieldType.js +46 -0
- package/features/modelBuilder/fields/AssetFieldType.js.map +1 -0
- package/features/modelBuilder/fields/DataFieldBuilder.d.ts +62 -18
- package/features/modelBuilder/fields/DataFieldBuilder.js +8 -0
- package/features/modelBuilder/fields/DataFieldBuilder.js.map +1 -1
- package/features/modelBuilder/fields/DynamicZoneFieldType.d.ts +1 -0
- package/features/modelBuilder/fields/DynamicZoneFieldType.js +2 -6
- package/features/modelBuilder/fields/DynamicZoneFieldType.js.map +1 -1
- package/features/modelBuilder/fields/resolveAssetUrl.d.ts +35 -0
- package/features/modelBuilder/fields/resolveAssetUrl.js +26 -0
- package/features/modelBuilder/fields/resolveAssetUrl.js.map +1 -0
- package/features/modelBuilder/index.d.ts +1 -1
- package/features/modelBuilder/models/BaseModelBuilder.d.ts +3 -1
- package/features/modelBuilder/models/BaseModelBuilder.js +7 -0
- package/features/modelBuilder/models/BaseModelBuilder.js.map +1 -1
- package/features/modelBuilder/models/PrivateModelBuilder.js +2 -1
- package/features/modelBuilder/models/PrivateModelBuilder.js.map +1 -1
- package/features/modelBuilder/models/PublicModelBuilder.js +2 -1
- package/features/modelBuilder/models/PublicModelBuilder.js.map +1 -1
- package/features/sortMapper/SortMapper.js +2 -5
- package/features/sortMapper/SortMapper.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 +4 -3
- 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/ObjectStorageTransform.js +27 -7
- package/features/storage/fields/ObjectStorageTransform.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/validation/validators/PatternValidator.js +1 -1
- package/features/validation/validators/PatternValidator.js.map +1 -1
- package/features/whereMapper/WhereMapper.js +10 -7
- package/features/whereMapper/WhereMapper.js.map +1 -1
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +8 -2
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +8 -2
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/index.d.ts +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/baseSchema.js +5 -25
- package/graphql/schema/baseSchema.js.map +1 -1
- package/graphql/schema/cms/getEntryResolver.js +3 -2
- package/graphql/schema/cms/getEntryResolver.js.map +1 -1
- package/graphql/schema/cms/getModelResolver.d.ts +35 -0
- package/graphql/schema/cms/getModelResolver.js +49 -0
- package/graphql/schema/cms/getModelResolver.js.map +1 -0
- package/graphql/schema/cms/helpers/buildFieldsSelection.js +9 -2
- package/graphql/schema/cms/helpers/buildFieldsSelection.js.map +1 -1
- package/graphql/schema/cms/helpers/expandFieldWildcards.d.ts +2 -0
- package/graphql/schema/cms/helpers/expandFieldWildcards.js +13 -0
- package/graphql/schema/cms/helpers/expandFieldWildcards.js.map +1 -0
- package/graphql/schema/cms/helpers/index.d.ts +1 -0
- package/graphql/schema/cms/helpers/index.js +1 -0
- package/graphql/schema/cms/helpers.d.ts +1 -0
- package/graphql/schema/cms/helpers.js +1 -0
- package/graphql/schema/cms/index.js +2 -1
- package/graphql/schema/cms/index.js.map +1 -1
- package/graphql/schema/cms/listEntriesResolver.js +3 -2
- package/graphql/schema/cms/listEntriesResolver.js.map +1 -1
- package/graphql/schema/cms/resolvers/getModel.d.ts +8 -0
- package/graphql/schema/cms/resolvers/getModel.js +18 -0
- package/graphql/schema/cms/resolvers/getModel.js.map +1 -0
- package/graphql/schema/cms/resolvers/index.d.ts +1 -0
- package/graphql/schema/cms/resolvers/index.js +1 -0
- package/graphql/schema/cms/typeDefs/query.js +1 -0
- package/graphql/schema/cms/typeDefs/query.js.map +1 -1
- package/graphql/schema/cms/typeDefs/responses.js +5 -0
- package/graphql/schema/cms/typeDefs/responses.js.map +1 -1
- package/graphql/schema/contentModels.js +40 -1
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createFieldResolvers.js +1 -1
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/index.d.ts +2 -5
- package/index.js +1 -21
- package/package.json +27 -30
- package/plugins/CmsModelPlugin.js +12 -10
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/types/fields/dynamicZoneField.d.ts +1 -0
- package/types/model.d.ts +6 -0
- package/types/modelField.d.ts +13 -0
- package/types/types.d.ts +8 -4
- package/types/types.js.map +1 -1
- package/utils/caching/Cache.js +1 -1
- package/utils/caching/Cache.js.map +1 -1
- package/utils/contentModelToJsonSchema/CmsModelToJsonSchemaConverter.d.ts +28 -0
- package/utils/contentModelToJsonSchema/CmsModelToJsonSchemaConverter.js +324 -0
- package/utils/contentModelToJsonSchema/CmsModelToJsonSchemaConverter.js.map +1 -0
- package/utils/contentModelToJsonSchema/index.d.ts +2 -0
- package/utils/contentModelToJsonSchema/index.js +1 -0
- package/utils/contentModelToJsonSchema/types.d.ts +24 -0
- package/utils/contentModelToJsonSchema/types.js +0 -0
- package/utils/createModelField.js +2 -1
- package/utils/createModelField.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/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/renderFields.js +1 -1
- package/utils/renderFields.js.map +1 -1
- package/index.js.map +0 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { RefModelsGenerator } from "./abstractions.js";
|
|
2
|
+
import { ModelToAstConverter } from "../ModelToAstConverter/abstractions.js";
|
|
3
|
+
import { ValuesSelectionGenerator } from "../ValuesSelectionGenerator/abstractions.js";
|
|
4
|
+
import { ModelsFetcher } from "../shared/abstractions.js";
|
|
5
|
+
class RefModelsGeneratorImpl {
|
|
6
|
+
constructor(modelToAst, modelsFetcher, valuesSelectionGenerator){
|
|
7
|
+
this.modelToAst = modelToAst;
|
|
8
|
+
this.modelsFetcher = modelsFetcher;
|
|
9
|
+
this.valuesSelectionGenerator = valuesSelectionGenerator;
|
|
10
|
+
}
|
|
11
|
+
async generate(model) {
|
|
12
|
+
const ast = this.modelToAst.toAst(model);
|
|
13
|
+
const refModelIds = new Set();
|
|
14
|
+
for (const node of ast.children)this.collectRefModelIds(node, refModelIds);
|
|
15
|
+
const result = {};
|
|
16
|
+
for (const modelId of refModelIds){
|
|
17
|
+
const fetchResult = await this.modelsFetcher.fetchById(modelId);
|
|
18
|
+
if (fetchResult.isFail()) continue;
|
|
19
|
+
const refModel = fetchResult.value;
|
|
20
|
+
const valuesSelection = this.valuesSelectionGenerator.generate(refModel);
|
|
21
|
+
result[modelId] = {
|
|
22
|
+
valuesSelection
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
collectRefModelIds(node, modelIds) {
|
|
28
|
+
if ("field" === node.type) this.collectFromFieldNode(node, modelIds);
|
|
29
|
+
else if ("collection" === node.type) this.collectFromCollectionNode(node, modelIds);
|
|
30
|
+
}
|
|
31
|
+
collectFromFieldNode(node, modelIds) {
|
|
32
|
+
const { field, children } = node;
|
|
33
|
+
if ("ref" === field.type) {
|
|
34
|
+
const models = field.settings?.models;
|
|
35
|
+
if (Array.isArray(models)) {
|
|
36
|
+
for (const refModel of models)if (refModel.modelId) modelIds.add(refModel.modelId);
|
|
37
|
+
}
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
for (const child of children)this.collectRefModelIds(child, modelIds);
|
|
41
|
+
}
|
|
42
|
+
collectFromCollectionNode(node, modelIds) {
|
|
43
|
+
for (const child of node.children)this.collectRefModelIds(child, modelIds);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const RefModelsGenerator_RefModelsGenerator = RefModelsGenerator.createImplementation({
|
|
47
|
+
implementation: RefModelsGeneratorImpl,
|
|
48
|
+
dependencies: [
|
|
49
|
+
ModelToAstConverter,
|
|
50
|
+
ModelsFetcher,
|
|
51
|
+
ValuesSelectionGenerator
|
|
52
|
+
]
|
|
53
|
+
});
|
|
54
|
+
export { RefModelsGenerator_RefModelsGenerator as RefModelsGenerator };
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=RefModelsGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/contentModel/RefModelsGenerator/RefModelsGenerator.js","sources":["../../../../src/features/contentModel/RefModelsGenerator/RefModelsGenerator.ts"],"sourcesContent":["import {\n RefModelsGenerator as Abstraction,\n type IRefModelsGenerator,\n type RefModelMetadata\n} from \"./abstractions.js\";\nimport { ModelToAstConverter } from \"../ModelToAstConverter/abstractions.js\";\nimport { ValuesSelectionGenerator } from \"../ValuesSelectionGenerator/abstractions.js\";\nimport { ModelsFetcher } from \"../shared/abstractions.js\";\nimport type {\n CmsModel,\n CmsModelFieldAstNode,\n CmsModelFieldAstNodeField,\n CmsModelFieldAstNodeCollection\n} from \"~/types/index.js\";\n\nclass RefModelsGeneratorImpl implements IRefModelsGenerator {\n constructor(\n private readonly modelToAst: ModelToAstConverter.Interface,\n private readonly modelsFetcher: ModelsFetcher.Interface,\n private readonly valuesSelectionGenerator: ValuesSelectionGenerator.Interface\n ) {}\n\n async generate(model: CmsModel): Promise<Record<string, RefModelMetadata>> {\n const ast = this.modelToAst.toAst(model);\n const refModelIds = new Set<string>();\n\n for (const node of ast.children) {\n this.collectRefModelIds(node, refModelIds);\n }\n\n const result: Record<string, RefModelMetadata> = {};\n\n for (const modelId of refModelIds) {\n const fetchResult = await this.modelsFetcher.fetchById(modelId);\n if (fetchResult.isFail()) {\n continue;\n }\n\n const refModel = fetchResult.value;\n const valuesSelection = this.valuesSelectionGenerator.generate(refModel);\n\n result[modelId] = { valuesSelection };\n }\n\n return result;\n }\n\n private collectRefModelIds(node: CmsModelFieldAstNode, modelIds: Set<string>): void {\n if (node.type === \"field\") {\n this.collectFromFieldNode(node, modelIds);\n } else if (node.type === \"collection\") {\n this.collectFromCollectionNode(node, modelIds);\n }\n }\n\n private collectFromFieldNode(node: CmsModelFieldAstNodeField, modelIds: Set<string>): void {\n const { field, children } = node;\n\n if (field.type === \"ref\") {\n const models = field.settings?.models;\n if (Array.isArray(models)) {\n for (const refModel of models) {\n if (refModel.modelId) {\n modelIds.add(refModel.modelId);\n }\n }\n }\n return;\n }\n\n for (const child of children) {\n this.collectRefModelIds(child, modelIds);\n }\n }\n\n private collectFromCollectionNode(\n node: CmsModelFieldAstNodeCollection,\n modelIds: Set<string>\n ): void {\n for (const child of node.children) {\n this.collectRefModelIds(child, modelIds);\n }\n }\n}\n\nexport const RefModelsGenerator = Abstraction.createImplementation({\n implementation: RefModelsGeneratorImpl,\n dependencies: [ModelToAstConverter, ModelsFetcher, ValuesSelectionGenerator]\n});\n"],"names":["RefModelsGeneratorImpl","modelToAst","modelsFetcher","valuesSelectionGenerator","model","ast","refModelIds","Set","node","result","modelId","fetchResult","refModel","valuesSelection","modelIds","field","children","models","Array","child","RefModelsGenerator","Abstraction","ModelToAstConverter","ModelsFetcher","ValuesSelectionGenerator"],"mappings":";;;;AAeA,MAAMA;IACF,YACqBC,UAAyC,EACzCC,aAAsC,EACtCC,wBAA4D,CAC/E;aAHmBF,UAAU,GAAVA;aACAC,aAAa,GAAbA;aACAC,wBAAwB,GAAxBA;IAClB;IAEH,MAAM,SAASC,KAAe,EAA6C;QACvE,MAAMC,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAACD;QAClC,MAAME,cAAc,IAAIC;QAExB,KAAK,MAAMC,QAAQH,IAAI,QAAQ,CAC3B,IAAI,CAAC,kBAAkB,CAACG,MAAMF;QAGlC,MAAMG,SAA2C,CAAC;QAElD,KAAK,MAAMC,WAAWJ,YAAa;YAC/B,MAAMK,cAAc,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAACD;YACvD,IAAIC,YAAY,MAAM,IAClB;YAGJ,MAAMC,WAAWD,YAAY,KAAK;YAClC,MAAME,kBAAkB,IAAI,CAAC,wBAAwB,CAAC,QAAQ,CAACD;YAE/DH,MAAM,CAACC,QAAQ,GAAG;gBAAEG;YAAgB;QACxC;QAEA,OAAOJ;IACX;IAEQ,mBAAmBD,IAA0B,EAAEM,QAAqB,EAAQ;QAChF,IAAIN,AAAc,YAAdA,KAAK,IAAI,EACT,IAAI,CAAC,oBAAoB,CAACA,MAAMM;aAC7B,IAAIN,AAAc,iBAAdA,KAAK,IAAI,EAChB,IAAI,CAAC,yBAAyB,CAACA,MAAMM;IAE7C;IAEQ,qBAAqBN,IAA+B,EAAEM,QAAqB,EAAQ;QACvF,MAAM,EAAEC,KAAK,EAAEC,QAAQ,EAAE,GAAGR;QAE5B,IAAIO,AAAe,UAAfA,MAAM,IAAI,EAAY;YACtB,MAAME,SAASF,MAAM,QAAQ,EAAE;YAC/B,IAAIG,MAAM,OAAO,CAACD,SACd;gBAAA,KAAK,MAAML,YAAYK,OACnB,IAAIL,SAAS,OAAO,EAChBE,SAAS,GAAG,CAACF,SAAS,OAAO;YAErC;YAEJ;QACJ;QAEA,KAAK,MAAMO,SAASH,SAChB,IAAI,CAAC,kBAAkB,CAACG,OAAOL;IAEvC;IAEQ,0BACJN,IAAoC,EACpCM,QAAqB,EACjB;QACJ,KAAK,MAAMK,SAASX,KAAK,QAAQ,CAC7B,IAAI,CAAC,kBAAkB,CAACW,OAAOL;IAEvC;AACJ;AAEO,MAAMM,wCAAqBC,mBAAAA,oBAAgC,CAAC;IAC/D,gBAAgBrB;IAChB,cAAc;QAACsB;QAAqBC;QAAeC;KAAyB;AAChF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CmsModel } from "../../../types/index.js";
|
|
2
|
+
export interface RefModelMetadata {
|
|
3
|
+
valuesSelection: string;
|
|
4
|
+
}
|
|
5
|
+
export interface IRefModelsGenerator {
|
|
6
|
+
generate(model: CmsModel): Promise<Record<string, RefModelMetadata>>;
|
|
7
|
+
}
|
|
8
|
+
export declare const RefModelsGenerator: import("@webiny/di").Abstraction<IRefModelsGenerator>;
|
|
9
|
+
export declare namespace RefModelsGenerator {
|
|
10
|
+
type Interface = IRefModelsGenerator;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/contentModel/RefModelsGenerator/abstractions.js","sources":["../../../../src/features/contentModel/RefModelsGenerator/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { CmsModel } from \"~/types/index.js\";\n\nexport interface RefModelMetadata {\n valuesSelection: string;\n}\n\nexport interface IRefModelsGenerator {\n generate(model: CmsModel): Promise<Record<string, RefModelMetadata>>;\n}\n\nexport const RefModelsGenerator = createAbstraction<IRefModelsGenerator>(\"RefModelsGenerator\");\n\nexport namespace RefModelsGenerator {\n export type Interface = IRefModelsGenerator;\n}\n"],"names":["RefModelsGenerator","createAbstraction"],"mappings":";AAWO,MAAMA,qBAAqBC,kBAAuC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { RefModelsGenerator } from "./RefModelsGenerator.js";
|
|
3
|
+
const RefModelsGeneratorFeature = createFeature({
|
|
4
|
+
name: "RefModelsGenerator",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(RefModelsGenerator);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { RefModelsGeneratorFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/contentModel/RefModelsGenerator/feature.js","sources":["../../../../src/features/contentModel/RefModelsGenerator/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { RefModelsGenerator } from \"./RefModelsGenerator.js\";\n\nexport const RefModelsGeneratorFeature = createFeature({\n name: \"RefModelsGenerator\",\n register(container) {\n container.register(RefModelsGenerator);\n }\n});\n"],"names":["RefModelsGeneratorFeature","createFeature","container","RefModelsGenerator"],"mappings":";;AAGO,MAAMA,4BAA4BC,cAAc;IACnD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type IValuesSelectionGenerator } from "./abstractions.js";
|
|
2
|
+
import { ModelToAstConverter } from "../ModelToAstConverter/abstractions.js";
|
|
3
|
+
import type { CmsModel } from "../../../types/index.js";
|
|
4
|
+
declare class ValuesSelectionGeneratorImpl implements IValuesSelectionGenerator {
|
|
5
|
+
private readonly modelToAst;
|
|
6
|
+
constructor(modelToAst: ModelToAstConverter.Interface);
|
|
7
|
+
generate(model: CmsModel): string;
|
|
8
|
+
private walkRoot;
|
|
9
|
+
private walkNode;
|
|
10
|
+
private walkFieldNode;
|
|
11
|
+
private walkCollectionNode;
|
|
12
|
+
}
|
|
13
|
+
export declare const ValuesSelectionGenerator: typeof ValuesSelectionGeneratorImpl & {
|
|
14
|
+
__abstraction: import("@webiny/di").Abstraction<IValuesSelectionGenerator>;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ValuesSelectionGenerator } from "./abstractions.js";
|
|
2
|
+
import { ModelToAstConverter } from "../ModelToAstConverter/abstractions.js";
|
|
3
|
+
import { createTypeName } from "../../../utils/createTypeName.js";
|
|
4
|
+
const REF_SELECTION = "{ id modelId }";
|
|
5
|
+
const ASSET_SELECTION = "{ id src url name type size image { width height crop { top left bottom right } focalPoint { x y } alt caption } document { pages } video { autoplay poster } }";
|
|
6
|
+
class ValuesSelectionGeneratorImpl {
|
|
7
|
+
constructor(modelToAst){
|
|
8
|
+
this.modelToAst = modelToAst;
|
|
9
|
+
}
|
|
10
|
+
generate(model) {
|
|
11
|
+
const ast = this.modelToAst.toAst(model);
|
|
12
|
+
const selection = this.walkRoot(ast, model.singularApiName);
|
|
13
|
+
return selection || "_empty";
|
|
14
|
+
}
|
|
15
|
+
walkRoot(ast, typePrefix) {
|
|
16
|
+
return ast.children.map((node)=>this.walkNode(node, typePrefix)).filter(Boolean).join("\n");
|
|
17
|
+
}
|
|
18
|
+
walkNode(node, typePrefix) {
|
|
19
|
+
if ("field" === node.type) return this.walkFieldNode(node, typePrefix);
|
|
20
|
+
if ("collection" === node.type) return this.walkCollectionNode(node, typePrefix);
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
walkFieldNode(node, typePrefix) {
|
|
24
|
+
const { field, children } = node;
|
|
25
|
+
if ("ref" === field.type) return `${field.fieldId} ${REF_SELECTION}`;
|
|
26
|
+
if ("asset" === field.type) return `${field.fieldId} ${ASSET_SELECTION}`;
|
|
27
|
+
if (0 === children.length) {
|
|
28
|
+
if ("object" === field.type || "dynamicZone" === field.type) return null;
|
|
29
|
+
return field.fieldId;
|
|
30
|
+
}
|
|
31
|
+
const nestedPrefix = `${typePrefix}_${createTypeName(field.fieldId)}`;
|
|
32
|
+
const childSelection = children.map((child)=>this.walkNode(child, nestedPrefix)).filter(Boolean).join("\n");
|
|
33
|
+
if (!childSelection) return null;
|
|
34
|
+
const idSelection = "object" === field.type ? "_id " : "";
|
|
35
|
+
return `${field.fieldId} { ${idSelection}${childSelection} }`;
|
|
36
|
+
}
|
|
37
|
+
walkCollectionNode(node, typePrefix) {
|
|
38
|
+
const { collection, children } = node;
|
|
39
|
+
const gqlTypeName = collection.gqlTypeName;
|
|
40
|
+
if (!gqlTypeName) return null;
|
|
41
|
+
const templateType = `${typePrefix}_${gqlTypeName}`;
|
|
42
|
+
const childSelection = children.map((child)=>this.walkNode(child, templateType)).filter(Boolean).join("\n");
|
|
43
|
+
return `...on ${templateType} { ${childSelection} _templateId _id __typename }`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const ValuesSelectionGenerator_ValuesSelectionGenerator = ValuesSelectionGenerator.createImplementation({
|
|
47
|
+
implementation: ValuesSelectionGeneratorImpl,
|
|
48
|
+
dependencies: [
|
|
49
|
+
ModelToAstConverter
|
|
50
|
+
]
|
|
51
|
+
});
|
|
52
|
+
export { ValuesSelectionGenerator_ValuesSelectionGenerator as ValuesSelectionGenerator };
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=ValuesSelectionGenerator.js.map
|
|
@@ -0,0 +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 type size\",\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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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CmsModel } from "../../../types/index.js";
|
|
2
|
+
export interface IValuesSelectionGenerator {
|
|
3
|
+
generate(model: CmsModel): string;
|
|
4
|
+
}
|
|
5
|
+
export declare const ValuesSelectionGenerator: import("@webiny/di").Abstraction<IValuesSelectionGenerator>;
|
|
6
|
+
export declare namespace ValuesSelectionGenerator {
|
|
7
|
+
type Interface = IValuesSelectionGenerator;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/contentModel/ValuesSelectionGenerator/abstractions.js","sources":["../../../../src/features/contentModel/ValuesSelectionGenerator/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { CmsModel } from \"~/types/index.js\";\n\nexport interface IValuesSelectionGenerator {\n generate(model: CmsModel): string;\n}\n\nexport const ValuesSelectionGenerator = createAbstraction<IValuesSelectionGenerator>(\n \"ValuesSelectionGenerator\"\n);\n\nexport namespace ValuesSelectionGenerator {\n export type Interface = IValuesSelectionGenerator;\n}\n"],"names":["ValuesSelectionGenerator","createAbstraction"],"mappings":";AAOO,MAAMA,2BAA2BC,kBACpC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { ValuesSelectionGenerator } from "./ValuesSelectionGenerator.js";
|
|
3
|
+
const ValuesSelectionGeneratorFeature = createFeature({
|
|
4
|
+
name: "ValuesSelectionGenerator",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(ValuesSelectionGenerator);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { ValuesSelectionGeneratorFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/contentModel/ValuesSelectionGenerator/feature.js","sources":["../../../../src/features/contentModel/ValuesSelectionGenerator/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ValuesSelectionGenerator } from \"./ValuesSelectionGenerator.js\";\n\nexport const ValuesSelectionGeneratorFeature = createFeature({\n name: \"ValuesSelectionGenerator\",\n register(container) {\n container.register(ValuesSelectionGenerator);\n }\n});\n"],"names":["ValuesSelectionGeneratorFeature","createFeature","container","ValuesSelectionGenerator"],"mappings":";;AAGO,MAAMA,kCAAkCC,cAAc;IACzD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./abstractions.js";
|
|
@@ -12,6 +12,7 @@ import { RefFieldToGraphQL } from "./fields/base/RefToGraphQL.js";
|
|
|
12
12
|
import { SearchableJsonFieldToGraphQL } from "./fields/base/SearchableJsonToGraphQL.js";
|
|
13
13
|
import { TextFieldToGraphQL } from "./fields/base/TextToGraphQL.js";
|
|
14
14
|
import { RichTextFieldToGraphQL } from "./fields/base/RichTextToGraphQL.js";
|
|
15
|
+
import { AssetFieldToGraphQL } from "./fields/base/AssetToGraphQL.js";
|
|
15
16
|
const GraphQLFeature = createFeature({
|
|
16
17
|
name: "Cms/GraphQLFeature",
|
|
17
18
|
register: (container)=>{
|
|
@@ -27,6 +28,7 @@ const GraphQLFeature = createFeature({
|
|
|
27
28
|
container.register(RichTextFieldToGraphQL);
|
|
28
29
|
container.register(SearchableJsonFieldToGraphQL);
|
|
29
30
|
container.register(TextFieldToGraphQL);
|
|
31
|
+
container.register(AssetFieldToGraphQL);
|
|
30
32
|
container.register(CmsModelFieldToGraphQLRegistry).inSingletonScope();
|
|
31
33
|
}
|
|
32
34
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/graphql/feature.js","sources":["../../../src/features/graphql/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CmsModelFieldToGraphQLRegistry } from \"./fields/CmsModelFieldToGraphQLRegistry.js\";\nimport { BooleanFieldToGraphQL } from \"./fields/base/BooleanToGraphQL.js\";\nimport { DateTimeFieldToGraphQL } from \"./fields/base/DateTimeToGraphQL.js\";\nimport { DynamicZoneFieldToGraphQL } from \"./fields/base/DynamicZoneToGraphQL.js\";\nimport { FileFieldToGraphQL } from \"./fields/base/FileToGraphQL.js\";\nimport { JsonFieldToGraphQL } from \"./fields/base/JsonToGraphQL.js\";\nimport { LongTextFieldToGraphQL } from \"./fields/base/LongTextToGraphQL.js\";\nimport { NumberFieldToGraphQL } from \"./fields/base/NumberToGraphQL.js\";\nimport { ObjectFieldToGraphQL } from \"./fields/base/ObjectToGraphQL.js\";\nimport { RefFieldToGraphQL } from \"./fields/base/RefToGraphQL.js\";\nimport { SearchableJsonFieldToGraphQL } from \"./fields/base/SearchableJsonToGraphQL.js\";\nimport { TextFieldToGraphQL } from \"./fields/base/TextToGraphQL.js\";\nimport { RichTextFieldToGraphQL } from \"./fields/base/RichTextToGraphQL.js\";\n\nexport const GraphQLFeature = createFeature({\n name: \"Cms/GraphQLFeature\",\n register: container => {\n container.register(BooleanFieldToGraphQL);\n container.register(DateTimeFieldToGraphQL);\n container.register(DynamicZoneFieldToGraphQL);\n container.register(FileFieldToGraphQL);\n container.register(JsonFieldToGraphQL);\n container.register(LongTextFieldToGraphQL);\n container.register(NumberFieldToGraphQL);\n container.register(ObjectFieldToGraphQL);\n container.register(RefFieldToGraphQL);\n container.register(RichTextFieldToGraphQL);\n container.register(SearchableJsonFieldToGraphQL);\n container.register(TextFieldToGraphQL);\n\n container.register(CmsModelFieldToGraphQLRegistry).inSingletonScope();\n }\n});\n"],"names":["GraphQLFeature","createFeature","container","BooleanFieldToGraphQL","DateTimeFieldToGraphQL","DynamicZoneFieldToGraphQL","FileFieldToGraphQL","JsonFieldToGraphQL","LongTextFieldToGraphQL","NumberFieldToGraphQL","ObjectFieldToGraphQL","RefFieldToGraphQL","RichTextFieldToGraphQL","SearchableJsonFieldToGraphQL","TextFieldToGraphQL","CmsModelFieldToGraphQLRegistry"],"mappings":"
|
|
1
|
+
{"version":3,"file":"features/graphql/feature.js","sources":["../../../src/features/graphql/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CmsModelFieldToGraphQLRegistry } from \"./fields/CmsModelFieldToGraphQLRegistry.js\";\nimport { BooleanFieldToGraphQL } from \"./fields/base/BooleanToGraphQL.js\";\nimport { DateTimeFieldToGraphQL } from \"./fields/base/DateTimeToGraphQL.js\";\nimport { DynamicZoneFieldToGraphQL } from \"./fields/base/DynamicZoneToGraphQL.js\";\nimport { FileFieldToGraphQL } from \"./fields/base/FileToGraphQL.js\";\nimport { JsonFieldToGraphQL } from \"./fields/base/JsonToGraphQL.js\";\nimport { LongTextFieldToGraphQL } from \"./fields/base/LongTextToGraphQL.js\";\nimport { NumberFieldToGraphQL } from \"./fields/base/NumberToGraphQL.js\";\nimport { ObjectFieldToGraphQL } from \"./fields/base/ObjectToGraphQL.js\";\nimport { RefFieldToGraphQL } from \"./fields/base/RefToGraphQL.js\";\nimport { SearchableJsonFieldToGraphQL } from \"./fields/base/SearchableJsonToGraphQL.js\";\nimport { TextFieldToGraphQL } from \"./fields/base/TextToGraphQL.js\";\nimport { RichTextFieldToGraphQL } from \"./fields/base/RichTextToGraphQL.js\";\nimport { AssetFieldToGraphQL } from \"./fields/base/AssetToGraphQL.js\";\n\nexport const GraphQLFeature = createFeature({\n name: \"Cms/GraphQLFeature\",\n register: container => {\n container.register(BooleanFieldToGraphQL);\n container.register(DateTimeFieldToGraphQL);\n container.register(DynamicZoneFieldToGraphQL);\n container.register(FileFieldToGraphQL);\n container.register(JsonFieldToGraphQL);\n container.register(LongTextFieldToGraphQL);\n container.register(NumberFieldToGraphQL);\n container.register(ObjectFieldToGraphQL);\n container.register(RefFieldToGraphQL);\n container.register(RichTextFieldToGraphQL);\n container.register(SearchableJsonFieldToGraphQL);\n container.register(TextFieldToGraphQL);\n container.register(AssetFieldToGraphQL);\n\n container.register(CmsModelFieldToGraphQLRegistry).inSingletonScope();\n }\n});\n"],"names":["GraphQLFeature","createFeature","container","BooleanFieldToGraphQL","DateTimeFieldToGraphQL","DynamicZoneFieldToGraphQL","FileFieldToGraphQL","JsonFieldToGraphQL","LongTextFieldToGraphQL","NumberFieldToGraphQL","ObjectFieldToGraphQL","RefFieldToGraphQL","RichTextFieldToGraphQL","SearchableJsonFieldToGraphQL","TextFieldToGraphQL","AssetFieldToGraphQL","CmsModelFieldToGraphQLRegistry"],"mappings":";;;;;;;;;;;;;;;AAgBO,MAAMA,iBAAiBC,cAAc;IACxC,MAAM;IACN,UAAUC,CAAAA;QACNA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;QACnBH,UAAU,QAAQ,CAACI;QACnBJ,UAAU,QAAQ,CAACK;QACnBL,UAAU,QAAQ,CAACM;QACnBN,UAAU,QAAQ,CAACO;QACnBP,UAAU,QAAQ,CAACQ;QACnBR,UAAU,QAAQ,CAACS;QACnBT,UAAU,QAAQ,CAACU;QACnBV,UAAU,QAAQ,CAACW;QACnBX,UAAU,QAAQ,CAACY;QACnBZ,UAAU,QAAQ,CAACa;QAEnBb,UAAU,QAAQ,CAACc,gCAAgC,gBAAgB;IACvE;AACJ"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CmsModelFieldToGraphQL } from "../abstractions/CmsModelFieldToGraphQL.js";
|
|
2
|
+
import type { CmsModelFieldType } from "../../../../types/modelField.js";
|
|
3
|
+
import type { GraphQLSchemaDefinition } from "@webiny/handler-graphql/types.js";
|
|
4
|
+
import type { CmsContext } from "../../../../types/types.js";
|
|
5
|
+
declare class ReadApi implements CmsModelFieldToGraphQL.ReadApi {
|
|
6
|
+
createTypeField({ field }: CmsModelFieldToGraphQL.TypeFieldParams): string;
|
|
7
|
+
createResolver(): CmsModelFieldToGraphQL.Resolver;
|
|
8
|
+
createSchema(): GraphQLSchemaDefinition<CmsContext>;
|
|
9
|
+
}
|
|
10
|
+
declare class ManageApi extends ReadApi implements CmsModelFieldToGraphQL.ManageApi {
|
|
11
|
+
createInputField({ field }: CmsModelFieldToGraphQL.TypeFieldParams): string;
|
|
12
|
+
}
|
|
13
|
+
declare class AssetToGraphQL implements CmsModelFieldToGraphQL.Interface {
|
|
14
|
+
readonly read: ReadApi;
|
|
15
|
+
readonly manage: ManageApi;
|
|
16
|
+
readonly fieldType: CmsModelFieldType;
|
|
17
|
+
readonly isSearchable: boolean;
|
|
18
|
+
readonly isSortable: boolean;
|
|
19
|
+
readonly isFullTextSearchable: boolean;
|
|
20
|
+
getReadApi(): CmsModelFieldToGraphQL.ReadApi;
|
|
21
|
+
getManageApi(): CmsModelFieldToGraphQL.ManageApi;
|
|
22
|
+
}
|
|
23
|
+
export declare const AssetFieldToGraphQL: typeof AssetToGraphQL & {
|
|
24
|
+
__abstraction: import("@webiny/di").Abstraction<import("../abstractions/CmsModelFieldToGraphQL.js").ICmsModelFieldToGraphQL<import("~/types/modelField.js").CmsModelField>>;
|
|
25
|
+
};
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { CmsModelFieldToGraphQL } from "../abstractions/CmsModelFieldToGraphQL.js";
|
|
2
|
+
import { createGraphQLInputField } from "./utils/createGraphQLInputField.js";
|
|
3
|
+
import { resolveAssetUrl } from "../../../modelBuilder/fields/resolveAssetUrl.js";
|
|
4
|
+
const imageTypeDefs = `
|
|
5
|
+
type FmAssetCrop {
|
|
6
|
+
top: Number
|
|
7
|
+
left: Number
|
|
8
|
+
bottom: Number
|
|
9
|
+
right: Number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type FmAssetFocalPoint {
|
|
13
|
+
x: Number
|
|
14
|
+
y: Number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type FmAssetImage {
|
|
18
|
+
width: Number
|
|
19
|
+
height: Number
|
|
20
|
+
crop: FmAssetCrop
|
|
21
|
+
focalPoint: FmAssetFocalPoint
|
|
22
|
+
alt: String
|
|
23
|
+
caption: String
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
input FmAssetCropInput {
|
|
27
|
+
top: Number
|
|
28
|
+
left: Number
|
|
29
|
+
bottom: Number
|
|
30
|
+
right: Number
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
input FmAssetFocalPointInput {
|
|
34
|
+
x: Number
|
|
35
|
+
y: Number
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
input FmAssetImageInput {
|
|
39
|
+
width: Number
|
|
40
|
+
height: Number
|
|
41
|
+
crop: FmAssetCropInput
|
|
42
|
+
focalPoint: FmAssetFocalPointInput
|
|
43
|
+
alt: String
|
|
44
|
+
caption: String
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
const documentTypeDefs = `
|
|
48
|
+
type FmAssetDocument {
|
|
49
|
+
pages: Number
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
input FmAssetDocumentInput {
|
|
53
|
+
pages: Number
|
|
54
|
+
}
|
|
55
|
+
`;
|
|
56
|
+
const videoTypeDefs = `
|
|
57
|
+
type FmAssetVideo {
|
|
58
|
+
autoplay: Boolean
|
|
59
|
+
poster: String
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
input FmAssetVideoInput {
|
|
63
|
+
autoplay: Boolean
|
|
64
|
+
poster: String
|
|
65
|
+
}
|
|
66
|
+
`;
|
|
67
|
+
const baseTypeDefs = `
|
|
68
|
+
type FmAsset {
|
|
69
|
+
id: String!
|
|
70
|
+
src: String!
|
|
71
|
+
url: String
|
|
72
|
+
name: String!
|
|
73
|
+
type: String!
|
|
74
|
+
size: Number!
|
|
75
|
+
image: FmAssetImage
|
|
76
|
+
document: FmAssetDocument
|
|
77
|
+
video: FmAssetVideo
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
input FmAssetInput {
|
|
81
|
+
id: String!
|
|
82
|
+
src: String!
|
|
83
|
+
# TODO: figure out how to remove this from here, as this is a derived read-only value.
|
|
84
|
+
url: String
|
|
85
|
+
name: String!
|
|
86
|
+
type: String!
|
|
87
|
+
size: Number!
|
|
88
|
+
image: FmAssetImageInput
|
|
89
|
+
document: FmAssetDocumentInput
|
|
90
|
+
video: FmAssetVideoInput
|
|
91
|
+
}
|
|
92
|
+
`;
|
|
93
|
+
const allTypeDefs = [
|
|
94
|
+
imageTypeDefs,
|
|
95
|
+
documentTypeDefs,
|
|
96
|
+
videoTypeDefs,
|
|
97
|
+
baseTypeDefs
|
|
98
|
+
].join("\n");
|
|
99
|
+
class ReadApi {
|
|
100
|
+
createTypeField({ field }) {
|
|
101
|
+
if (field.list) return `${field.fieldId}: [FmAsset]`;
|
|
102
|
+
return `${field.fieldId}: FmAsset`;
|
|
103
|
+
}
|
|
104
|
+
createResolver() {
|
|
105
|
+
return {
|
|
106
|
+
resolver: null,
|
|
107
|
+
typeResolvers: {
|
|
108
|
+
FmAsset: {
|
|
109
|
+
url: (parent)=>resolveAssetUrl(parent)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
createSchema() {
|
|
115
|
+
return {
|
|
116
|
+
typeDefs: allTypeDefs,
|
|
117
|
+
resolvers: {}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
class ManageApi extends ReadApi {
|
|
122
|
+
createInputField({ field }) {
|
|
123
|
+
return createGraphQLInputField(field, "FmAssetInput");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
class AssetToGraphQL {
|
|
127
|
+
getReadApi() {
|
|
128
|
+
return this.read;
|
|
129
|
+
}
|
|
130
|
+
getManageApi() {
|
|
131
|
+
return this.manage;
|
|
132
|
+
}
|
|
133
|
+
constructor(){
|
|
134
|
+
this.read = new ReadApi();
|
|
135
|
+
this.manage = new ManageApi();
|
|
136
|
+
this.fieldType = "asset";
|
|
137
|
+
this.isSearchable = false;
|
|
138
|
+
this.isSortable = false;
|
|
139
|
+
this.isFullTextSearchable = false;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const AssetFieldToGraphQL = CmsModelFieldToGraphQL.createImplementation({
|
|
143
|
+
implementation: AssetToGraphQL,
|
|
144
|
+
dependencies: []
|
|
145
|
+
});
|
|
146
|
+
export { AssetFieldToGraphQL };
|
|
147
|
+
|
|
148
|
+
//# sourceMappingURL=AssetToGraphQL.js.map
|
|
@@ -0,0 +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 type: String!\n size: 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 type: String!\n size: 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;;;;;;;;;;;;;;;;;;;;;;;;;AAyBpC,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"}
|
|
@@ -66,10 +66,15 @@ class ReadApi {
|
|
|
66
66
|
fieldRegistry,
|
|
67
67
|
templates
|
|
68
68
|
});
|
|
69
|
+
const templateIds = templateTypes.map((type)=>`extend type ${type} {
|
|
70
|
+
_templateId: ID!
|
|
71
|
+
_id: ID
|
|
72
|
+
}
|
|
73
|
+
`);
|
|
69
74
|
typeDefs.unshift(`union ${unionTypeName} = ${templateTypes.join(" | ")}`);
|
|
70
75
|
return {
|
|
71
76
|
fields: `${field.fieldId}: ${field.list ? `[${unionTypeName}!]` : unionTypeName}`,
|
|
72
|
-
typeDefs: typeDefs.join("\n")
|
|
77
|
+
typeDefs: typeDefs.concat(templateIds).join("\n")
|
|
73
78
|
};
|
|
74
79
|
}
|
|
75
80
|
createResolver(params) {
|
|
@@ -93,6 +98,7 @@ class ManageApi {
|
|
|
93
98
|
});
|
|
94
99
|
const templateIds = templateTypes.map((type)=>`extend type ${type} {
|
|
95
100
|
_templateId: ID!
|
|
101
|
+
_id: ID
|
|
96
102
|
}
|
|
97
103
|
`);
|
|
98
104
|
typeDefs.unshift(`union ${unionTypeName} = ${templateTypes.join(" | ")}`);
|
|
@@ -127,9 +133,13 @@ class ManageApi {
|
|
|
127
133
|
${key}: ${value}
|
|
128
134
|
`)}
|
|
129
135
|
}`);
|
|
136
|
+
const templateInputIds = templateTypes.map((inputTypeName)=>`extend input ${inputTypeName} {
|
|
137
|
+
_id: ID
|
|
138
|
+
}
|
|
139
|
+
`);
|
|
130
140
|
return {
|
|
131
141
|
fields: createGraphQLInputField(field, `${typeName}Input`),
|
|
132
|
-
typeDefs: typeDefs.join("\n")
|
|
142
|
+
typeDefs: typeDefs.concat(templateInputIds).join("\n")
|
|
133
143
|
};
|
|
134
144
|
}
|
|
135
145
|
createResolver(params) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/graphql/fields/base/DynamicZoneToGraphQL.js","sources":["../../../../../src/features/graphql/fields/base/DynamicZoneToGraphQL.ts"],"sourcesContent":["import { CmsModelFieldToGraphQL } from \"../abstractions/CmsModelFieldToGraphQL.js\";\nimport type {\n ApiEndpoint,\n CmsDynamicZoneTemplate,\n CmsModel,\n CmsModelDynamicZoneField,\n CmsModelField,\n CmsModelFieldType,\n CmsModelFieldDefinition\n} from \"~/types/index.js\";\nimport type { ValidateChildFieldsParams } from \"../abstractions/CmsModelFieldToGraphQL.js\";\nimport type { CmsModelFieldAstNode, ICmsModelFieldToAst } from \"~/types/modelAst.js\";\nimport type { GraphQLFieldResolver } from \"@webiny/handler-graphql/types.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { createTypeName } from \"~/utils/createTypeName.js\";\nimport { createGraphQLInputField } from \"./utils/createGraphQLInputField.js\";\nimport { createTypeDefsForTemplates } from \"./dynamicZone/createTypeDefsForTemplates.js\";\nimport { normalizeDynamicZoneInput } from \"./dynamicZone/normalizeDynamicZoneInput.js\";\n\nconst createUnionTypeName = (model: CmsModel, field: CmsModelField) => {\n return `${model.singularApiName}_${createTypeName(field.fieldId)}`;\n};\n\nconst getFieldTemplates = (field: CmsModelDynamicZoneField): CmsDynamicZoneTemplate[] => {\n if (!Array.isArray(field.settings?.templates)) {\n return [];\n }\n return field.settings.templates;\n};\n\nconst remapTemplateValue = (value: any, typeName: string) => {\n return { ...value, __typename: typeName };\n};\n\nconst createDynamicZoneResolver = (\n endpointType: ApiEndpoint\n): ((params: CmsModelFieldToGraphQL.ResolverParams) => CmsModelFieldToGraphQL.Resolver) => {\n return ({ model, models, field, fieldRegistry, createFieldResolvers, graphQLType }) => {\n const dzField = field as CmsModelDynamicZoneField;\n const templates = getFieldTemplates(dzField);\n\n if (!templates.length) {\n return false;\n }\n\n const resolver = (parent: any) => {\n const value = parent[field.fieldId];\n if (!value) {\n return value;\n }\n\n const typeName = `${graphQLType}_${createTypeName(field.fieldId)}`;\n\n if (field.list && Array.isArray(value)) {\n return value.map(v => {\n const template = templates.find(tpl => tpl.id === v._templateId);\n if (!template) {\n return undefined;\n }\n return remapTemplateValue(v, `${typeName}_${template.gqlTypeName}`);\n });\n }\n\n const template = templates.find(tpl => tpl.id === value._templateId);\n if (!template) {\n return undefined;\n }\n return remapTemplateValue(value, `${typeName}_${template.gqlTypeName}`);\n };\n\n const { templateTypes } = createTypeDefsForTemplates({\n models,\n field,\n type: endpointType,\n typeOfType: \"type\",\n model,\n fieldRegistry,\n templates\n });\n\n const replace = new RegExp(`${model.singularApiName}_`, \"g\");\n\n const typeResolvers = templateTypes\n .map(templateType => {\n return templateType.replace(replace, `${graphQLType}_`);\n })\n .reduce<Record<string, Record<string, GraphQLFieldResolver>>>(\n (typeResolvers, templateType, index) => {\n return {\n ...typeResolvers,\n ...createFieldResolvers({\n graphQLType: templateType,\n fields: dzField.settings.templates[index].fields\n })\n };\n },\n {}\n );\n\n return {\n resolver,\n typeResolvers\n };\n };\n};\n\nclass ReadApi implements CmsModelFieldToGraphQL.ReadApi {\n public createTypeField({\n models,\n model,\n field,\n fieldRegistry\n }: CmsModelFieldToGraphQL.TypeFieldParams): CmsModelFieldDefinition | null {\n const dzField = field as CmsModelDynamicZoneField;\n const templates = getFieldTemplates(dzField);\n if (!templates.length) {\n return null;\n }\n\n const unionTypeName = createUnionTypeName(model, field);\n\n const { typeDefs, templateTypes } = createTypeDefsForTemplates({\n models,\n field,\n type: \"read\",\n typeOfType: \"type\",\n model,\n fieldRegistry,\n templates\n });\n\n typeDefs.unshift(`union ${unionTypeName} = ${templateTypes.join(\" | \")}`);\n\n return {\n fields: `${field.fieldId}: ${field.list ? `[${unionTypeName}!]` : unionTypeName}`,\n typeDefs: typeDefs.join(\"\\n\")\n };\n }\n\n public createResolver(\n params: CmsModelFieldToGraphQL.ResolverParams\n ): CmsModelFieldToGraphQL.Resolver {\n return createDynamicZoneResolver(\"read\")(params);\n }\n}\n\nclass ManageApi implements CmsModelFieldToGraphQL.ManageApi {\n public createTypeField({\n models,\n model,\n field,\n fieldRegistry\n }: CmsModelFieldToGraphQL.TypeFieldParams): CmsModelFieldDefinition | null {\n const dzField = field as CmsModelDynamicZoneField;\n const templates = getFieldTemplates(dzField);\n\n if (!templates.length) {\n return null;\n }\n\n const unionTypeName = createUnionTypeName(model, field);\n\n const { typeDefs, templateTypes } = createTypeDefsForTemplates({\n models,\n field,\n type: \"manage\",\n typeOfType: \"type\",\n model,\n fieldRegistry,\n templates\n });\n\n /* Add _templateId. */\n const templateIds = templateTypes.map(type => {\n return `extend type ${type} {\n _templateId: ID!\n }\n `;\n });\n\n typeDefs.unshift(`union ${unionTypeName} = ${templateTypes.join(\" | \")}`);\n\n return {\n fields: `${field.fieldId}: ${field.list ? `[${unionTypeName}!]` : unionTypeName}`,\n typeDefs: typeDefs.concat(templateIds).join(\"\\n\")\n };\n }\n\n public createInputField({\n models,\n model,\n field,\n fieldRegistry\n }: CmsModelFieldToGraphQL.TypeFieldParams): CmsModelFieldDefinition | null {\n const dzField = field as CmsModelDynamicZoneField;\n const templates = getFieldTemplates(dzField);\n\n if (!templates.length) {\n return null;\n }\n\n const { typeDefs, templateTypes } = createTypeDefsForTemplates({\n models,\n field,\n type: \"manage\",\n typeOfType: \"input\",\n model,\n fieldRegistry,\n templates\n });\n\n const typeName = `${model.singularApiName}_${createTypeName(field.fieldId)}`;\n\n const inputProperties = templateTypes.map(inputTypeName => {\n const key = inputTypeName.replace(`${typeName}_`, \"\").replace(\"Input\", \"\");\n return [key, inputTypeName];\n });\n\n /**\n * Generate a field input type, similar to this example:\n *\n * input Article_ContentInput {\n * Hero: Article_Content_HeroInput\n * SimpleText: Article_Content_SimpleTextInput\n * }\n */\n typeDefs.push(`input ${typeName}Input {\n ${inputProperties.map(\n ([key, value]) => `\n ${key}: ${value}\n `\n )}\n }`);\n\n return {\n fields: createGraphQLInputField(field, `${typeName}Input`),\n typeDefs: typeDefs.join(\"\\n\")\n };\n }\n\n public createResolver(\n params: CmsModelFieldToGraphQL.ResolverParams\n ): CmsModelFieldToGraphQL.Resolver {\n return createDynamicZoneResolver(\"manage\")(params);\n }\n\n public async normalizeInput<T>({\n field,\n input\n }: CmsModelFieldToGraphQL.InputNormalizeParams): Promise<T> {\n const dzField = field as CmsModelDynamicZoneField;\n const templates = dzField.settings?.templates || [];\n\n if (Array.isArray(input) && field.list) {\n return input\n .map(value => normalizeDynamicZoneInput(value, templates))\n .filter(Boolean) as T;\n }\n\n return normalizeDynamicZoneInput(input as GenericRecord<string>, templates) as T;\n }\n}\n\nclass DynamicZoneToGraphQL implements CmsModelFieldToGraphQL.Interface {\n public readonly read = new ReadApi();\n public readonly manage = new ManageApi();\n\n public readonly fieldType: CmsModelFieldType = \"dynamicZone\";\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 public validateChildFields(params: ValidateChildFieldsParams<CmsModelField>): void {\n const field = params.field as CmsModelDynamicZoneField;\n const originalField = params.originalField as CmsModelDynamicZoneField | undefined;\n\n const getOriginalTemplateFields = (templateId: string) => {\n if (!originalField?.settings?.templates) {\n return [];\n }\n const template = originalField.settings.templates.find(t => t.id === templateId);\n return template?.fields || [];\n };\n\n for (const template of field.settings.templates) {\n params.validate({\n fields: template.fields,\n originalFields: getOriginalTemplateFields(template.id)\n });\n }\n }\n\n public getFieldAst(field: CmsModelField, converter: ICmsModelFieldToAst): CmsModelFieldAstNode {\n const dzField = field as CmsModelDynamicZoneField;\n const { templates = [] } = dzField.settings;\n\n return {\n type: \"field\",\n field,\n children: templates.map(({ fields, ...template }) => {\n return {\n type: \"collection\" as const,\n collection: {\n ...template,\n discriminator: \"_templateId\"\n },\n children: fields.map(f => converter.toAst(f))\n };\n })\n };\n }\n}\n\nexport const DynamicZoneFieldToGraphQL = CmsModelFieldToGraphQL.createImplementation({\n implementation: DynamicZoneToGraphQL,\n dependencies: []\n});\n"],"names":["createUnionTypeName","model","field","createTypeName","getFieldTemplates","Array","remapTemplateValue","value","typeName","createDynamicZoneResolver","endpointType","models","fieldRegistry","createFieldResolvers","graphQLType","dzField","templates","resolver","parent","v","template","tpl","templateTypes","createTypeDefsForTemplates","replace","RegExp","typeResolvers","templateType","index","ReadApi","unionTypeName","typeDefs","params","ManageApi","templateIds","type","inputProperties","inputTypeName","key","createGraphQLInputField","input","normalizeDynamicZoneInput","Boolean","DynamicZoneToGraphQL","originalField","getOriginalTemplateFields","templateId","t","converter","fields","f","DynamicZoneFieldToGraphQL","CmsModelFieldToGraphQL"],"mappings":";;;;;AAmBA,MAAMA,sBAAsB,CAACC,OAAiBC,QACnC,GAAGD,MAAM,eAAe,CAAC,CAAC,EAAEE,eAAeD,MAAM,OAAO,GAAG;AAGtE,MAAME,oBAAoB,CAACF;IACvB,IAAI,CAACG,MAAM,OAAO,CAACH,MAAM,QAAQ,EAAE,YAC/B,OAAO,EAAE;IAEb,OAAOA,MAAM,QAAQ,CAAC,SAAS;AACnC;AAEA,MAAMI,qBAAqB,CAACC,OAAYC,WAC7B;QAAE,GAAGD,KAAK;QAAE,YAAYC;IAAS;AAG5C,MAAMC,4BAA4B,CAC9BC,eAEO,CAAC,EAAET,KAAK,EAAEU,MAAM,EAAET,KAAK,EAAEU,aAAa,EAAEC,oBAAoB,EAAEC,WAAW,EAAE;QAC9E,MAAMC,UAAUb;QAChB,MAAMc,YAAYZ,kBAAkBW;QAEpC,IAAI,CAACC,UAAU,MAAM,EACjB,OAAO;QAGX,MAAMC,WAAW,CAACC;YACd,MAAMX,QAAQW,MAAM,CAAChB,MAAM,OAAO,CAAC;YACnC,IAAI,CAACK,OACD,OAAOA;YAGX,MAAMC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ACpB"}
|
|
1
|
+
{"version":3,"file":"features/graphql/fields/base/DynamicZoneToGraphQL.js","sources":["../../../../../src/features/graphql/fields/base/DynamicZoneToGraphQL.ts"],"sourcesContent":["import { CmsModelFieldToGraphQL } from \"../abstractions/CmsModelFieldToGraphQL.js\";\nimport type {\n ApiEndpoint,\n CmsDynamicZoneTemplate,\n CmsModel,\n CmsModelDynamicZoneField,\n CmsModelField,\n CmsModelFieldType,\n CmsModelFieldDefinition\n} from \"~/types/index.js\";\nimport type { ValidateChildFieldsParams } from \"../abstractions/CmsModelFieldToGraphQL.js\";\nimport type { CmsModelFieldAstNode, ICmsModelFieldToAst } from \"~/types/modelAst.js\";\nimport type { GraphQLFieldResolver } from \"@webiny/handler-graphql/types.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { createTypeName } from \"~/utils/createTypeName.js\";\nimport { createGraphQLInputField } from \"./utils/createGraphQLInputField.js\";\nimport { createTypeDefsForTemplates } from \"./dynamicZone/createTypeDefsForTemplates.js\";\nimport { normalizeDynamicZoneInput } from \"./dynamicZone/normalizeDynamicZoneInput.js\";\n\nconst createUnionTypeName = (model: CmsModel, field: CmsModelField) => {\n return `${model.singularApiName}_${createTypeName(field.fieldId)}`;\n};\n\nconst getFieldTemplates = (field: CmsModelDynamicZoneField): CmsDynamicZoneTemplate[] => {\n if (!Array.isArray(field.settings?.templates)) {\n return [];\n }\n return field.settings.templates;\n};\n\nconst remapTemplateValue = (value: any, typeName: string) => {\n return { ...value, __typename: typeName };\n};\n\nconst createDynamicZoneResolver = (\n endpointType: ApiEndpoint\n): ((params: CmsModelFieldToGraphQL.ResolverParams) => CmsModelFieldToGraphQL.Resolver) => {\n return ({ model, models, field, fieldRegistry, createFieldResolvers, graphQLType }) => {\n const dzField = field as CmsModelDynamicZoneField;\n const templates = getFieldTemplates(dzField);\n\n if (!templates.length) {\n return false;\n }\n\n const resolver = (parent: any) => {\n const value = parent[field.fieldId];\n if (!value) {\n return value;\n }\n\n const typeName = `${graphQLType}_${createTypeName(field.fieldId)}`;\n\n if (field.list && Array.isArray(value)) {\n return value.map(v => {\n const template = templates.find(tpl => tpl.id === v._templateId);\n if (!template) {\n return undefined;\n }\n return remapTemplateValue(v, `${typeName}_${template.gqlTypeName}`);\n });\n }\n\n const template = templates.find(tpl => tpl.id === value._templateId);\n if (!template) {\n return undefined;\n }\n return remapTemplateValue(value, `${typeName}_${template.gqlTypeName}`);\n };\n\n const { templateTypes } = createTypeDefsForTemplates({\n models,\n field,\n type: endpointType,\n typeOfType: \"type\",\n model,\n fieldRegistry,\n templates\n });\n\n const replace = new RegExp(`${model.singularApiName}_`, \"g\");\n\n const typeResolvers = templateTypes\n .map(templateType => {\n return templateType.replace(replace, `${graphQLType}_`);\n })\n .reduce<Record<string, Record<string, GraphQLFieldResolver>>>(\n (typeResolvers, templateType, index) => {\n return {\n ...typeResolvers,\n ...createFieldResolvers({\n graphQLType: templateType,\n fields: dzField.settings.templates[index].fields\n })\n };\n },\n {}\n );\n\n return {\n resolver,\n typeResolvers\n };\n };\n};\n\nclass ReadApi implements CmsModelFieldToGraphQL.ReadApi {\n public createTypeField({\n models,\n model,\n field,\n fieldRegistry\n }: CmsModelFieldToGraphQL.TypeFieldParams): CmsModelFieldDefinition | null {\n const dzField = field as CmsModelDynamicZoneField;\n const templates = getFieldTemplates(dzField);\n if (!templates.length) {\n return null;\n }\n\n const unionTypeName = createUnionTypeName(model, field);\n\n const { typeDefs, templateTypes } = createTypeDefsForTemplates({\n models,\n field,\n type: \"read\",\n typeOfType: \"type\",\n model,\n fieldRegistry,\n templates\n });\n\n const templateIds = templateTypes.map(type => {\n return `extend type ${type} {\n _templateId: ID!\n _id: ID\n }\n `;\n });\n\n typeDefs.unshift(`union ${unionTypeName} = ${templateTypes.join(\" | \")}`);\n\n return {\n fields: `${field.fieldId}: ${field.list ? `[${unionTypeName}!]` : unionTypeName}`,\n typeDefs: typeDefs.concat(templateIds).join(\"\\n\")\n };\n }\n\n public createResolver(\n params: CmsModelFieldToGraphQL.ResolverParams\n ): CmsModelFieldToGraphQL.Resolver {\n return createDynamicZoneResolver(\"read\")(params);\n }\n}\n\nclass ManageApi implements CmsModelFieldToGraphQL.ManageApi {\n public createTypeField({\n models,\n model,\n field,\n fieldRegistry\n }: CmsModelFieldToGraphQL.TypeFieldParams): CmsModelFieldDefinition | null {\n const dzField = field as CmsModelDynamicZoneField;\n const templates = getFieldTemplates(dzField);\n\n if (!templates.length) {\n return null;\n }\n\n const unionTypeName = createUnionTypeName(model, field);\n\n const { typeDefs, templateTypes } = createTypeDefsForTemplates({\n models,\n field,\n type: \"manage\",\n typeOfType: \"type\",\n model,\n fieldRegistry,\n templates\n });\n\n /* Add _templateId and _id. */\n const templateIds = templateTypes.map(type => {\n return `extend type ${type} {\n _templateId: ID!\n _id: ID\n }\n `;\n });\n\n typeDefs.unshift(`union ${unionTypeName} = ${templateTypes.join(\" | \")}`);\n\n return {\n fields: `${field.fieldId}: ${field.list ? `[${unionTypeName}!]` : unionTypeName}`,\n typeDefs: typeDefs.concat(templateIds).join(\"\\n\")\n };\n }\n\n public createInputField({\n models,\n model,\n field,\n fieldRegistry\n }: CmsModelFieldToGraphQL.TypeFieldParams): CmsModelFieldDefinition | null {\n const dzField = field as CmsModelDynamicZoneField;\n const templates = getFieldTemplates(dzField);\n\n if (!templates.length) {\n return null;\n }\n\n const { typeDefs, templateTypes } = createTypeDefsForTemplates({\n models,\n field,\n type: \"manage\",\n typeOfType: \"input\",\n model,\n fieldRegistry,\n templates\n });\n\n const typeName = `${model.singularApiName}_${createTypeName(field.fieldId)}`;\n\n const inputProperties = templateTypes.map(inputTypeName => {\n const key = inputTypeName.replace(`${typeName}_`, \"\").replace(\"Input\", \"\");\n return [key, inputTypeName];\n });\n\n /**\n * Generate a field input type, similar to this example:\n *\n * input Article_ContentInput {\n * Hero: Article_Content_HeroInput\n * SimpleText: Article_Content_SimpleTextInput\n * }\n */\n typeDefs.push(`input ${typeName}Input {\n ${inputProperties.map(\n ([key, value]) => `\n ${key}: ${value}\n `\n )}\n }`);\n\n /* Extend each template input type with _id. */\n const templateInputIds = templateTypes.map(inputTypeName => {\n return `extend input ${inputTypeName} {\n _id: ID\n }\n `;\n });\n\n return {\n fields: createGraphQLInputField(field, `${typeName}Input`),\n typeDefs: typeDefs.concat(templateInputIds).join(\"\\n\")\n };\n }\n\n public createResolver(\n params: CmsModelFieldToGraphQL.ResolverParams\n ): CmsModelFieldToGraphQL.Resolver {\n return createDynamicZoneResolver(\"manage\")(params);\n }\n\n public async normalizeInput<T>({\n field,\n input\n }: CmsModelFieldToGraphQL.InputNormalizeParams): Promise<T> {\n const dzField = field as CmsModelDynamicZoneField;\n const templates = dzField.settings?.templates || [];\n\n if (Array.isArray(input) && field.list) {\n return input\n .map(value => normalizeDynamicZoneInput(value, templates))\n .filter(Boolean) as T;\n }\n\n return normalizeDynamicZoneInput(input as GenericRecord<string>, templates) as T;\n }\n}\n\nclass DynamicZoneToGraphQL implements CmsModelFieldToGraphQL.Interface {\n public readonly read = new ReadApi();\n public readonly manage = new ManageApi();\n\n public readonly fieldType: CmsModelFieldType = \"dynamicZone\";\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 public validateChildFields(params: ValidateChildFieldsParams<CmsModelField>): void {\n const field = params.field as CmsModelDynamicZoneField;\n const originalField = params.originalField as CmsModelDynamicZoneField | undefined;\n\n const getOriginalTemplateFields = (templateId: string) => {\n if (!originalField?.settings?.templates) {\n return [];\n }\n const template = originalField.settings.templates.find(t => t.id === templateId);\n return template?.fields || [];\n };\n\n for (const template of field.settings.templates) {\n params.validate({\n fields: template.fields,\n originalFields: getOriginalTemplateFields(template.id)\n });\n }\n }\n\n public getFieldAst(field: CmsModelField, converter: ICmsModelFieldToAst): CmsModelFieldAstNode {\n const dzField = field as CmsModelDynamicZoneField;\n const { templates = [] } = dzField.settings;\n\n return {\n type: \"field\",\n field,\n children: templates.map(({ fields, ...template }) => {\n return {\n type: \"collection\" as const,\n collection: {\n ...template,\n discriminator: \"_templateId\"\n },\n children: fields.map(f => converter.toAst(f))\n };\n })\n };\n }\n}\n\nexport const DynamicZoneFieldToGraphQL = CmsModelFieldToGraphQL.createImplementation({\n implementation: DynamicZoneToGraphQL,\n dependencies: []\n});\n"],"names":["createUnionTypeName","model","field","createTypeName","getFieldTemplates","Array","remapTemplateValue","value","typeName","createDynamicZoneResolver","endpointType","models","fieldRegistry","createFieldResolvers","graphQLType","dzField","templates","resolver","parent","v","template","tpl","templateTypes","createTypeDefsForTemplates","replace","RegExp","typeResolvers","templateType","index","ReadApi","unionTypeName","typeDefs","templateIds","type","params","ManageApi","inputProperties","inputTypeName","key","templateInputIds","createGraphQLInputField","input","normalizeDynamicZoneInput","Boolean","DynamicZoneToGraphQL","originalField","getOriginalTemplateFields","templateId","t","converter","fields","f","DynamicZoneFieldToGraphQL","CmsModelFieldToGraphQL"],"mappings":";;;;;AAmBA,MAAMA,sBAAsB,CAACC,OAAiBC,QACnC,GAAGD,MAAM,eAAe,CAAC,CAAC,EAAEE,eAAeD,MAAM,OAAO,GAAG;AAGtE,MAAME,oBAAoB,CAACF;IACvB,IAAI,CAACG,MAAM,OAAO,CAACH,MAAM,QAAQ,EAAE,YAC/B,OAAO,EAAE;IAEb,OAAOA,MAAM,QAAQ,CAAC,SAAS;AACnC;AAEA,MAAMI,qBAAqB,CAACC,OAAYC,WAC7B;QAAE,GAAGD,KAAK;QAAE,YAAYC;IAAS;AAG5C,MAAMC,4BAA4B,CAC9BC,eAEO,CAAC,EAAET,KAAK,EAAEU,MAAM,EAAET,KAAK,EAAEU,aAAa,EAAEC,oBAAoB,EAAEC,WAAW,EAAE;QAC9E,MAAMC,UAAUb;QAChB,MAAMc,YAAYZ,kBAAkBW;QAEpC,IAAI,CAACC,UAAU,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