@webiny/api-headless-cms 6.4.12-beta.5 → 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/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.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/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.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/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 +7 -5
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js +48 -18
- 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 +7 -3
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js +73 -30
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/abstractions.d.ts +15 -1
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/abstractions.js.map +1 -1
- package/features/contentEntry/entryDataFactories/expiresAt.js +2 -2
- package/features/contentEntry/entryDataFactories/expiresAt.js.map +1 -1
- package/features/contentEntry/entryDataFactories/hasEntryContentChanged.d.ts +24 -0
- package/features/contentEntry/entryDataFactories/hasEntryContentChanged.js +13 -0
- package/features/contentEntry/entryDataFactories/hasEntryContentChanged.js.map +1 -0
- package/features/contentModel/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 +153 -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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentModel/CreateModelFrom/CreateModelFromRepository.js","sources":["../../../../src/features/contentModel/CreateModelFrom/CreateModelFromRepository.ts"],"sourcesContent":["import camelCase from \"lodash/camelCase.js\";\nimport { Result } from \"@webiny/feature/api\";\nimport { CreateModelFromRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport {\n ModelCache,\n ModelsFetcher,\n PluginModelsProvider\n} from \"~/features/contentModel/shared/abstractions.js\";\nimport {\n ModelAlreadyExistsError,\n ModelPersistenceError,\n ModelValidationError\n} from \"~/domain/contentModel/errors.js\";\nimport { CmsContext, StorageOperations } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport {\n validateExistingModelId,\n validateModelIdAllowed\n} from \"~/crud/contentModel/validate/modelId.js\";\nimport { validateEndingAllowed } from \"~/crud/contentModel/validate/endingAllowed.js\";\nimport { validateSingularApiName } from \"~/domain/contentModel/validation/singularApiName.js\";\nimport { validatePluralApiName } from \"~/domain/contentModel/validation/pluralApiName.js\";\nimport { validateModelFields } from \"~/domain/contentModel/validation/modelFields.js\";\nimport type { CmsModel } from \"~/types/index.js\";\nimport { ensureTypeTag } from \"~/domain/contentModel/ensureTypeTag.js\";\nimport { ModelFieldCompression } from \"~/features/contentModel/ModelFieldCompression/index.js\";\nimport { RuntimeTenant } from \"~/features/runtimeTenant/abstractions.js\";\n\n/**\n * Generate modelId from model following the exact logic from beforeCreate.ts\n */\nconst getModelId = (model: { modelId?: string; name?: string }): string => {\n const { modelId, name } = model;\n const value = modelId ? modelId.trim() : null;\n if (value) {\n const isModelIdValid = camelCase(value).toLowerCase() === value.toLowerCase();\n if (isModelIdValid) {\n return value;\n }\n return camelCase(value);\n } else if (name) {\n return camelCase(name.trim());\n }\n throw new ModelValidationError(\n `There is no \"modelId\" or \"name\" passed into the create model from method.`\n );\n};\n\n/**\n * CreateModelFromRepository - Validates domain rules and persists cloned model.\n *\n * Responsibilities:\n * - Generate modelId from input\n * - Validate modelId is allowed (not in disallowed list)\n * - Validate API name endings\n * - Validate modelId uniqueness (database + plugins)\n * - Validate API name uniqueness (database + plugins)\n * - Validate plugin conflicts\n * - Validate model fields\n * - Persist to storage\n * - Clear ModelCache after successful create\n */\nclass CreateModelFromRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private readonly modelCache: ModelCache.Interface,\n private readonly pluginModelsProvider: PluginModelsProvider.Interface,\n private readonly modelsFetcher: ModelsFetcher.Interface,\n private readonly storageOperations: StorageOperations.Interface,\n private readonly tenantContext: TenantContext.Interface,\n private readonly cmsContext: CmsContext.Interface,\n private readonly modelFieldCompression: ModelFieldCompression.Interface,\n private readonly runtimeTenant: RuntimeTenant.Interface\n ) {}\n\n async execute(initialModel: CmsModel): Promise<Result<CmsModel, RepositoryAbstraction.Error>> {\n const model = this.runtimeTenant.assign(initialModel);\n try {\n const tenant = this.tenantContext.getTenant();\n\n // Generate modelId using the exact logic from beforeCreate.ts\n const modelId = getModelId(model);\n model.modelId = modelId;\n\n // Validate modelId is allowed (not in disallowed list)\n try {\n validateModelIdAllowed({ model });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({ message: error.message, data: error.data })\n );\n }\n\n // Validate API name endings\n try {\n validateEndingAllowed({ model });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({ message: error.message, data: error.data })\n );\n }\n\n // Validate modelId uniqueness (database)\n const modelsResult = await this.modelsFetcher.fetchAll();\n if (modelsResult.isFail()) {\n return Result.fail(new ModelPersistenceError(modelsResult.error));\n }\n\n const existingModel = modelsResult.value.find(m => m.modelId === modelId);\n if (existingModel) {\n return Result.fail(new ModelAlreadyExistsError({ modelId }));\n }\n\n // Check for plugin model conflicts\n const pluginModels = await this.pluginModelsProvider.list(tenant.id);\n const pluginModelConflict = pluginModels.find(pm => {\n return (\n pm.modelId === model.modelId ||\n pm.singularApiName === model.singularApiName ||\n pm.pluralApiName === model.pluralApiName\n );\n });\n\n if (pluginModelConflict) {\n return Result.fail(\n new ModelAlreadyExistsError({\n modelId,\n message: `Model \"${modelId}\" is already registered via a plugin.`\n })\n );\n }\n\n const models = modelsResult.value;\n\n try {\n // Validate uniqueness\n for (const existingModel of models) {\n validateExistingModelId({\n existingModel,\n model\n });\n validateSingularApiName({\n existingModel,\n model\n });\n validatePluralApiName({\n existingModel,\n model\n });\n }\n\n // Validate model fields\n await validateModelFields({\n models,\n model,\n context: this.cmsContext\n });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({ message: error.message, data: error.data })\n );\n }\n\n // Ensure type tags\n model.tags = ensureTypeTag(model);\n\n const fields = await this.modelFieldCompression.compress(model.fields);\n\n // Persist to storage\n await this.storageOperations.models.create({\n model: {\n ...model,\n fields\n }\n });\n\n // Clear cache\n this.modelCache.clear();\n\n return Result.ok(model);\n } catch (error) {\n return Result.fail(new ModelPersistenceError(error as Error));\n }\n }\n}\n\nexport const CreateModelFromRepository = RepositoryAbstraction.createImplementation({\n implementation: CreateModelFromRepositoryImpl,\n dependencies: [\n ModelCache,\n PluginModelsProvider,\n ModelsFetcher,\n StorageOperations,\n TenantContext,\n CmsContext,\n ModelFieldCompression,\n RuntimeTenant\n ]\n});\n"],"names":["getModelId","model","modelId","name","value","isModelIdValid","camelCase","ModelValidationError","CreateModelFromRepositoryImpl","modelCache","pluginModelsProvider","modelsFetcher","storageOperations","tenantContext","cmsContext","modelFieldCompression","runtimeTenant","initialModel","tenant","validateModelIdAllowed","error","Result","validateEndingAllowed","modelsResult","ModelPersistenceError","existingModel","m","ModelAlreadyExistsError","pluginModels","pluginModelConflict","pm","models","validateExistingModelId","validateSingularApiName","validatePluralApiName","validateModelFields","ensureTypeTag","fields","CreateModelFromRepository","RepositoryAbstraction","ModelCache","PluginModelsProvider","ModelsFetcher","StorageOperations","TenantContext","CmsContext","ModelFieldCompression","RuntimeTenant"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"features/contentModel/CreateModelFrom/CreateModelFromRepository.js","sources":["../../../../src/features/contentModel/CreateModelFrom/CreateModelFromRepository.ts"],"sourcesContent":["import camelCase from \"lodash/camelCase.js\";\nimport { Result } from \"@webiny/feature/api\";\nimport { CreateModelFromRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport {\n ModelCache,\n ModelsFetcher,\n PluginModelsProvider\n} from \"~/features/contentModel/shared/abstractions.js\";\nimport {\n ModelAlreadyExistsError,\n ModelPersistenceError,\n ModelValidationError\n} from \"~/domain/contentModel/errors.js\";\nimport { CmsContext, StorageOperations } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport {\n validateExistingModelId,\n validateModelIdAllowed\n} from \"~/crud/contentModel/validate/modelId.js\";\nimport { validateEndingAllowed } from \"~/crud/contentModel/validate/endingAllowed.js\";\nimport { validateSingularApiName } from \"~/domain/contentModel/validation/singularApiName.js\";\nimport { validatePluralApiName } from \"~/domain/contentModel/validation/pluralApiName.js\";\nimport { validateModelFields } from \"~/domain/contentModel/validation/modelFields.js\";\nimport type { CmsModel } from \"~/types/index.js\";\nimport { ensureTypeTag } from \"~/domain/contentModel/ensureTypeTag.js\";\nimport { ModelFieldCompression } from \"~/features/contentModel/ModelFieldCompression/index.js\";\nimport { RuntimeTenant } from \"~/features/runtimeTenant/abstractions.js\";\n\n/**\n * Generate modelId from model following the exact logic from beforeCreate.ts\n */\nconst getModelId = (model: { modelId?: string; name?: string }): string => {\n const { modelId, name } = model;\n const value = modelId ? modelId.trim() : null;\n if (value) {\n const isModelIdValid = camelCase(value).toLowerCase() === value.toLowerCase();\n if (isModelIdValid) {\n return value;\n }\n return camelCase(value);\n } else if (name) {\n return camelCase(name.trim());\n }\n throw new ModelValidationError(\n `There is no \"modelId\" or \"name\" passed into the create model from method.`\n );\n};\n\n/**\n * CreateModelFromRepository - Validates domain rules and persists cloned model.\n *\n * Responsibilities:\n * - Generate modelId from input\n * - Validate modelId is allowed (not in disallowed list)\n * - Validate API name endings\n * - Validate modelId uniqueness (database + plugins)\n * - Validate API name uniqueness (database + plugins)\n * - Validate plugin conflicts\n * - Validate model fields\n * - Persist to storage\n * - Clear ModelCache after successful create\n */\nclass CreateModelFromRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private readonly modelCache: ModelCache.Interface,\n private readonly pluginModelsProvider: PluginModelsProvider.Interface,\n private readonly modelsFetcher: ModelsFetcher.Interface,\n private readonly storageOperations: StorageOperations.Interface,\n private readonly tenantContext: TenantContext.Interface,\n private readonly cmsContext: CmsContext.Interface,\n private readonly modelFieldCompression: ModelFieldCompression.Interface,\n private readonly runtimeTenant: RuntimeTenant.Interface\n ) {}\n\n async execute(initialModel: CmsModel): Promise<Result<CmsModel, RepositoryAbstraction.Error>> {\n const model = this.runtimeTenant.assign(initialModel);\n try {\n const tenant = this.tenantContext.getTenant();\n\n // Generate modelId using the exact logic from beforeCreate.ts\n const modelId = getModelId(model);\n model.modelId = modelId;\n\n // Validate modelId is allowed (not in disallowed list)\n try {\n validateModelIdAllowed({ model });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({ message: error.message, data: error.data })\n );\n }\n\n // Validate API name endings\n try {\n validateEndingAllowed({ model });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({ message: error.message, data: error.data })\n );\n }\n\n // Validate modelId uniqueness (database)\n const modelsResult = await this.modelsFetcher.fetchAll();\n if (modelsResult.isFail()) {\n return Result.fail(new ModelPersistenceError(modelsResult.error));\n }\n\n const existingModel = modelsResult.value.find(m => m.modelId === modelId);\n if (existingModel) {\n return Result.fail(new ModelAlreadyExistsError({ modelId }));\n }\n\n // Check for plugin model conflicts\n const pluginModels = await this.pluginModelsProvider.list(tenant.id);\n const pluginModelConflict = pluginModels.find(pm => {\n return (\n pm.modelId === model.modelId ||\n pm.singularApiName === model.singularApiName ||\n pm.pluralApiName === model.pluralApiName\n );\n });\n\n if (pluginModelConflict) {\n return Result.fail(\n new ModelAlreadyExistsError({\n modelId,\n message: `Model \"${modelId}\" is already registered via a plugin.`\n })\n );\n }\n\n const models = modelsResult.value;\n\n try {\n // Validate uniqueness\n for (const existingModel of models) {\n validateExistingModelId({\n existingModel,\n model\n });\n validateSingularApiName({\n existingModel,\n model\n });\n validatePluralApiName({\n existingModel,\n model\n });\n }\n\n // Validate model fields\n await validateModelFields({\n models,\n model,\n context: this.cmsContext\n });\n } catch (error) {\n return Result.fail(\n new ModelValidationError({ message: error.message, data: error.data })\n );\n }\n\n // Ensure type tags\n model.tags = ensureTypeTag(model);\n\n const fields = await this.modelFieldCompression.compress(model.fields);\n\n // Persist to storage\n await this.storageOperations.models.create({\n model: {\n ...model,\n fields\n }\n });\n\n // Clear cache\n this.modelCache.clear();\n\n return Result.ok(model);\n } catch (error) {\n return Result.fail(new ModelPersistenceError(error as Error));\n }\n }\n}\n\nexport const CreateModelFromRepository = RepositoryAbstraction.createImplementation({\n implementation: CreateModelFromRepositoryImpl,\n dependencies: [\n ModelCache,\n PluginModelsProvider,\n ModelsFetcher,\n StorageOperations,\n TenantContext,\n CmsContext,\n ModelFieldCompression,\n RuntimeTenant\n ]\n});\n"],"names":["getModelId","model","modelId","name","value","isModelIdValid","camelCase","ModelValidationError","CreateModelFromRepositoryImpl","modelCache","pluginModelsProvider","modelsFetcher","storageOperations","tenantContext","cmsContext","modelFieldCompression","runtimeTenant","initialModel","tenant","validateModelIdAllowed","error","Result","validateEndingAllowed","modelsResult","ModelPersistenceError","existingModel","m","ModelAlreadyExistsError","pluginModels","pluginModelConflict","pm","models","validateExistingModelId","validateSingularApiName","validatePluralApiName","validateModelFields","ensureTypeTag","fields","CreateModelFromRepository","RepositoryAbstraction","ModelCache","PluginModelsProvider","ModelsFetcher","StorageOperations","TenantContext","CmsContext","ModelFieldCompression","RuntimeTenant"],"mappings":"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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type IRefModelsGenerator, type RefModelMetadata } 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
|
+
import type { CmsModel } from "../../../types/index.js";
|
|
6
|
+
declare class RefModelsGeneratorImpl implements IRefModelsGenerator {
|
|
7
|
+
private readonly modelToAst;
|
|
8
|
+
private readonly modelsFetcher;
|
|
9
|
+
private readonly valuesSelectionGenerator;
|
|
10
|
+
constructor(modelToAst: ModelToAstConverter.Interface, modelsFetcher: ModelsFetcher.Interface, valuesSelectionGenerator: ValuesSelectionGenerator.Interface);
|
|
11
|
+
generate(model: CmsModel): Promise<Record<string, RefModelMetadata>>;
|
|
12
|
+
private collectRefModelIds;
|
|
13
|
+
private collectFromFieldNode;
|
|
14
|
+
private collectFromCollectionNode;
|
|
15
|
+
}
|
|
16
|
+
export declare const RefModelsGenerator: typeof RefModelsGeneratorImpl & {
|
|
17
|
+
__abstraction: import("@webiny/di").Abstraction<IRefModelsGenerator>;
|
|
18
|
+
};
|
|
19
|
+
export {};
|
|
@@ -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 mimeType size width height 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 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"}
|
|
@@ -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,153 @@
|
|
|
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
|
+
mimeType: String!
|
|
74
|
+
size: Number!
|
|
75
|
+
# Same as image.width/image.height, kept at the root for 6.4 frontends.
|
|
76
|
+
width: Number
|
|
77
|
+
height: Number
|
|
78
|
+
image: FmAssetImage
|
|
79
|
+
document: FmAssetDocument
|
|
80
|
+
video: FmAssetVideo
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
input FmAssetInput {
|
|
84
|
+
id: String!
|
|
85
|
+
src: String!
|
|
86
|
+
# TODO: figure out how to remove this from here, as this is a derived read-only value.
|
|
87
|
+
url: String
|
|
88
|
+
name: String!
|
|
89
|
+
mimeType: String!
|
|
90
|
+
size: Number!
|
|
91
|
+
width: Number
|
|
92
|
+
height: Number
|
|
93
|
+
image: FmAssetImageInput
|
|
94
|
+
document: FmAssetDocumentInput
|
|
95
|
+
video: FmAssetVideoInput
|
|
96
|
+
}
|
|
97
|
+
`;
|
|
98
|
+
const allTypeDefs = [
|
|
99
|
+
imageTypeDefs,
|
|
100
|
+
documentTypeDefs,
|
|
101
|
+
videoTypeDefs,
|
|
102
|
+
baseTypeDefs
|
|
103
|
+
].join("\n");
|
|
104
|
+
class ReadApi {
|
|
105
|
+
createTypeField({ field }) {
|
|
106
|
+
if (field.list) return `${field.fieldId}: [FmAsset]`;
|
|
107
|
+
return `${field.fieldId}: FmAsset`;
|
|
108
|
+
}
|
|
109
|
+
createResolver() {
|
|
110
|
+
return {
|
|
111
|
+
resolver: null,
|
|
112
|
+
typeResolvers: {
|
|
113
|
+
FmAsset: {
|
|
114
|
+
url: (parent)=>resolveAssetUrl(parent)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
createSchema() {
|
|
120
|
+
return {
|
|
121
|
+
typeDefs: allTypeDefs,
|
|
122
|
+
resolvers: {}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
class ManageApi extends ReadApi {
|
|
127
|
+
createInputField({ field }) {
|
|
128
|
+
return createGraphQLInputField(field, "FmAssetInput");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
class AssetToGraphQL {
|
|
132
|
+
getReadApi() {
|
|
133
|
+
return this.read;
|
|
134
|
+
}
|
|
135
|
+
getManageApi() {
|
|
136
|
+
return this.manage;
|
|
137
|
+
}
|
|
138
|
+
constructor(){
|
|
139
|
+
this.read = new ReadApi();
|
|
140
|
+
this.manage = new ManageApi();
|
|
141
|
+
this.fieldType = "asset";
|
|
142
|
+
this.isSearchable = false;
|
|
143
|
+
this.isSortable = false;
|
|
144
|
+
this.isFullTextSearchable = false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const AssetFieldToGraphQL = CmsModelFieldToGraphQL.createImplementation({
|
|
148
|
+
implementation: AssetToGraphQL,
|
|
149
|
+
dependencies: []
|
|
150
|
+
});
|
|
151
|
+
export { AssetFieldToGraphQL };
|
|
152
|
+
|
|
153
|
+
//# 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 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"}
|
|
@@ -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) {
|