From 79bf5f444e3344f07911d786e5b3cba40d903c09 Mon Sep 17 00:00:00 2001 From: Chase Poirier Date: Fri, 31 Jan 2025 15:52:02 -0700 Subject: [PATCH] chore: update validators for prebinding fields (#971) --- package-lock.json | 1 + packages/core/src/types.ts | 5 +++ packages/validators/src/schemas/index.ts | 3 ++ .../src/schemas/v2023_09_28/experience.ts | 40 +++++++++++++++++++ 4 files changed, 49 insertions(+) diff --git a/package-lock.json b/package-lock.json index e4e5399ec..afc102c97 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2507,6 +2507,7 @@ }, "node_modules/@clack/prompts/node_modules/is-unicode-supported": { "version": "1.3.0", + "extraneous": true, "inBundle": true, "license": "MIT", "engines": { diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index e227315ab..908447984 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -16,6 +16,7 @@ import type { ExperienceComponentTree, ComponentDefinitionPropertyType, BindingSourceTypeEnum, + PatternProperty, } from '@contentful/experiences-validators'; export type { ExperienceDataSource, @@ -32,6 +33,9 @@ export type { BoundValue, ComponentValue, ComponentDefinitionPropertyType as ComponentDefinitionVariableType, + PatternProperty, + PatternPropertyDefinition, + VariableMapping, } from '@contentful/experiences-validators'; export type ComponentDefinitionVariableTypeMap = { @@ -171,6 +175,7 @@ export type ExperienceTreeNode = { dataSource: ExperienceDataSource; unboundValues: ExperienceUnboundValues; breakpoints: Breakpoint[]; + patternProperties?: Record; pattern?: { id: string; nodeId: string; diff --git a/packages/validators/src/schemas/index.ts b/packages/validators/src/schemas/index.ts index 4e9960c0a..410cbe085 100644 --- a/packages/validators/src/schemas/index.ts +++ b/packages/validators/src/schemas/index.ts @@ -1,5 +1,8 @@ export { BindingSourceTypeEnum, + PatternProperty, + PatternPropertyDefinition, + VariableMapping, ExperienceFieldsCMAShapeSchema as Schema_2023_09_28, } from './v2023_09_28/experience'; export { ComponentDefinitionSchema } from './componentDefinition'; diff --git a/packages/validators/src/schemas/v2023_09_28/experience.ts b/packages/validators/src/schemas/v2023_09_28/experience.ts index dcfb35570..701aaf039 100644 --- a/packages/validators/src/schemas/v2023_09_28/experience.ts +++ b/packages/validators/src/schemas/v2023_09_28/experience.ts @@ -96,6 +96,40 @@ const ComponentPropertyValueSchema = z.discriminatedUnion('type', [ export type ComponentPropertyValue = z.infer; +// TODO: finalized schema structure before release +// https://contentful.atlassian.net/browse/LUMOS-523 +const VariableMappingSchema = z.object({ + patternPropertyDefinitionId: propertyKeySchema, + type: z.literal('ContentTypeMapping'), + pathsByContentType: z.record(z.string(), z.object({ path: z.string() })), +}); + +const VariableMappingsSchema = z.record(propertyKeySchema, VariableMappingSchema); + +// TODO: finalized schema structure before release +// https://contentful.atlassian.net/browse/LUMOS-523 +const PatternPropertyDefinitionSchema = z.object({ + defaultValue: z.object({ + path: z.string(), + type: z.literal('BoundValue'), + }), + contentTypes: z.record(z.string(), z.any()), +}); + +const PatternPropertyDefinitionsSchema = z.record( + propertyKeySchema, + PatternPropertyDefinitionSchema, +); + +// TODO: finalized schema structure before release +// https://contentful.atlassian.net/browse/LUMOS-523 +const PatternPropertySchema = z.object({ + type: z.literal('BoundValue'), + path: z.string(), +}); + +const PatternPropertysSchema = z.record(propertyKeySchema, PatternPropertySchema); + export const BreakpointSchema = z .object({ id: propertyKeySchema, @@ -124,6 +158,7 @@ const BaseComponentTreeNodeSchema = z.object({ displayName: z.string().optional(), slotId: z.string().optional(), variables: z.record(propertyKeySchema, ComponentPropertyValueSchema), + patternProperties: PatternPropertysSchema.optional(), }); export type ComponentTreeNode = z.infer & { children: ComponentTreeNode[]; @@ -166,6 +201,8 @@ export const ComponentVariablesSchema = z.record( const ComponentSettingsSchema = z.object({ variableDefinitions: ComponentVariablesSchema, + variableMappings: VariableMappingsSchema.optional(), + patternPropertyDefinitions: PatternPropertyDefinitionsSchema.optional(), }); const UsedComponentsSchema = z.array( @@ -255,3 +292,6 @@ export type UnboundValue = z.infer; export type HyperlinkValue = z.infer; export type ComponentValue = z.infer; export type BindingSourceTypeEnum = z.infer; +export type PatternPropertyDefinition = z.infer; +export type PatternProperty = z.infer; +export type VariableMapping = z.infer;