Skip to content

Commit

Permalink
chore: update validators for prebinding fields (#971)
Browse files Browse the repository at this point in the history
  • Loading branch information
chasepoirier authored Jan 31, 2025
1 parent f781e57 commit 79bf5f4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
ExperienceComponentTree,
ComponentDefinitionPropertyType,
BindingSourceTypeEnum,
PatternProperty,
} from '@contentful/experiences-validators';
export type {
ExperienceDataSource,
Expand All @@ -32,6 +33,9 @@ export type {
BoundValue,
ComponentValue,
ComponentDefinitionPropertyType as ComponentDefinitionVariableType,
PatternProperty,
PatternPropertyDefinition,
VariableMapping,
} from '@contentful/experiences-validators';

export type ComponentDefinitionVariableTypeMap = {
Expand Down Expand Up @@ -171,6 +175,7 @@ export type ExperienceTreeNode = {
dataSource: ExperienceDataSource;
unboundValues: ExperienceUnboundValues;
breakpoints: Breakpoint[];
patternProperties?: Record<string, PatternProperty>;
pattern?: {
id: string;
nodeId: string;
Expand Down
3 changes: 3 additions & 0 deletions packages/validators/src/schemas/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
export {
BindingSourceTypeEnum,
PatternProperty,
PatternPropertyDefinition,
VariableMapping,
ExperienceFieldsCMAShapeSchema as Schema_2023_09_28,
} from './v2023_09_28/experience';
export { ComponentDefinitionSchema } from './componentDefinition';
40 changes: 40 additions & 0 deletions packages/validators/src/schemas/v2023_09_28/experience.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,40 @@ const ComponentPropertyValueSchema = z.discriminatedUnion('type', [

export type ComponentPropertyValue = z.infer<typeof ComponentPropertyValueSchema>;

// 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,
Expand Down Expand Up @@ -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<typeof BaseComponentTreeNodeSchema> & {
children: ComponentTreeNode[];
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -255,3 +292,6 @@ export type UnboundValue = z.infer<typeof UnboundValueSchema>;
export type HyperlinkValue = z.infer<typeof HyperlinkValueSchema>;
export type ComponentValue = z.infer<typeof ComponentValueSchema>;
export type BindingSourceTypeEnum = z.infer<typeof BindingSourceTypeEnumSchema>;
export type PatternPropertyDefinition = z.infer<typeof PatternPropertyDefinitionSchema>;
export type PatternProperty = z.infer<typeof PatternPropertySchema>;
export type VariableMapping = z.infer<typeof VariableMappingSchema>;

0 comments on commit 79bf5f4

Please sign in to comment.