@webiny/api-headless-cms 0.0.0-unstable.9f53ea597d → 0.0.0-unstable.a4f3e4ea8b
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.crud.js +12 -39
- package/crud/contentEntry.crud.js.map +1 -1
- package/features/contentEntry/ContentEntriesFeature.js +4 -0
- package/features/contentEntry/ContentEntriesFeature.js.map +1 -1
- package/features/contentEntry/CreateEntry/CreateEntryRepository.d.ts +4 -2
- package/features/contentEntry/CreateEntry/CreateEntryRepository.js +8 -3
- package/features/contentEntry/CreateEntry/CreateEntryRepository.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/CreateEntryRevisionFromRepository.d.ts +4 -2
- package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromRepository.js +8 -3
- package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromRepository.js.map +1 -1
- package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromUseCase.js.map +1 -1
- package/features/contentEntry/DeleteEntry/DeleteEntryRepository.d.ts +4 -2
- package/features/contentEntry/DeleteEntry/DeleteEntryRepository.js +8 -3
- package/features/contentEntry/DeleteEntry/DeleteEntryRepository.js.map +1 -1
- package/features/contentEntry/DeleteEntry/MoveEntryToBinRepository.d.ts +3 -1
- package/features/contentEntry/DeleteEntry/MoveEntryToBinRepository.js +8 -3
- package/features/contentEntry/DeleteEntry/MoveEntryToBinRepository.js.map +1 -1
- package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionRepository.d.ts +3 -1
- package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionRepository.js +9 -3
- package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionRepository.js.map +1 -1
- package/features/contentEntry/DeleteMultipleEntries/DeleteMultipleEntriesRepository.d.ts +4 -2
- package/features/contentEntry/DeleteMultipleEntries/DeleteMultipleEntriesRepository.js +7 -3
- package/features/contentEntry/DeleteMultipleEntries/DeleteMultipleEntriesRepository.js.map +1 -1
- package/features/contentEntry/GetEntriesByIds/GetEntriesByIdsRepository.d.ts +4 -4
- package/features/contentEntry/GetEntriesByIds/GetEntriesByIdsRepository.js +8 -11
- package/features/contentEntry/GetEntriesByIds/GetEntriesByIdsRepository.js.map +1 -1
- package/features/contentEntry/GetLatestEntriesByIds/GetLatestEntriesByIdsRepository.d.ts +4 -2
- package/features/contentEntry/GetLatestEntriesByIds/GetLatestEntriesByIdsRepository.js +7 -3
- package/features/contentEntry/GetLatestEntriesByIds/GetLatestEntriesByIdsRepository.js.map +1 -1
- package/features/contentEntry/GetLatestRevisionByEntryId/GetLatestRevisionByEntryIdRepository.d.ts +4 -2
- package/features/contentEntry/GetLatestRevisionByEntryId/GetLatestRevisionByEntryIdRepository.js +7 -3
- package/features/contentEntry/GetLatestRevisionByEntryId/GetLatestRevisionByEntryIdRepository.js.map +1 -1
- package/features/contentEntry/GetPreviousRevisionByEntryId/GetPreviousRevisionByEntryIdRepository.d.ts +4 -2
- package/features/contentEntry/GetPreviousRevisionByEntryId/GetPreviousRevisionByEntryIdRepository.js +7 -3
- package/features/contentEntry/GetPreviousRevisionByEntryId/GetPreviousRevisionByEntryIdRepository.js.map +1 -1
- package/features/contentEntry/GetPublishedEntriesByIds/GetPublishedEntriesByIdsRepository.d.ts +4 -2
- package/features/contentEntry/GetPublishedEntriesByIds/GetPublishedEntriesByIdsRepository.js +7 -3
- package/features/contentEntry/GetPublishedEntriesByIds/GetPublishedEntriesByIdsRepository.js.map +1 -1
- package/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdRepository.d.ts +4 -2
- package/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdRepository.js +7 -3
- package/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdRepository.js.map +1 -1
- package/features/contentEntry/GetRevisionById/GetRevisionByIdRepository.d.ts +4 -2
- package/features/contentEntry/GetRevisionById/GetRevisionByIdRepository.js +7 -3
- package/features/contentEntry/GetRevisionById/GetRevisionByIdRepository.js.map +1 -1
- package/features/contentEntry/GetRevisionsByEntryId/GetRevisionsByEntryIdRepository.d.ts +4 -2
- package/features/contentEntry/GetRevisionsByEntryId/GetRevisionsByEntryIdRepository.js +7 -3
- package/features/contentEntry/GetRevisionsByEntryId/GetRevisionsByEntryIdRepository.js.map +1 -1
- package/features/contentEntry/GetUniqueFieldValues/GetUniqueFieldValuesRepository.d.ts +4 -2
- package/features/contentEntry/GetUniqueFieldValues/GetUniqueFieldValuesRepository.js +7 -3
- package/features/contentEntry/GetUniqueFieldValues/GetUniqueFieldValuesRepository.js.map +1 -1
- package/features/contentEntry/ListEntries/ListEntriesRepository.d.ts +4 -2
- package/features/contentEntry/ListEntries/ListEntriesRepository.js +7 -3
- package/features/contentEntry/ListEntries/ListEntriesRepository.js.map +1 -1
- package/features/contentEntry/MoveEntry/MoveEntryRepository.d.ts +4 -2
- package/features/contentEntry/MoveEntry/MoveEntryRepository.js +7 -3
- package/features/contentEntry/MoveEntry/MoveEntryRepository.js.map +1 -1
- package/features/contentEntry/PublishEntry/PublishEntryRepository.d.ts +4 -2
- package/features/contentEntry/PublishEntry/PublishEntryRepository.js +8 -3
- package/features/contentEntry/PublishEntry/PublishEntryRepository.js.map +1 -1
- package/features/contentEntry/PublishEntry/PublishEntryUseCase.js.map +1 -1
- package/features/contentEntry/RepublishEntry/RepublishEntryRepository.d.ts +4 -2
- package/features/contentEntry/RepublishEntry/RepublishEntryRepository.js +8 -3
- package/features/contentEntry/RepublishEntry/RepublishEntryRepository.js.map +1 -1
- package/features/contentEntry/RestoreEntryFromBin/RestoreEntryFromBinRepository.d.ts +4 -2
- package/features/contentEntry/RestoreEntryFromBin/RestoreEntryFromBinRepository.js +8 -3
- package/features/contentEntry/RestoreEntryFromBin/RestoreEntryFromBinRepository.js.map +1 -1
- package/features/contentEntry/UnpublishEntry/UnpublishEntryRepository.d.ts +4 -2
- package/features/contentEntry/UnpublishEntry/UnpublishEntryRepository.js +8 -3
- package/features/contentEntry/UnpublishEntry/UnpublishEntryRepository.js.map +1 -1
- package/features/contentEntry/UpdateEntry/UpdateEntryRepository.d.ts +4 -2
- package/features/contentEntry/UpdateEntry/UpdateEntryRepository.js +8 -3
- package/features/contentEntry/UpdateEntry/UpdateEntryRepository.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 +8 -2
- package/features/contentEntry/entryDataFactories/CreateEntryDataFactory/CreateEntryDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.d.ts +3 -1
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js +8 -2
- 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 +8 -2
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js.map +1 -1
- package/features/contentModel/CreateModel/CreateModelRepository.d.ts +4 -2
- package/features/contentModel/CreateModel/CreateModelRepository.js +8 -4
- package/features/contentModel/CreateModel/CreateModelRepository.js.map +1 -1
- package/features/contentModel/CreateModel/CreateModelUseCase.js +2 -2
- package/features/contentModel/CreateModel/CreateModelUseCase.js.map +1 -1
- package/features/contentModel/CreateModel/abstractions.d.ts +1 -1
- package/features/contentModel/CreateModel/abstractions.js.map +1 -1
- package/features/contentModel/CreateModelFrom/CreateModelFromRepository.d.ts +4 -2
- package/features/contentModel/CreateModelFrom/CreateModelFromRepository.js +8 -4
- package/features/contentModel/CreateModelFrom/CreateModelFromRepository.js.map +1 -1
- package/features/contentModel/CreateModelFrom/CreateModelFromUseCase.js +2 -2
- package/features/contentModel/CreateModelFrom/CreateModelFromUseCase.js.map +1 -1
- package/features/contentModel/CreateModelFrom/abstractions.d.ts +1 -1
- package/features/contentModel/CreateModelFrom/abstractions.js.map +1 -1
- package/features/contentModel/DeleteModel/DeleteModelRepository.d.ts +4 -2
- package/features/contentModel/DeleteModel/DeleteModelRepository.js +7 -3
- package/features/contentModel/DeleteModel/DeleteModelRepository.js.map +1 -1
- package/features/contentModel/UpdateModel/UpdateModelRepository.d.ts +4 -2
- package/features/contentModel/UpdateModel/UpdateModelRepository.js +8 -4
- package/features/contentModel/UpdateModel/UpdateModelRepository.js.map +1 -1
- package/features/contentModel/UpdateModel/UpdateModelUseCase.js +2 -2
- package/features/contentModel/UpdateModel/UpdateModelUseCase.js.map +1 -1
- package/features/contentModel/UpdateModel/abstractions.d.ts +1 -1
- package/features/contentModel/UpdateModel/abstractions.js.map +1 -1
- package/features/contentModel/ValuesSelectionGenerator/ValuesSelectionGenerator.js +3 -2
- package/features/contentModel/ValuesSelectionGenerator/ValuesSelectionGenerator.js.map +1 -1
- package/features/contentModelGroup/CreateGroup/CreateGroupRepository.d.ts +4 -2
- package/features/contentModelGroup/CreateGroup/CreateGroupRepository.js +8 -4
- package/features/contentModelGroup/CreateGroup/CreateGroupRepository.js.map +1 -1
- package/features/contentModelGroup/CreateGroup/CreateGroupUseCase.d.ts +1 -3
- package/features/contentModelGroup/CreateGroup/CreateGroupUseCase.js +5 -7
- package/features/contentModelGroup/CreateGroup/CreateGroupUseCase.js.map +1 -1
- package/features/contentModelGroup/CreateGroup/abstractions.d.ts +1 -1
- package/features/contentModelGroup/CreateGroup/abstractions.js.map +1 -1
- package/features/contentModelGroup/DeleteGroup/DeleteGroupRepository.d.ts +4 -2
- package/features/contentModelGroup/DeleteGroup/DeleteGroupRepository.js +7 -3
- package/features/contentModelGroup/DeleteGroup/DeleteGroupRepository.js.map +1 -1
- package/features/contentModelGroup/UpdateGroup/UpdateGroupRepository.d.ts +4 -2
- package/features/contentModelGroup/UpdateGroup/UpdateGroupRepository.js +8 -4
- package/features/contentModelGroup/UpdateGroup/UpdateGroupRepository.js.map +1 -1
- package/features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.js +2 -2
- package/features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.js.map +1 -1
- package/features/contentModelGroup/UpdateGroup/abstractions.d.ts +1 -1
- package/features/contentModelGroup/UpdateGroup/abstractions.js.map +1 -1
- package/features/graphql/fields/base/DynamicZoneToGraphQL.js +7 -1
- package/features/graphql/fields/base/DynamicZoneToGraphQL.js.map +1 -1
- package/features/graphql/fields/base/ObjectToGraphQL.js +6 -3
- package/features/graphql/fields/base/ObjectToGraphQL.js.map +1 -1
- package/features/graphql/fields/base/RefToGraphQL.js +17 -7
- package/features/graphql/fields/base/RefToGraphQL.js.map +1 -1
- package/features/modelBuilder/abstractions.d.ts +1 -2
- package/features/modelBuilder/abstractions.js.map +1 -1
- package/features/runtimeTenant/RuntimeTenant.d.ts +13 -0
- package/features/runtimeTenant/RuntimeTenant.js +22 -0
- package/features/runtimeTenant/RuntimeTenant.js.map +1 -0
- package/features/runtimeTenant/abstractions.d.ts +11 -0
- package/features/runtimeTenant/abstractions.js +5 -0
- package/features/runtimeTenant/abstractions.js.map +1 -0
- package/features/runtimeTenant/index.d.ts +2 -0
- package/features/runtimeTenant/index.js +2 -0
- package/features/sortMapper/SortMapper.js +2 -5
- package/features/sortMapper/SortMapper.js.map +1 -1
- package/features/storage/fields/ObjectStorageTransform.js +27 -7
- package/features/storage/fields/ObjectStorageTransform.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 +7 -5
- package/features/whereMapper/WhereMapper.js.map +1 -1
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +15 -5
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +8 -2
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
- package/package.json +18 -18
- package/types/types.d.ts +4 -0
- package/types/types.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentModelGroup/CreateGroup/CreateGroupRepository.js","sources":["../../../../src/features/contentModelGroup/CreateGroup/CreateGroupRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { CreateGroupRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { GroupCache } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { PluginGroupsProvider } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { GroupSlugTakenError } from \"~/domain/contentModelGroup/errors.js\";\nimport { GroupPersistenceError } from \"~/domain/contentModelGroup/errors.js\";\nimport { StorageOperations } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { toSlug } from \"~/utils/toSlug.js\";\nimport { generateAlphaNumericId } from \"@webiny/utils\";\nimport type { CmsGroup } from \"~/types/index.js\";\n\n/**\n * CreateGroupRepository - Validates and persists a new group.\n *\n * Responsibilities:\n * - Validate ID uniqueness (if provided)\n * - Validate slug uniqueness (or generate unique slug)\n * - Check for plugin group conflicts\n * - Persist to storage\n * - Clear GroupCache after successful create\n */\nclass CreateGroupRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private groupCache: GroupCache.Interface,\n private pluginGroupsProvider: PluginGroupsProvider.Interface,\n private storageOperations: StorageOperations.Interface,\n private tenantContext: TenantContext.Interface\n ) {}\n\n async execute(
|
|
1
|
+
{"version":3,"file":"features/contentModelGroup/CreateGroup/CreateGroupRepository.js","sources":["../../../../src/features/contentModelGroup/CreateGroup/CreateGroupRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { CreateGroupRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { GroupCache } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { PluginGroupsProvider } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { GroupSlugTakenError } from \"~/domain/contentModelGroup/errors.js\";\nimport { GroupPersistenceError } from \"~/domain/contentModelGroup/errors.js\";\nimport { StorageOperations } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { toSlug } from \"~/utils/toSlug.js\";\nimport { generateAlphaNumericId } from \"@webiny/utils\";\nimport type { CmsGroup } from \"~/types/index.js\";\nimport { RuntimeTenant } from \"~/features/runtimeTenant/abstractions.js\";\n\n/**\n * CreateGroupRepository - Validates and persists a new group.\n *\n * Responsibilities:\n * - Validate ID uniqueness (if provided)\n * - Validate slug uniqueness (or generate unique slug)\n * - Check for plugin group conflicts\n * - Persist to storage\n * - Clear GroupCache after successful create\n */\nclass CreateGroupRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private groupCache: GroupCache.Interface,\n private pluginGroupsProvider: PluginGroupsProvider.Interface,\n private storageOperations: StorageOperations.Interface,\n private tenantContext: TenantContext.Interface,\n private runtimeTenant: RuntimeTenant.Interface\n ) {}\n\n async execute(initialGroup: CmsGroup): Promise<Result<CmsGroup, RepositoryAbstraction.Error>> {\n const group = this.runtimeTenant.assign(initialGroup);\n try {\n const tenant = this.tenantContext.getTenant();\n\n // 1. Validate ID uniqueness (if provided)\n if (group.id) {\n const existingById = await this.storageOperations.groups.list({\n where: {\n tenant: tenant.id,\n id: group.id\n }\n });\n\n if (existingById.length > 0) {\n return Result.fail(new GroupSlugTakenError(group.slug));\n }\n }\n\n // 2. Generate or validate slug\n const slugTaken = await this.isSlugTaken(group, tenant.id);\n if (slugTaken) {\n return Result.fail(new GroupSlugTakenError(group.slug));\n }\n\n // 3. Check for plugin group conflicts\n const pluginGroups = await this.pluginGroupsProvider.getGroups();\n const pluginGroupConflict = pluginGroups.find(pg => pg.slug === group.slug);\n if (pluginGroupConflict) {\n return Result.fail(new GroupSlugTakenError(group.slug));\n }\n\n // 4. Persist to storage\n await this.storageOperations.groups.create({ group });\n\n // 5. Clear cache\n this.groupCache.clear();\n\n return Result.ok(group);\n } catch (error) {\n return Result.fail(new GroupPersistenceError(error as Error));\n }\n }\n\n private async isSlugTaken(group: CmsGroup, tenant: string): Promise<boolean> {\n // If slug is provided and not empty, validate it\n if (group.slug && group.slug.trim()) {\n const existingBySlug = await this.storageOperations.groups.list({\n where: {\n tenant,\n slug: group.slug\n }\n });\n\n return existingBySlug.length > 0;\n }\n\n // Generate slug from name\n const baseSlug = toSlug(group.name);\n const existingBySlug = await this.storageOperations.groups.list({\n where: {\n tenant,\n slug: baseSlug\n }\n });\n\n if (existingBySlug.length === 0) {\n // No conflict, use base slug\n group.slug = baseSlug;\n } else {\n // Conflict, append random suffix\n group.slug = `${baseSlug}-${generateAlphaNumericId(8)}`;\n }\n\n return false;\n }\n}\n\nexport const CreateGroupRepository = createImplementation({\n abstraction: RepositoryAbstraction,\n implementation: CreateGroupRepositoryImpl,\n dependencies: [\n GroupCache,\n PluginGroupsProvider,\n StorageOperations,\n TenantContext,\n RuntimeTenant\n ]\n});\n"],"names":["CreateGroupRepositoryImpl","groupCache","pluginGroupsProvider","storageOperations","tenantContext","runtimeTenant","initialGroup","group","tenant","existingById","Result","GroupSlugTakenError","slugTaken","pluginGroups","pluginGroupConflict","pg","error","GroupPersistenceError","existingBySlug","baseSlug","toSlug","generateAlphaNumericId","CreateGroupRepository","createImplementation","RepositoryAbstraction","GroupCache","PluginGroupsProvider","StorageOperations","TenantContext","RuntimeTenant"],"mappings":";;;;;;;;;AAwBA,MAAMA;IACF,YACYC,UAAgC,EAChCC,oBAAoD,EACpDC,iBAA8C,EAC9CC,aAAsC,EACtCC,aAAsC,CAChD;aALUJ,UAAU,GAAVA;aACAC,oBAAoB,GAApBA;aACAC,iBAAiB,GAAjBA;aACAC,aAAa,GAAbA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QAAQC,YAAsB,EAA0D;QAC1F,MAAMC,QAAQ,IAAI,CAAC,aAAa,CAAC,MAAM,CAACD;QACxC,IAAI;YACA,MAAME,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;YAG3C,IAAID,MAAM,EAAE,EAAE;gBACV,MAAME,eAAe,MAAM,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC;oBAC1D,OAAO;wBACH,QAAQD,OAAO,EAAE;wBACjB,IAAID,MAAM,EAAE;oBAChB;gBACJ;gBA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GAAGY,SAAS,CAAC,EAAEE,uBAAuB,IAAI;QAG3D,OAAO;IACX;AACJ;AAEO,MAAMC,8CAAwBC,qBAAqB;IACtD,aAAaC;IACb,gBAAgBxB;IAChB,cAAc;QACVyB;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -5,7 +5,6 @@ import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.j
|
|
|
5
5
|
import { AccessControl } from "../../../features/shared/abstractions.js";
|
|
6
6
|
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
7
7
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
8
|
-
import { CmsContext } from "../../../features/shared/abstractions.js";
|
|
9
8
|
import type { CmsGroup } from "../../../types/index.js";
|
|
10
9
|
import type { CmsGroupCreateInput } from "../../../types/index.js";
|
|
11
10
|
/**
|
|
@@ -25,8 +24,7 @@ declare class CreateGroupUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
|
25
24
|
private accessControl;
|
|
26
25
|
private tenantContext;
|
|
27
26
|
private identityContext;
|
|
28
|
-
|
|
29
|
-
constructor(eventPublisher: EventPublisher.Interface, repository: CreateGroupRepository.Interface, accessControl: AccessControl.Interface, tenantContext: TenantContext.Interface, identityContext: IdentityContext.Interface, cmsContext: CmsContext.Interface);
|
|
27
|
+
constructor(eventPublisher: EventPublisher.Interface, repository: CreateGroupRepository.Interface, accessControl: AccessControl.Interface, tenantContext: TenantContext.Interface, identityContext: IdentityContext.Interface);
|
|
30
28
|
execute(input: CmsGroupCreateInput): Promise<Result<CmsGroup, UseCaseAbstraction.Error>>;
|
|
31
29
|
}
|
|
32
30
|
export declare const CreateGroupUseCase: import("@webiny/di").Implementation<typeof CreateGroupUseCaseImpl>;
|
|
@@ -2,20 +2,19 @@ import { Result, createImplementation } from "@webiny/feature/api";
|
|
|
2
2
|
import { CreateGroupRepository, CreateGroupUseCase } from "./abstractions.js";
|
|
3
3
|
import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
4
4
|
import { GroupAfterCreateEvent, GroupBeforeCreateEventEvent, GroupCreateErrorEvent } from "./events.js";
|
|
5
|
-
import { AccessControl
|
|
5
|
+
import { AccessControl } from "../../shared/abstractions.js";
|
|
6
6
|
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
7
7
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
8
8
|
import { GroupNotAuthorizedError, GroupValidationError } from "../../../domain/contentModelGroup/errors.js";
|
|
9
9
|
import { createZodError, mdbid } from "@webiny/utils";
|
|
10
10
|
import { createGroupCreateValidation } from "../../../domain/contentModelGroup/validation.js";
|
|
11
11
|
class CreateGroupUseCaseImpl {
|
|
12
|
-
constructor(eventPublisher, repository, accessControl, tenantContext, identityContext
|
|
12
|
+
constructor(eventPublisher, repository, accessControl, tenantContext, identityContext){
|
|
13
13
|
this.eventPublisher = eventPublisher;
|
|
14
14
|
this.repository = repository;
|
|
15
15
|
this.accessControl = accessControl;
|
|
16
16
|
this.tenantContext = tenantContext;
|
|
17
17
|
this.identityContext = identityContext;
|
|
18
|
-
this.cmsContext = cmsContext;
|
|
19
18
|
}
|
|
20
19
|
async execute(input) {
|
|
21
20
|
const canAccess = await this.accessControl.canAccessGroup({
|
|
@@ -62,9 +61,9 @@ class CreateGroupUseCaseImpl {
|
|
|
62
61
|
return Result.fail(result.error);
|
|
63
62
|
}
|
|
64
63
|
await this.eventPublisher.publish(new GroupAfterCreateEvent({
|
|
65
|
-
group
|
|
64
|
+
group: result.value
|
|
66
65
|
}));
|
|
67
|
-
return Result.ok(
|
|
66
|
+
return Result.ok(result.value);
|
|
68
67
|
} catch (error) {
|
|
69
68
|
await this.eventPublisher.publish(new GroupCreateErrorEvent({
|
|
70
69
|
input,
|
|
@@ -83,8 +82,7 @@ const CreateGroupUseCase_CreateGroupUseCase = createImplementation({
|
|
|
83
82
|
CreateGroupRepository,
|
|
84
83
|
AccessControl,
|
|
85
84
|
TenantContext,
|
|
86
|
-
IdentityContext
|
|
87
|
-
CmsContext
|
|
85
|
+
IdentityContext
|
|
88
86
|
]
|
|
89
87
|
});
|
|
90
88
|
export { CreateGroupUseCase_CreateGroupUseCase as CreateGroupUseCase };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentModelGroup/CreateGroup/CreateGroupUseCase.js","sources":["../../../../src/features/contentModelGroup/CreateGroup/CreateGroupUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { CreateGroupUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { CreateGroupRepository } from \"./abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { GroupBeforeCreateEventEvent } from \"./events.js\";\nimport { GroupAfterCreateEvent } from \"./events.js\";\nimport { GroupCreateErrorEvent } from \"./events.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"features/contentModelGroup/CreateGroup/CreateGroupUseCase.js","sources":["../../../../src/features/contentModelGroup/CreateGroup/CreateGroupUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { CreateGroupUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { CreateGroupRepository } from \"./abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { GroupBeforeCreateEventEvent } from \"./events.js\";\nimport { GroupAfterCreateEvent } from \"./events.js\";\nimport { GroupCreateErrorEvent } from \"./events.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport {\n GroupNotAuthorizedError,\n GroupValidationError\n} from \"~/domain/contentModelGroup/errors.js\";\nimport { createZodError } from \"@webiny/utils\";\nimport { mdbid } from \"@webiny/utils\";\nimport { createGroupCreateValidation } from \"~/domain/contentModelGroup/validation.js\";\nimport type { CmsGroup } from \"~/types/index.js\";\nimport type { CmsGroupCreateInput } from \"~/types/index.js\";\n\n/**\n * CreateGroupUseCase - Orchestrates group creation.\n *\n * Responsibilities:\n * - Validate input (Zod)\n * - Create domain group object\n * - Access control checks\n * - Publish before event\n * - Delegate to repository\n * - Publish after event or error event\n */\nclass CreateGroupUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private eventPublisher: EventPublisher.Interface,\n private repository: CreateGroupRepository.Interface,\n private accessControl: AccessControl.Interface,\n private tenantContext: TenantContext.Interface,\n private identityContext: IdentityContext.Interface\n ) {}\n\n async execute(input: CmsGroupCreateInput): Promise<Result<CmsGroup, UseCaseAbstraction.Error>> {\n // Initial access control check\n const canAccess = await this.accessControl.canAccessGroup({ rwd: \"w\" });\n if (!canAccess) {\n return Result.fail(new GroupNotAuthorizedError());\n }\n\n // Validate input\n const validationResult = await createGroupCreateValidation().safeParseAsync(input);\n if (!validationResult.success) {\n const zodError = createZodError(validationResult.error);\n return Result.fail(\n new GroupValidationError(zodError.message, zodError.data!.invalidFields)\n );\n }\n const data = validationResult.data;\n\n // Create domain group object\n const identity = this.identityContext.getIdentity();\n const tenant = this.tenantContext.getTenant();\n\n const id = data.id || mdbid();\n const group: CmsGroup = {\n ...data,\n id,\n tenant: tenant.id,\n createdOn: new Date().toISOString(),\n savedOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n }\n };\n\n // Access control check on created group\n const canAccessGroup = await this.accessControl.canAccessGroup({ group, rwd: \"w\" });\n if (!canAccessGroup) {\n return Result.fail(new GroupNotAuthorizedError());\n }\n\n try {\n // Publish before event\n await this.eventPublisher.publish(new GroupBeforeCreateEventEvent({ group }));\n\n // Persist via repository\n const result = await this.repository.execute(group);\n if (result.isFail()) {\n // Publish error event\n await this.eventPublisher.publish(\n new GroupCreateErrorEvent({\n input,\n group,\n error: result.error\n })\n );\n return Result.fail(result.error);\n }\n\n // Publish after event\n await this.eventPublisher.publish(\n new GroupAfterCreateEvent({\n group: result.value\n })\n );\n\n return Result.ok(result.value);\n } catch (error) {\n // Publish error event for unexpected errors\n await this.eventPublisher.publish(\n new GroupCreateErrorEvent({\n input,\n group,\n error: error as Error\n })\n );\n return Result.fail(error as UseCaseAbstraction.Error);\n }\n }\n}\n\nexport const CreateGroupUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: CreateGroupUseCaseImpl,\n dependencies: [\n EventPublisher,\n CreateGroupRepository,\n AccessControl,\n TenantContext,\n IdentityContext\n ]\n});\n"],"names":["CreateGroupUseCaseImpl","eventPublisher","repository","accessControl","tenantContext","identityContext","input","canAccess","Result","GroupNotAuthorizedError","validationResult","createGroupCreateValidation","zodError","createZodError","GroupValidationError","data","identity","tenant","id","mdbid","group","Date","canAccessGroup","GroupBeforeCreateEventEvent","result","GroupCreateErrorEvent","GroupAfterCreateEvent","error","CreateGroupUseCase","createImplementation","UseCaseAbstraction","EventPublisher","CreateGroupRepository","AccessControl","TenantContext","IdentityContext"],"mappings":";;;;;;;;;;AAgCA,MAAMA;IACF,YACYC,cAAwC,EACxCC,UAA2C,EAC3CC,aAAsC,EACtCC,aAAsC,EACtCC,eAA0C,CACpD;aALUJ,cAAc,GAAdA;aACAC,UAAU,GAAVA;aACAC,aAAa,GAAbA;aACAC,aAAa,GAAbA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QAAQC,KAA0B,EAAuD;QAE3F,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAE,KAAK;QAAI;QACrE,IAAI,CAACA,WACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,mB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hB,OAAO,EAAE,CAACgB,OAAO,KAAK;QACjC,EAAE,OAAOG,OAAO;YAEZ,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIF,sBAAsB;gBACtBnB;gBACAc;gBACA,OAAOO;YACX;YAEJ,OAAOnB,OAAO,IAAI,CAACmB;QACvB;IACJ;AACJ;AAEO,MAAMC,wCAAqBC,qBAAqB;IACnD,aAAaC;IACb,gBAAgB9B;IAChB,cAAc;QACV+B;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -26,7 +26,7 @@ export declare namespace CreateGroupUseCase {
|
|
|
26
26
|
* CreateGroupRepository - Persists a new group to storage.
|
|
27
27
|
*/
|
|
28
28
|
export interface ICreateGroupRepository {
|
|
29
|
-
execute(group: CmsGroup): Promise<Result<
|
|
29
|
+
execute(group: CmsGroup): Promise<Result<CmsGroup, RepositoryError>>;
|
|
30
30
|
}
|
|
31
31
|
export interface ICreateGroupRepositoryErrors {
|
|
32
32
|
alreadyExists: GroupSlugTakenError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentModelGroup/CreateGroup/abstractions.js","sources":["../../../../src/features/contentModelGroup/CreateGroup/abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { CmsGroup, CmsGroupCreateInput } from \"~/types/index.js\";\nimport type {\n GroupPersistenceError,\n GroupValidationError\n} from \"~/domain/contentModelGroup/errors.js\";\nimport {\n GroupNotAuthorizedError,\n type GroupSlugTakenError\n} from \"~/domain/contentModelGroup/errors.js\";\n\n/**\n * CreateGroup Use Case\n */\nexport interface ICreateGroupUseCase {\n execute(input: CmsGroupCreateInput): Promise<Result<CmsGroup, UseCaseError>>;\n}\n\nexport interface ICreateGroupUseCaseErrors {\n notAuthorized: GroupNotAuthorizedError;\n validation: GroupValidationError;\n repository: RepositoryError;\n}\n\ntype UseCaseError = ICreateGroupUseCaseErrors[keyof ICreateGroupUseCaseErrors];\n\n/** Create a new content model group. */\nexport const CreateGroupUseCase = createAbstraction<ICreateGroupUseCase>(\"CreateGroupUseCase\");\n\nexport namespace CreateGroupUseCase {\n export type Interface = ICreateGroupUseCase;\n export type Input = CmsGroupCreateInput;\n\n export type Error = UseCaseError;\n export type Return = Promise<Result<CmsGroup, UseCaseError>>;\n}\n\n/**\n * CreateGroupRepository - Persists a new group to storage.\n */\nexport interface ICreateGroupRepository {\n execute(group: CmsGroup): Promise<Result<
|
|
1
|
+
{"version":3,"file":"features/contentModelGroup/CreateGroup/abstractions.js","sources":["../../../../src/features/contentModelGroup/CreateGroup/abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { CmsGroup, CmsGroupCreateInput } from \"~/types/index.js\";\nimport type {\n GroupPersistenceError,\n GroupValidationError\n} from \"~/domain/contentModelGroup/errors.js\";\nimport {\n GroupNotAuthorizedError,\n type GroupSlugTakenError\n} from \"~/domain/contentModelGroup/errors.js\";\n\n/**\n * CreateGroup Use Case\n */\nexport interface ICreateGroupUseCase {\n execute(input: CmsGroupCreateInput): Promise<Result<CmsGroup, UseCaseError>>;\n}\n\nexport interface ICreateGroupUseCaseErrors {\n notAuthorized: GroupNotAuthorizedError;\n validation: GroupValidationError;\n repository: RepositoryError;\n}\n\ntype UseCaseError = ICreateGroupUseCaseErrors[keyof ICreateGroupUseCaseErrors];\n\n/** Create a new content model group. */\nexport const CreateGroupUseCase = createAbstraction<ICreateGroupUseCase>(\"CreateGroupUseCase\");\n\nexport namespace CreateGroupUseCase {\n export type Interface = ICreateGroupUseCase;\n export type Input = CmsGroupCreateInput;\n\n export type Error = UseCaseError;\n export type Return = Promise<Result<CmsGroup, UseCaseError>>;\n}\n\n/**\n * CreateGroupRepository - Persists a new group to storage.\n */\nexport interface ICreateGroupRepository {\n execute(group: CmsGroup): Promise<Result<CmsGroup, RepositoryError>>;\n}\n\nexport interface ICreateGroupRepositoryErrors {\n alreadyExists: GroupSlugTakenError;\n storage: GroupPersistenceError;\n}\n\ntype RepositoryError = ICreateGroupRepositoryErrors[keyof ICreateGroupRepositoryErrors];\n\nexport const CreateGroupRepository =\n createAbstraction<ICreateGroupRepository>(\"CreateGroupRepository\");\n\nexport namespace CreateGroupRepository {\n export type Interface = ICreateGroupRepository;\n export type Error = RepositoryError;\n}\n"],"names":["CreateGroupUseCase","createAbstraction","CreateGroupRepository"],"mappings":";AA2BO,MAAMA,qBAAqBC,kBAAuC;AAwBlE,MAAMC,wBACTD,kBAA0C"}
|
|
@@ -4,6 +4,7 @@ import { GroupCache } from "../../../features/contentModelGroup/shared/abstracti
|
|
|
4
4
|
import { PluginGroupsProvider } from "../../../features/contentModelGroup/shared/abstractions.js";
|
|
5
5
|
import { StorageOperations } from "../../../features/shared/abstractions.js";
|
|
6
6
|
import type { CmsGroup } from "../../../types/index.js";
|
|
7
|
+
import { RuntimeTenant } from "../../../features/runtimeTenant/abstractions.js";
|
|
7
8
|
/**
|
|
8
9
|
* DeleteGroupRepository - Validates and performs group deletion.
|
|
9
10
|
*
|
|
@@ -17,8 +18,9 @@ declare class DeleteGroupRepositoryImpl implements RepositoryAbstraction.Interfa
|
|
|
17
18
|
private groupCache;
|
|
18
19
|
private pluginGroupsProvider;
|
|
19
20
|
private storageOperations;
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
private runtimeTenant;
|
|
22
|
+
constructor(groupCache: GroupCache.Interface, pluginGroupsProvider: PluginGroupsProvider.Interface, storageOperations: StorageOperations.Interface, runtimeTenant: RuntimeTenant.Interface);
|
|
23
|
+
execute(initialGroup: CmsGroup): Promise<Result<void, RepositoryAbstraction.Error>>;
|
|
22
24
|
}
|
|
23
25
|
export declare const DeleteGroupRepository: import("@webiny/di").Implementation<typeof DeleteGroupRepositoryImpl>;
|
|
24
26
|
export {};
|
|
@@ -3,13 +3,16 @@ import { DeleteGroupRepository } from "./abstractions.js";
|
|
|
3
3
|
import { GroupCache, PluginGroupsProvider } from "../shared/abstractions.js";
|
|
4
4
|
import { GroupCannotDeleteCodeDefinedError, GroupHasModelsError, GroupPersistenceError } from "../../../domain/contentModelGroup/errors.js";
|
|
5
5
|
import { StorageOperations } from "../../shared/abstractions.js";
|
|
6
|
+
import { RuntimeTenant } from "../../runtimeTenant/abstractions.js";
|
|
6
7
|
class DeleteGroupRepositoryImpl {
|
|
7
|
-
constructor(groupCache, pluginGroupsProvider, storageOperations){
|
|
8
|
+
constructor(groupCache, pluginGroupsProvider, storageOperations, runtimeTenant){
|
|
8
9
|
this.groupCache = groupCache;
|
|
9
10
|
this.pluginGroupsProvider = pluginGroupsProvider;
|
|
10
11
|
this.storageOperations = storageOperations;
|
|
12
|
+
this.runtimeTenant = runtimeTenant;
|
|
11
13
|
}
|
|
12
|
-
async execute(
|
|
14
|
+
async execute(initialGroup) {
|
|
15
|
+
const group = this.runtimeTenant.assign(initialGroup);
|
|
13
16
|
try {
|
|
14
17
|
const pluginGroups = await this.pluginGroupsProvider.getGroups();
|
|
15
18
|
const isPluginGroup = pluginGroups.some((pg)=>pg.slug === group.slug);
|
|
@@ -37,7 +40,8 @@ const DeleteGroupRepository_DeleteGroupRepository = createImplementation({
|
|
|
37
40
|
dependencies: [
|
|
38
41
|
GroupCache,
|
|
39
42
|
PluginGroupsProvider,
|
|
40
|
-
StorageOperations
|
|
43
|
+
StorageOperations,
|
|
44
|
+
RuntimeTenant
|
|
41
45
|
]
|
|
42
46
|
});
|
|
43
47
|
export { DeleteGroupRepository_DeleteGroupRepository as DeleteGroupRepository };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentModelGroup/DeleteGroup/DeleteGroupRepository.js","sources":["../../../../src/features/contentModelGroup/DeleteGroup/DeleteGroupRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { DeleteGroupRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { GroupCache } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { PluginGroupsProvider } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { GroupCannotDeleteCodeDefinedError } from \"~/domain/contentModelGroup/errors.js\";\nimport { GroupHasModelsError } from \"~/domain/contentModelGroup/errors.js\";\nimport { GroupPersistenceError } from \"~/domain/contentModelGroup/errors.js\";\nimport { StorageOperations } from \"~/features/shared/abstractions.js\";\nimport type { CmsGroup } from \"~/types/index.js\";\n\n/**\n * DeleteGroupRepository - Validates and performs group deletion.\n *\n * Responsibilities:\n * - Check if group is plugin-based (cannot delete)\n * - Check if models reference this group (cannot delete)\n * - Persist deletion to storage\n * - Clear GroupCache after successful deletion\n */\nclass DeleteGroupRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private groupCache: GroupCache.Interface,\n private pluginGroupsProvider: PluginGroupsProvider.Interface,\n private storageOperations: StorageOperations.Interface\n ) {}\n\n async execute(
|
|
1
|
+
{"version":3,"file":"features/contentModelGroup/DeleteGroup/DeleteGroupRepository.js","sources":["../../../../src/features/contentModelGroup/DeleteGroup/DeleteGroupRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { DeleteGroupRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { GroupCache } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { PluginGroupsProvider } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { GroupCannotDeleteCodeDefinedError } from \"~/domain/contentModelGroup/errors.js\";\nimport { GroupHasModelsError } from \"~/domain/contentModelGroup/errors.js\";\nimport { GroupPersistenceError } from \"~/domain/contentModelGroup/errors.js\";\nimport { StorageOperations } from \"~/features/shared/abstractions.js\";\nimport type { CmsGroup } from \"~/types/index.js\";\nimport { RuntimeTenant } from \"~/features/runtimeTenant/abstractions.js\";\n\n/**\n * DeleteGroupRepository - Validates and performs group deletion.\n *\n * Responsibilities:\n * - Check if group is plugin-based (cannot delete)\n * - Check if models reference this group (cannot delete)\n * - Persist deletion to storage\n * - Clear GroupCache after successful deletion\n */\nclass DeleteGroupRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private groupCache: GroupCache.Interface,\n private pluginGroupsProvider: PluginGroupsProvider.Interface,\n private storageOperations: StorageOperations.Interface,\n private runtimeTenant: RuntimeTenant.Interface\n ) {}\n\n async execute(initialGroup: CmsGroup): Promise<Result<void, RepositoryAbstraction.Error>> {\n const group = this.runtimeTenant.assign(initialGroup);\n try {\n // Check if this is a plugin-based group (cannot be deleted)\n const pluginGroups = await this.pluginGroupsProvider.getGroups();\n const isPluginGroup = pluginGroups.some(pg => pg.slug === group.slug);\n\n if (isPluginGroup) {\n return Result.fail(new GroupCannotDeleteCodeDefinedError(group.id));\n }\n\n // Check if any models reference this group\n const models = await this.storageOperations.models.list({\n where: {\n tenant: group.tenant\n }\n });\n\n const items = models.filter(model => model.group === group.slug);\n if (items.length > 0) {\n return Result.fail(new GroupHasModelsError());\n }\n\n // Perform deletion\n await this.storageOperations.groups.delete({ group });\n\n // Clear cache\n this.groupCache.clear();\n\n return Result.ok();\n } catch (error) {\n return Result.fail(new GroupPersistenceError(error as Error));\n }\n }\n}\n\nexport const DeleteGroupRepository = createImplementation({\n abstraction: RepositoryAbstraction,\n implementation: DeleteGroupRepositoryImpl,\n dependencies: [GroupCache, PluginGroupsProvider, StorageOperations, RuntimeTenant]\n});\n"],"names":["DeleteGroupRepositoryImpl","groupCache","pluginGroupsProvider","storageOperations","runtimeTenant","initialGroup","group","pluginGroups","isPluginGroup","pg","Result","GroupCannotDeleteCodeDefinedError","models","items","model","GroupHasModelsError","error","GroupPersistenceError","DeleteGroupRepository","createImplementation","RepositoryAbstraction","GroupCache","PluginGroupsProvider","StorageOperations","RuntimeTenant"],"mappings":";;;;;;AAqBA,MAAMA;IACF,YACYC,UAAgC,EAChCC,oBAAoD,EACpDC,iBAA8C,EAC9CC,aAAsC,CAChD;aAJUH,UAAU,GAAVA;aACAC,oBAAoB,GAApBA;aACAC,iBAAiB,GAAjBA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QAAQC,YAAsB,EAAsD;QACtF,MAAMC,QAAQ,IAAI,CAAC,aAAa,CAAC,MAAM,CAACD;QACxC,IAAI;YAEA,MAAME,eAAe,MAAM,IAAI,CAAC,oBAAoB,CAAC,SAAS;YAC9D,MAAMC,gBAAgBD,aAAa,IAAI,CAACE,CAAAA,KAAMA,GAAG,IAAI,KAAKH,MAAM,IAAI;YAEpE,IAAIE,eACA,OAAOE,OAAO,IAAI,CAAC,IAAIC,kCAAkCL,MAAM,EAAE;YAIrE,MAAMM,SAAS,MAAM,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC;gBACpD,OAAO;oBACH,QAAQN,MAAM,MAAM;gBACxB;YACJ;YAEA,MAAMO,QAAQD,OAAO,MAAM,CAACE,CAAAA,QAASA,MAAM,KAAK,KAAKR,MAAM,IAAI;YAC/D,IAAIO,MAAM,MAAM,GAAG,GACf,OAAOH,OAAO,IAAI,CAAC,IAAIK;YAI3B,MAAM,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC;gBAAET;YAAM;YAGnD,IAAI,CAAC,UAAU,CAAC,KAAK;YAErB,OAAOI,OAAO,EAAE;QACpB,EAAE,OAAOM,OAAO;YACZ,OAAON,OAAO,IAAI,CAAC,IAAIO,sBAAsBD;QACjD;IACJ;AACJ;AAEO,MAAME,8CAAwBC,qBAAqB;IACtD,aAAaC;IACb,gBAAgBpB;IAChB,cAAc;QAACqB;QAAYC;QAAsBC;QAAmBC;KAAc;AACtF"}
|
|
@@ -4,6 +4,7 @@ import { GroupCache } from "../../../features/contentModelGroup/shared/abstracti
|
|
|
4
4
|
import { PluginGroupsProvider } from "../../../features/contentModelGroup/shared/abstractions.js";
|
|
5
5
|
import { StorageOperations } from "../../../features/shared/abstractions.js";
|
|
6
6
|
import type { CmsGroup } from "../../../types/index.js";
|
|
7
|
+
import { RuntimeTenant } from "../../../features/runtimeTenant/abstractions.js";
|
|
7
8
|
/**
|
|
8
9
|
* UpdateGroupRepository - Validates and persists group updates.
|
|
9
10
|
*
|
|
@@ -16,8 +17,9 @@ declare class UpdateGroupRepositoryImpl implements RepositoryAbstraction.Interfa
|
|
|
16
17
|
private groupCache;
|
|
17
18
|
private pluginGroupsProvider;
|
|
18
19
|
private storageOperations;
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
private runtimeTenant;
|
|
21
|
+
constructor(groupCache: GroupCache.Interface, pluginGroupsProvider: PluginGroupsProvider.Interface, storageOperations: StorageOperations.Interface, runtimeTenant: RuntimeTenant.Interface);
|
|
22
|
+
execute(initialGroup: CmsGroup): Promise<Result<CmsGroup, RepositoryAbstraction.Error>>;
|
|
21
23
|
}
|
|
22
24
|
export declare const UpdateGroupRepository: import("@webiny/di").Implementation<typeof UpdateGroupRepositoryImpl>;
|
|
23
25
|
export {};
|
|
@@ -3,13 +3,16 @@ import { UpdateGroupRepository } from "./abstractions.js";
|
|
|
3
3
|
import { GroupCache, PluginGroupsProvider } from "../shared/abstractions.js";
|
|
4
4
|
import { GroupCannotUpdateCodeDefinedError, GroupPersistenceError } from "../../../domain/contentModelGroup/errors.js";
|
|
5
5
|
import { StorageOperations } from "../../shared/abstractions.js";
|
|
6
|
+
import { RuntimeTenant } from "../../runtimeTenant/abstractions.js";
|
|
6
7
|
class UpdateGroupRepositoryImpl {
|
|
7
|
-
constructor(groupCache, pluginGroupsProvider, storageOperations){
|
|
8
|
+
constructor(groupCache, pluginGroupsProvider, storageOperations, runtimeTenant){
|
|
8
9
|
this.groupCache = groupCache;
|
|
9
10
|
this.pluginGroupsProvider = pluginGroupsProvider;
|
|
10
11
|
this.storageOperations = storageOperations;
|
|
12
|
+
this.runtimeTenant = runtimeTenant;
|
|
11
13
|
}
|
|
12
|
-
async execute(
|
|
14
|
+
async execute(initialGroup) {
|
|
15
|
+
const group = this.runtimeTenant.assign(initialGroup);
|
|
13
16
|
try {
|
|
14
17
|
const pluginGroups = await this.pluginGroupsProvider.getGroups();
|
|
15
18
|
const isPluginGroup = pluginGroups.some((pg)=>pg.slug === group.slug);
|
|
@@ -18,7 +21,7 @@ class UpdateGroupRepositoryImpl {
|
|
|
18
21
|
group
|
|
19
22
|
});
|
|
20
23
|
this.groupCache.clear();
|
|
21
|
-
return Result.ok();
|
|
24
|
+
return Result.ok(group);
|
|
22
25
|
} catch (error) {
|
|
23
26
|
return Result.fail(new GroupPersistenceError(error));
|
|
24
27
|
}
|
|
@@ -30,7 +33,8 @@ const UpdateGroupRepository_UpdateGroupRepository = createImplementation({
|
|
|
30
33
|
dependencies: [
|
|
31
34
|
GroupCache,
|
|
32
35
|
PluginGroupsProvider,
|
|
33
|
-
StorageOperations
|
|
36
|
+
StorageOperations,
|
|
37
|
+
RuntimeTenant
|
|
34
38
|
]
|
|
35
39
|
});
|
|
36
40
|
export { UpdateGroupRepository_UpdateGroupRepository as UpdateGroupRepository };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentModelGroup/UpdateGroup/UpdateGroupRepository.js","sources":["../../../../src/features/contentModelGroup/UpdateGroup/UpdateGroupRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { UpdateGroupRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { GroupCache } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { PluginGroupsProvider } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { GroupCannotUpdateCodeDefinedError } from \"~/domain/contentModelGroup/errors.js\";\nimport { GroupPersistenceError } from \"~/domain/contentModelGroup/errors.js\";\nimport { StorageOperations } from \"~/features/shared/abstractions.js\";\nimport type { CmsGroup } from \"~/types/index.js\";\n\n/**\n * UpdateGroupRepository - Validates and persists group updates.\n *\n * Responsibilities:\n * - Check if group is plugin-based (cannot update)\n * - Persist updates to storage\n * - Clear GroupCache after successful update\n */\nclass UpdateGroupRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private groupCache: GroupCache.Interface,\n private pluginGroupsProvider: PluginGroupsProvider.Interface,\n private storageOperations: StorageOperations.Interface\n ) {}\n\n async execute(
|
|
1
|
+
{"version":3,"file":"features/contentModelGroup/UpdateGroup/UpdateGroupRepository.js","sources":["../../../../src/features/contentModelGroup/UpdateGroup/UpdateGroupRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { UpdateGroupRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { GroupCache } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { PluginGroupsProvider } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { GroupCannotUpdateCodeDefinedError } from \"~/domain/contentModelGroup/errors.js\";\nimport { GroupPersistenceError } from \"~/domain/contentModelGroup/errors.js\";\nimport { StorageOperations } from \"~/features/shared/abstractions.js\";\nimport type { CmsGroup } from \"~/types/index.js\";\nimport { RuntimeTenant } from \"~/features/runtimeTenant/abstractions.js\";\n\n/**\n * UpdateGroupRepository - Validates and persists group updates.\n *\n * Responsibilities:\n * - Check if group is plugin-based (cannot update)\n * - Persist updates to storage\n * - Clear GroupCache after successful update\n */\nclass UpdateGroupRepositoryImpl implements RepositoryAbstraction.Interface {\n public constructor(\n private groupCache: GroupCache.Interface,\n private pluginGroupsProvider: PluginGroupsProvider.Interface,\n private storageOperations: StorageOperations.Interface,\n private runtimeTenant: RuntimeTenant.Interface\n ) {}\n\n async execute(initialGroup: CmsGroup): Promise<Result<CmsGroup, RepositoryAbstraction.Error>> {\n const group = this.runtimeTenant.assign(initialGroup);\n try {\n // Check if this is a plugin-based group (cannot be updated)\n const pluginGroups = await this.pluginGroupsProvider.getGroups();\n const isPluginGroup = pluginGroups.some(pg => pg.slug === group.slug);\n\n if (isPluginGroup) {\n return Result.fail(new GroupCannotUpdateCodeDefinedError(group.id));\n }\n\n // Persist updates\n await this.storageOperations.groups.update({ group });\n\n // Clear cache\n this.groupCache.clear();\n\n return Result.ok(group);\n } catch (error) {\n return Result.fail(new GroupPersistenceError(error as Error));\n }\n }\n}\n\nexport const UpdateGroupRepository = createImplementation({\n abstraction: RepositoryAbstraction,\n implementation: UpdateGroupRepositoryImpl,\n dependencies: [GroupCache, PluginGroupsProvider, StorageOperations, RuntimeTenant]\n});\n"],"names":["UpdateGroupRepositoryImpl","groupCache","pluginGroupsProvider","storageOperations","runtimeTenant","initialGroup","group","pluginGroups","isPluginGroup","pg","Result","GroupCannotUpdateCodeDefinedError","error","GroupPersistenceError","UpdateGroupRepository","createImplementation","RepositoryAbstraction","GroupCache","PluginGroupsProvider","StorageOperations","RuntimeTenant"],"mappings":";;;;;;AAmBA,MAAMA;IACF,YACYC,UAAgC,EAChCC,oBAAoD,EACpDC,iBAA8C,EAC9CC,aAAsC,CAChD;aAJUH,UAAU,GAAVA;aACAC,oBAAoB,GAApBA;aACAC,iBAAiB,GAAjBA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QAAQC,YAAsB,EAA0D;QAC1F,MAAMC,QAAQ,IAAI,CAAC,aAAa,CAAC,MAAM,CAACD;QACxC,IAAI;YAEA,MAAME,eAAe,MAAM,IAAI,CAAC,oBAAoB,CAAC,SAAS;YAC9D,MAAMC,gBAAgBD,aAAa,IAAI,CAACE,CAAAA,KAAMA,GAAG,IAAI,KAAKH,MAAM,IAAI;YAEpE,IAAIE,eACA,OAAOE,OAAO,IAAI,CAAC,IAAIC,kCAAkCL,MAAM,EAAE;YAIrE,MAAM,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC;gBAAEA;YAAM;YAGnD,IAAI,CAAC,UAAU,CAAC,KAAK;YAErB,OAAOI,OAAO,EAAE,CAACJ;QACrB,EAAE,OAAOM,OAAO;YACZ,OAAOF,OAAO,IAAI,CAAC,IAAIG,sBAAsBD;QACjD;IACJ;AACJ;AAEO,MAAME,8CAAwBC,qBAAqB;IACtD,aAAaC;IACb,gBAAgBhB;IAChB,cAAc;QAACiB;QAAYC;QAAsBC;QAAmBC;KAAc;AACtF"}
|
|
@@ -59,9 +59,9 @@ class UpdateGroupUseCaseImpl {
|
|
|
59
59
|
}
|
|
60
60
|
await this.eventPublisher.publish(new GroupAfterUpdateEvent({
|
|
61
61
|
original,
|
|
62
|
-
group
|
|
62
|
+
group: result.value
|
|
63
63
|
}));
|
|
64
|
-
return Result.ok(
|
|
64
|
+
return Result.ok(result.value);
|
|
65
65
|
} catch (error) {
|
|
66
66
|
await this.eventPublisher.publish(new GroupUpdateErrorEvent({
|
|
67
67
|
input,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.js","sources":["../../../../src/features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { UpdateGroupUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { UpdateGroupRepository } from \"./abstractions.js\";\nimport { GetGroupUseCase } from \"~/features/contentModelGroup/GetGroup/abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { GroupBeforeUpdateEvent } from \"./events.js\";\nimport { GroupAfterUpdateEvent } from \"./events.js\";\nimport { GroupUpdateErrorEvent } from \"./events.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport {\n GroupNotAuthorizedError,\n GroupValidationError\n} from \"~/domain/contentModelGroup/errors.js\";\nimport { createZodError } from \"@webiny/utils\";\nimport { createGroupUpdateValidation } from \"~/domain/contentModelGroup/validation.js\";\nimport type { CmsGroup } from \"~/types/index.js\";\nimport type { CmsGroupUpdateInput } from \"~/types/index.js\";\n\n/**\n * UpdateGroupUseCase - Orchestrates group updates.\n *\n * Responsibilities:\n * - Fetch original group\n * - Access control checks\n * - Validate input (Zod)\n * - Skip if no changes\n * - Merge changes\n * - Publish before event\n * - Delegate to repository\n * - Publish after event or error event\n */\nclass UpdateGroupUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private eventPublisher: EventPublisher.Interface,\n private repository: UpdateGroupRepository.Interface,\n private getGroupUseCase: GetGroupUseCase.Interface,\n private accessControl: AccessControl.Interface,\n private tenantContext: TenantContext.Interface\n ) {}\n\n async execute(\n groupId: string,\n input: CmsGroupUpdateInput\n ): Promise<Result<CmsGroup, UseCaseAbstraction.Error>> {\n // Initial access control check\n const canAccess = await this.accessControl.canAccessGroup({ rwd: \"w\" });\n if (!canAccess) {\n return Result.fail(new GroupNotAuthorizedError());\n }\n\n // Fetch original group\n const getResult = await this.getGroupUseCase.execute(groupId);\n if (getResult.isFail()) {\n return Result.fail(getResult.error);\n }\n const original = getResult.value;\n\n // Access control check on original group\n const canAccessGroup = await this.accessControl.canAccessGroup({ group: original });\n if (!canAccessGroup) {\n return Result.fail(new GroupNotAuthorizedError());\n }\n\n // Validate input\n const validationResult = await createGroupUpdateValidation().safeParseAsync(input);\n if (!validationResult.success) {\n const zodError = createZodError(validationResult.error);\n return Result.fail(\n new GroupValidationError(zodError.message, zodError.data!.invalidFields)\n );\n }\n const data = validationResult.data;\n\n // Skip if no changes\n if (Object.keys(data).length === 0) {\n return Result.ok(original);\n }\n\n // Merge changes\n const tenant = this.tenantContext.getTenant();\n const group: CmsGroup = {\n ...original,\n ...data,\n tenant: tenant.id,\n savedOn: new Date().toISOString()\n };\n\n try {\n // Publish before event\n await this.eventPublisher.publish(\n new GroupBeforeUpdateEvent({\n original,\n group\n })\n );\n\n // Persist via repository\n const result = await this.repository.execute(group);\n if (result.isFail()) {\n // Publish error event\n await this.eventPublisher.publish(\n new GroupUpdateErrorEvent({\n input,\n original,\n group,\n error: result.error\n })\n );\n return Result.fail(result.error);\n }\n\n // Publish after event\n await this.eventPublisher.publish(\n new GroupAfterUpdateEvent({\n original,\n group\n })\n );\n\n return Result.ok(
|
|
1
|
+
{"version":3,"file":"features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.js","sources":["../../../../src/features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { UpdateGroupUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { UpdateGroupRepository } from \"./abstractions.js\";\nimport { GetGroupUseCase } from \"~/features/contentModelGroup/GetGroup/abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { GroupBeforeUpdateEvent } from \"./events.js\";\nimport { GroupAfterUpdateEvent } from \"./events.js\";\nimport { GroupUpdateErrorEvent } from \"./events.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport {\n GroupNotAuthorizedError,\n GroupValidationError\n} from \"~/domain/contentModelGroup/errors.js\";\nimport { createZodError } from \"@webiny/utils\";\nimport { createGroupUpdateValidation } from \"~/domain/contentModelGroup/validation.js\";\nimport type { CmsGroup } from \"~/types/index.js\";\nimport type { CmsGroupUpdateInput } from \"~/types/index.js\";\n\n/**\n * UpdateGroupUseCase - Orchestrates group updates.\n *\n * Responsibilities:\n * - Fetch original group\n * - Access control checks\n * - Validate input (Zod)\n * - Skip if no changes\n * - Merge changes\n * - Publish before event\n * - Delegate to repository\n * - Publish after event or error event\n */\nclass UpdateGroupUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private eventPublisher: EventPublisher.Interface,\n private repository: UpdateGroupRepository.Interface,\n private getGroupUseCase: GetGroupUseCase.Interface,\n private accessControl: AccessControl.Interface,\n private tenantContext: TenantContext.Interface\n ) {}\n\n async execute(\n groupId: string,\n input: CmsGroupUpdateInput\n ): Promise<Result<CmsGroup, UseCaseAbstraction.Error>> {\n // Initial access control check\n const canAccess = await this.accessControl.canAccessGroup({ rwd: \"w\" });\n if (!canAccess) {\n return Result.fail(new GroupNotAuthorizedError());\n }\n\n // Fetch original group\n const getResult = await this.getGroupUseCase.execute(groupId);\n if (getResult.isFail()) {\n return Result.fail(getResult.error);\n }\n const original = getResult.value;\n\n // Access control check on original group\n const canAccessGroup = await this.accessControl.canAccessGroup({ group: original });\n if (!canAccessGroup) {\n return Result.fail(new GroupNotAuthorizedError());\n }\n\n // Validate input\n const validationResult = await createGroupUpdateValidation().safeParseAsync(input);\n if (!validationResult.success) {\n const zodError = createZodError(validationResult.error);\n return Result.fail(\n new GroupValidationError(zodError.message, zodError.data!.invalidFields)\n );\n }\n const data = validationResult.data;\n\n // Skip if no changes\n if (Object.keys(data).length === 0) {\n return Result.ok(original);\n }\n\n // Merge changes\n const tenant = this.tenantContext.getTenant();\n const group: CmsGroup = {\n ...original,\n ...data,\n tenant: tenant.id,\n savedOn: new Date().toISOString()\n };\n\n try {\n // Publish before event\n await this.eventPublisher.publish(\n new GroupBeforeUpdateEvent({\n original,\n group\n })\n );\n\n // Persist via repository\n const result = await this.repository.execute(group);\n if (result.isFail()) {\n // Publish error event\n await this.eventPublisher.publish(\n new GroupUpdateErrorEvent({\n input,\n original,\n group,\n error: result.error\n })\n );\n return Result.fail(result.error);\n }\n\n // Publish after event\n await this.eventPublisher.publish(\n new GroupAfterUpdateEvent({\n original,\n group: result.value\n })\n );\n\n return Result.ok(result.value);\n } catch (error) {\n // Publish error event for unexpected errors\n await this.eventPublisher.publish(\n new GroupUpdateErrorEvent({\n input,\n original,\n group,\n error: error as Error\n })\n );\n return Result.fail(error as UseCaseAbstraction.Error);\n }\n }\n}\n\nexport const UpdateGroupUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: UpdateGroupUseCaseImpl,\n dependencies: [\n EventPublisher,\n UpdateGroupRepository,\n GetGroupUseCase,\n AccessControl,\n TenantContext\n ]\n});\n"],"names":["UpdateGroupUseCaseImpl","eventPublisher","repository","getGroupUseCase","accessControl","tenantContext","groupId","input","canAccess","Result","GroupNotAuthorizedError","getResult","original","canAccessGroup","validationResult","createGroupUpdateValidation","zodError","createZodError","GroupValidationError","data","Object","tenant","group","Date","GroupBeforeUpdateEvent","result","GroupUpdateErrorEvent","GroupAfterUpdateEvent","error","UpdateGroupUseCase","createImplementation","UseCaseAbstraction","EventPublisher","UpdateGroupRepository","GetGroupUseCase","AccessControl","TenantContext"],"mappings":";;;;;;;;;;AAiCA,MAAMA;IACF,YACYC,cAAwC,EACxCC,UAA2C,EAC3CC,eAA0C,EAC1CC,aAAsC,EACtCC,aAAsC,CAChD;aALUJ,cAAc,GAAdA;aACAC,UAAU,GAAVA;aACAC,eAAe,GAAfA;aACAC,aAAa,GAAbA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QACFC,OAAe,EACfC,KAA0B,EACyB;QAEnD,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAE,KAAK;QAAI;QACrE,IAAI,CAACA,WACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,YAAY,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAACL;QACrD,IAAIK,UAAU,MAAM,IAChB,OAAOF,OAAO,IAAI,CAACE,UAAU,KAAK;QAEtC,MAAMC,WAAWD,UAAU,KAAK;QAGhC,MAAME,iBAAiB,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAE,OAAOD;QAAS;QACjF,IAAI,CAACC,gBACD,OAAOJ,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMI,mBAAmB,MAAMC,8BAA8B,cAAc,CAACR;QAC5E,IAAI,CAACO,iBAAiB,OAAO,EAAE;YAC3B,MAAME,WAAWC,eAAeH,iBAAiB,KAAK;YACtD,OAAOL,OAAO,IAAI,CACd,IAAIS,qBAAqBF,SAAS,OAAO,EAAEA,SAAS,IAAI,CAAE,aAAa;QAE/E;QACA,MAAMG,OAAOL,iBAAiB,IAAI;QAGlC,IAAIM,AAA6B,MAA7BA,OAAO,IAAI,CAACD,MAAM,MAAM,EACxB,OAAOV,OAAO,EAAE,CAACG;QAIrB,MAAMS,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,MAAMC,QAAkB;YACpB,GAAGV,QAAQ;YACX,GAAGO,IAAI;YACP,QAAQE,OAAO,EAAE;YACjB,SAAS,IAAIE,OAAO,WAAW;QACnC;QAEA,IAAI;YAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,uBAAuB;gBACvBZ;gBACAU;YACJ;YAIJ,MAAMG,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACH;YAC7C,IAAIG,OAAO,MAAM,IAAI;gBAEjB,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,sBAAsB;oBACtBnB;oBACAK;oBACAU;oBACA,OAAOG,OAAO,KAAK;gBACvB;gBAEJ,OAAOhB,OAAO,IAAI,CAACgB,OAAO,KAAK;YACnC;YAGA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIE,sBAAsB;gBACtBf;gBACA,OAAOa,OAAO,KAAK;YACvB;YAGJ,OAAOhB,OAAO,EAAE,CAACgB,OAAO,KAAK;QACjC,EAAE,OAAOG,OAAO;YAEZ,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIF,sBAAsB;gBACtBnB;gBACAK;gBACAU;gBACA,OAAOM;YACX;YAEJ,OAAOnB,OAAO,IAAI,CAACmB;QACvB;IACJ;AACJ;AAEO,MAAMC,wCAAqBC,qBAAqB;IACnD,aAAaC;IACb,gBAAgB/B;IAChB,cAAc;QACVgC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -27,7 +27,7 @@ export declare namespace UpdateGroupUseCase {
|
|
|
27
27
|
* UpdateGroupRepository - Persists group updates to storage.
|
|
28
28
|
*/
|
|
29
29
|
export interface IUpdateGroupRepository {
|
|
30
|
-
execute(group: CmsGroup): Promise<Result<
|
|
30
|
+
execute(group: CmsGroup): Promise<Result<CmsGroup, RepositoryError>>;
|
|
31
31
|
}
|
|
32
32
|
export interface IUpdateGroupRepositoryErrors {
|
|
33
33
|
cannotUpdate: GroupCannotUpdateCodeDefinedError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentModelGroup/UpdateGroup/abstractions.js","sources":["../../../../src/features/contentModelGroup/UpdateGroup/abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { CmsGroup, CmsGroupUpdateInput } from \"~/types/index.js\";\nimport type {\n GroupCannotUpdateCodeDefinedError,\n GroupPersistenceError,\n GroupValidationError\n} from \"~/domain/contentModelGroup/errors.js\";\nimport {\n GroupNotAuthorizedError,\n type GroupNotFoundError\n} from \"~/domain/contentModelGroup/errors.js\";\n\n/**\n * UpdateGroup Use Case\n */\nexport interface IUpdateGroupUseCase {\n execute(groupId: string, input: CmsGroupUpdateInput): Promise<Result<CmsGroup, UseCaseError>>;\n}\n\nexport interface IUpdateGroupUseCaseErrors {\n notFound: GroupNotFoundError;\n notAuthorized: GroupNotAuthorizedError;\n validation: GroupValidationError;\n repository: RepositoryError;\n}\n\ntype UseCaseError = IUpdateGroupUseCaseErrors[keyof IUpdateGroupUseCaseErrors];\n\n/** Update a content model group. */\nexport const UpdateGroupUseCase = createAbstraction<IUpdateGroupUseCase>(\"UpdateGroupUseCase\");\n\nexport namespace UpdateGroupUseCase {\n export type Interface = IUpdateGroupUseCase;\n export type Input = CmsGroupUpdateInput;\n\n export type Error = UseCaseError;\n export type Return = Promise<Result<CmsGroup, UseCaseError>>;\n}\n\n/**\n * UpdateGroupRepository - Persists group updates to storage.\n */\nexport interface IUpdateGroupRepository {\n execute(group: CmsGroup): Promise<Result<
|
|
1
|
+
{"version":3,"file":"features/contentModelGroup/UpdateGroup/abstractions.js","sources":["../../../../src/features/contentModelGroup/UpdateGroup/abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { CmsGroup, CmsGroupUpdateInput } from \"~/types/index.js\";\nimport type {\n GroupCannotUpdateCodeDefinedError,\n GroupPersistenceError,\n GroupValidationError\n} from \"~/domain/contentModelGroup/errors.js\";\nimport {\n GroupNotAuthorizedError,\n type GroupNotFoundError\n} from \"~/domain/contentModelGroup/errors.js\";\n\n/**\n * UpdateGroup Use Case\n */\nexport interface IUpdateGroupUseCase {\n execute(groupId: string, input: CmsGroupUpdateInput): Promise<Result<CmsGroup, UseCaseError>>;\n}\n\nexport interface IUpdateGroupUseCaseErrors {\n notFound: GroupNotFoundError;\n notAuthorized: GroupNotAuthorizedError;\n validation: GroupValidationError;\n repository: RepositoryError;\n}\n\ntype UseCaseError = IUpdateGroupUseCaseErrors[keyof IUpdateGroupUseCaseErrors];\n\n/** Update a content model group. */\nexport const UpdateGroupUseCase = createAbstraction<IUpdateGroupUseCase>(\"UpdateGroupUseCase\");\n\nexport namespace UpdateGroupUseCase {\n export type Interface = IUpdateGroupUseCase;\n export type Input = CmsGroupUpdateInput;\n\n export type Error = UseCaseError;\n export type Return = Promise<Result<CmsGroup, UseCaseError>>;\n}\n\n/**\n * UpdateGroupRepository - Persists group updates to storage.\n */\nexport interface IUpdateGroupRepository {\n execute(group: CmsGroup): Promise<Result<CmsGroup, RepositoryError>>;\n}\n\nexport interface IUpdateGroupRepositoryErrors {\n cannotUpdate: GroupCannotUpdateCodeDefinedError;\n storage: GroupPersistenceError;\n}\n\ntype RepositoryError = IUpdateGroupRepositoryErrors[keyof IUpdateGroupRepositoryErrors];\n\nexport const UpdateGroupRepository =\n createAbstraction<IUpdateGroupRepository>(\"UpdateGroupRepository\");\n\nexport namespace UpdateGroupRepository {\n export type Interface = IUpdateGroupRepository;\n export type Error = RepositoryError;\n}\n"],"names":["UpdateGroupUseCase","createAbstraction","UpdateGroupRepository"],"mappings":";AA6BO,MAAMA,qBAAqBC,kBAAuC;AAwBlE,MAAMC,wBACTD,kBAA0C"}
|
|
@@ -68,6 +68,7 @@ class ReadApi {
|
|
|
68
68
|
});
|
|
69
69
|
const templateIds = templateTypes.map((type)=>`extend type ${type} {
|
|
70
70
|
_templateId: ID!
|
|
71
|
+
_id: ID
|
|
71
72
|
}
|
|
72
73
|
`);
|
|
73
74
|
typeDefs.unshift(`union ${unionTypeName} = ${templateTypes.join(" | ")}`);
|
|
@@ -97,6 +98,7 @@ class ManageApi {
|
|
|
97
98
|
});
|
|
98
99
|
const templateIds = templateTypes.map((type)=>`extend type ${type} {
|
|
99
100
|
_templateId: ID!
|
|
101
|
+
_id: ID
|
|
100
102
|
}
|
|
101
103
|
`);
|
|
102
104
|
typeDefs.unshift(`union ${unionTypeName} = ${templateTypes.join(" | ")}`);
|
|
@@ -131,9 +133,13 @@ class ManageApi {
|
|
|
131
133
|
${key}: ${value}
|
|
132
134
|
`)}
|
|
133
135
|
}`);
|
|
136
|
+
const templateInputIds = templateTypes.map((inputTypeName)=>`extend input ${inputTypeName} {
|
|
137
|
+
_id: ID
|
|
138
|
+
}
|
|
139
|
+
`);
|
|
134
140
|
return {
|
|
135
141
|
fields: createGraphQLInputField(field, `${typeName}Input`),
|
|
136
|
-
typeDefs: typeDefs.join("\n")
|
|
142
|
+
typeDefs: typeDefs.concat(templateInputIds).join("\n")
|
|
137
143
|
};
|
|
138
144
|
}
|
|
139
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 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 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","templateIds","type","params","ManageApi","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,WAAW,GAAGM,YAAY,CAAC,EAAEX,eAAeD,MAAM,OAAO,GAAG;YAElE,IAAIA,MAAM,IAAI,IAAIG,MAAM,OAAO,CAACE,QAC5B,OAAOA,MAAM,GAAG,CAACY,CAAAA;gBACb,MAAMC,WAAWJ,UAAU,IAAI,CAACK,CAAAA,MAAOA,IAAI,EAAE,KAAKF,EAAE,WAAW;gBAC/D,IAAI,CAACC,UACD;gBAEJ,OAAOd,mBAAmBa,GAAG,GAAGX,SAAS,CAAC,EAAEY,SAAS,WAAW,EAAE;YACtE;YAGJ,MAAMA,WAAWJ,UAAU,IAAI,CAACK,CAAAA,MAAOA,IAAI,EAAE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,eAAe,UAAU,WAC1B,OAAO,EAAE;YAEb,MAAMxB,WAAWwB,cAAc,QAAQ,CAAC,SAAS,CAAC,IAAI,CAACG,CAAAA,IAAKA,EAAE,EAAE,KAAKD;YACrE,OAAO1B,UAAU,UAAU,EAAE;QACjC;QAEA,KAAK,MAAMA,YAAYlB,MAAM,QAAQ,CAAC,SAAS,CAC3CgC,OAAO,QAAQ,CAAC;YACZ,QAAQd,SAAS,MAAM;YACvB,gBAAgByB,0BAA0BzB,SAAS,EAAE;QACzD;IAER;IAEO,YAAYlB,KAAoB,EAAE8C,SAA8B,EAAwB;QAC3F,MAAMjC,UAAUb;QAChB,MAAM,EAAEc,YAAY,EAAE,EAAE,GAAGD,QAAQ,QAAQ;QAE3C,OAAO;YACH,MAAM;YACNb;YACA,UAAUc,UAAU,GAAG,CAAC,CAAC,EAAEiC,MAAM,EAAE,GAAG7B,UAAU,GACrC;oBACH,MAAM;oBACN,YAAY;wBACR,GAAGA,QAAQ;wBACX,eAAe;oBACnB;oBACA,UAAU6B,OAAO,GAAG,CAACC,CAAAA,IAAKF,UAAU,KAAK,CAACE;gBAC9C;QAER;IACJ;;aAtDgB,IAAI,GAAG,IAAIrB;aACX,MAAM,GAAG,IAAIM;aAEb,SAAS,GAAsB;aAC/B,YAAY,GAAY;aACxB,UAAU,GAAY;aACtB,oBAAoB,GAAY;;AAiDpD;AAEO,MAAMgB,4BAA4BC,uBAAuB,oBAAoB,CAAC;IACjF,gBAAgBT;IAChB,cAAc,EAAE;AACpB"}
|
|
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,MAAM,EACjB,OAAO;QAGX,MAAMC,WAAW,CAACC;YACd,MAAMX,QAAQW,MAAM,CAAChB,MAAM,OAAO,CAAC;YACnC,IAAI,CAACK,OACD,OAAOA;YAGX,MAAMC,WAAW,GAAGM,YAAY,CAAC,EAAEX,eAAeD,MAAM,OAAO,GAAG;YAElE,IAAIA,MAAM,IAAI,IAAIG,MAAM,OAAO,CAACE,QAC5B,OAAOA,MAAM,GAAG,CAACY,CAAAA;gBACb,MAAMC,WA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4BC,uBAAuB,oBAAoB,CAAC;IACjF,gBAAgBT;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -74,9 +74,10 @@ class ReadApi {
|
|
|
74
74
|
fieldRegistry,
|
|
75
75
|
endpointType: "read"
|
|
76
76
|
});
|
|
77
|
+
const itemIdTypeDef = `\nextend type ${fieldType} {\n _id: ID\n}\n`;
|
|
77
78
|
return {
|
|
78
79
|
fields: `${field.fieldId}: ${field.list ? `[${fieldType}!]` : fieldType}`,
|
|
79
|
-
typeDefs: `${typeDefs}${childTypeDefs}`
|
|
80
|
+
typeDefs: `${typeDefs}${childTypeDefs}${itemIdTypeDef}`
|
|
80
81
|
};
|
|
81
82
|
}
|
|
82
83
|
createResolver({ field, createFieldResolvers, graphQLType }) {
|
|
@@ -118,9 +119,10 @@ class ManageApi {
|
|
|
118
119
|
fieldRegistry,
|
|
119
120
|
endpointType: "manage"
|
|
120
121
|
});
|
|
122
|
+
const itemIdTypeDef = `\nextend type ${fieldType} {\n _id: ID\n}\n`;
|
|
121
123
|
return {
|
|
122
124
|
fields: `${field.fieldId}: ${field.list ? `[${fieldType}!]` : fieldType}`,
|
|
123
|
-
typeDefs: `${typeDefs}\n${childTypeDefs}`
|
|
125
|
+
typeDefs: `${typeDefs}\n${childTypeDefs}${itemIdTypeDef}`
|
|
124
126
|
};
|
|
125
127
|
}
|
|
126
128
|
createInputField({ models, model, field, fieldRegistry }) {
|
|
@@ -139,9 +141,10 @@ class ManageApi {
|
|
|
139
141
|
});
|
|
140
142
|
if (!result) return null;
|
|
141
143
|
const { fieldType, typeDefs } = result;
|
|
144
|
+
const itemIdTypeDef = `\nextend input ${fieldType} {\n _id: ID\n}\n`;
|
|
142
145
|
return {
|
|
143
146
|
fields: `${field.fieldId}: ${field.list ? `[${fieldType}!]` : fieldType}`,
|
|
144
|
-
typeDefs
|
|
147
|
+
typeDefs: `${typeDefs}${itemIdTypeDef}`
|
|
145
148
|
};
|
|
146
149
|
}
|
|
147
150
|
createResolver({ graphQLType, field, createFieldResolvers }) {
|