cms-renderer 0.7.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2584,14 +2584,14 @@ var require_buffer_from = __commonJS({
2584
2584
  }
2585
2585
  return isModern ? Buffer.from(obj.slice(byteOffset, byteOffset + length)) : new Buffer(new Uint8Array(obj.slice(byteOffset, byteOffset + length)));
2586
2586
  }
2587
- function fromString(string, encoding) {
2587
+ function fromString(string2, encoding) {
2588
2588
  if (typeof encoding !== "string" || encoding === "") {
2589
2589
  encoding = "utf8";
2590
2590
  }
2591
2591
  if (!Buffer.isEncoding(encoding)) {
2592
2592
  throw new TypeError('"encoding" must be a valid string encoding');
2593
2593
  }
2594
- return isModern ? Buffer.from(string, encoding) : new Buffer(string, encoding);
2594
+ return isModern ? Buffer.from(string2, encoding) : new Buffer(string2, encoding);
2595
2595
  }
2596
2596
  function bufferFrom(value, encodingOrOffset, length) {
2597
2597
  if (typeof value === "number") {
@@ -213877,10 +213877,10 @@ var LanguageSchema = z3.object({
213877
213877
  });
213878
213878
 
213879
213879
  // ../../packages/cms-schema/src/documents/unified-registry.ts
213880
- import { z as z8 } from "zod";
213880
+ import { z as z10 } from "zod";
213881
213881
 
213882
213882
  // ../../packages/cms-schema/src/documents/rehydration.ts
213883
- import { z as z7 } from "zod";
213883
+ import { z as z9 } from "zod";
213884
213884
 
213885
213885
  // ../../packages/cms-schema/src/fields/complex/media.ts
213886
213886
  import { z as z5 } from "zod";
@@ -213990,6 +213990,66 @@ function richtext(options) {
213990
213990
  return result.meta(meta);
213991
213991
  }
213992
213992
 
213993
+ // ../../packages/cms-schema/src/fields/primitives/select.ts
213994
+ import { z as z7 } from "zod";
213995
+ function normalizeChoices(choices) {
213996
+ return choices.map(
213997
+ (choice) => typeof choice === "string" ? { value: choice, label: choice } : choice
213998
+ );
213999
+ }
214000
+ function select(options) {
214001
+ const normalizedChoices = normalizeChoices(options.choices);
214002
+ const values = normalizedChoices.map((c) => c.value);
214003
+ const schema = z7.enum(values);
214004
+ const meta = {
214005
+ label: options.label,
214006
+ component: "select",
214007
+ required: options.required,
214008
+ description: options.description,
214009
+ options: {
214010
+ choices: normalizedChoices
214011
+ }
214012
+ };
214013
+ const result = options.required ? schema : schema.optional();
214014
+ return result.meta(meta);
214015
+ }
214016
+
214017
+ // ../../packages/cms-schema/src/fields/primitives/string.ts
214018
+ import { z as z8 } from "zod";
214019
+ function string(options) {
214020
+ let schema = z8.string();
214021
+ if (options.minLength) {
214022
+ schema = schema.min(options.minLength);
214023
+ }
214024
+ if (options.maxLength) {
214025
+ schema = schema.max(options.maxLength);
214026
+ }
214027
+ if (options.pattern) {
214028
+ schema = schema.regex(options.pattern, options.patternMessage);
214029
+ }
214030
+ if (options.format === "email") {
214031
+ schema = schema.email();
214032
+ }
214033
+ if (options.format === "url") {
214034
+ schema = schema.url();
214035
+ }
214036
+ if (options.format === "uuid") {
214037
+ schema = schema.uuid();
214038
+ }
214039
+ const meta = {
214040
+ label: options.label,
214041
+ component: options.multiline ? "textarea" : "input",
214042
+ required: options.required,
214043
+ description: options.description,
214044
+ placeholder: options.placeholder,
214045
+ options: {
214046
+ rows: options.rows
214047
+ }
214048
+ };
214049
+ const result = options.required ? schema : schema.optional();
214050
+ return result.meta(meta);
214051
+ }
214052
+
213993
214053
  // ../../packages/cms-schema/src/utils/safe-regex.ts
213994
214054
  var import_safe_regex2 = __toESM(require_safe_regex2(), 1);
213995
214055
  function validateSafeRegex(pattern) {
@@ -214008,6 +214068,25 @@ function validateSafeRegex(pattern) {
214008
214068
  }
214009
214069
 
214010
214070
  // ../../packages/cms-schema/src/documents/rehydration.ts
214071
+ var LAYOUT_VALUES = ["middle", "left", "right"];
214072
+ var HEX_COLOR_PATTERN = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
214073
+ var DEFAULT_COMPONENT_FIELDS = {
214074
+ layout: select({
214075
+ label: "Layout",
214076
+ description: "Horizontal alignment of the component.",
214077
+ choices: LAYOUT_VALUES.map((value) => ({
214078
+ value,
214079
+ label: value.charAt(0).toUpperCase() + value.slice(1)
214080
+ }))
214081
+ }),
214082
+ background: string({
214083
+ label: "Background",
214084
+ description: "Background color as a hex value, e.g. #1a2b3c.",
214085
+ placeholder: "#000000",
214086
+ pattern: HEX_COLOR_PATTERN,
214087
+ patternMessage: "Must be a hex color like #fff or #1a2b3c"
214088
+ })
214089
+ };
214011
214090
  var RehydrationError = class extends Error {
214012
214091
  constructor(message, fieldName, fieldType) {
214013
214092
  super(message);
@@ -214036,41 +214115,41 @@ function rehydrateField(field) {
214036
214115
  function createBaseSchema(type, constraints) {
214037
214116
  switch (type) {
214038
214117
  case "string":
214039
- return applyStringConstraints(z7.string(), constraints);
214118
+ return applyStringConstraints(z9.string(), constraints);
214040
214119
  case "richtext":
214041
214120
  return richtext({ label: "Rich Text", required: true });
214042
214121
  case "number":
214043
- return applyNumberConstraints(z7.number(), constraints);
214122
+ return applyNumberConstraints(z9.number(), constraints);
214044
214123
  case "boolean":
214045
- return z7.boolean();
214124
+ return z9.boolean();
214046
214125
  case "image":
214047
214126
  return ImageReferenceSchema;
214048
214127
  case "icon":
214049
- return z7.string().max(50);
214128
+ return z9.string().max(50);
214050
214129
  case "date":
214051
- return z7.iso.date("Invalid date format. Expected YYYY-MM-DD");
214130
+ return z9.iso.date("Invalid date format. Expected YYYY-MM-DD");
214052
214131
  case "datetime":
214053
- return z7.iso.datetime({
214132
+ return z9.iso.datetime({
214054
214133
  offset: true,
214055
214134
  message: "Invalid datetime format. Expected ISO 8601"
214056
214135
  });
214057
214136
  case "url":
214058
- return applyStringConstraints(z7.string(), constraints).pipe(z7.url("Invalid URL format"));
214137
+ return applyStringConstraints(z9.string(), constraints).pipe(z9.url("Invalid URL format"));
214059
214138
  case "email":
214060
- return applyStringConstraints(z7.string(), constraints).pipe(z7.email("Invalid email format"));
214139
+ return applyStringConstraints(z9.string(), constraints).pipe(z9.email("Invalid email format"));
214061
214140
  case "enum": {
214062
214141
  const values = constraints?.enumValues;
214063
214142
  if (!values || values.length === 0) {
214064
214143
  throw new Error("Enum field requires at least one enumValues in constraints");
214065
214144
  }
214066
- return z7.enum(values);
214145
+ return z9.enum(values);
214067
214146
  }
214068
214147
  case "reference":
214069
- return z7.record(z7.string(), z7.unknown());
214148
+ return z9.record(z9.string(), z9.unknown());
214070
214149
  case "array": {
214071
214150
  const itemType = constraints?.arrayItemType ?? "string";
214072
- const itemSchema = itemType === "reference" ? z7.record(z7.string(), z7.unknown()) : createPrimitiveSchema(itemType);
214073
- return applyArrayConstraints(z7.array(itemSchema), constraints);
214151
+ const itemSchema = itemType === "reference" ? z9.record(z9.string(), z9.unknown()) : createPrimitiveSchema(itemType);
214152
+ return applyArrayConstraints(z9.array(itemSchema), constraints);
214074
214153
  }
214075
214154
  default:
214076
214155
  throw new Error(`Unknown field type: ${type}`);
@@ -214079,11 +214158,11 @@ function createBaseSchema(type, constraints) {
214079
214158
  function createPrimitiveSchema(type) {
214080
214159
  switch (type) {
214081
214160
  case "string":
214082
- return z7.string();
214161
+ return z9.string();
214083
214162
  case "number":
214084
- return z7.number();
214163
+ return z9.number();
214085
214164
  case "boolean":
214086
- return z7.boolean();
214165
+ return z9.boolean();
214087
214166
  default:
214088
214167
  throw new Error(`Unsupported array item type: ${type}`);
214089
214168
  }
@@ -214175,7 +214254,12 @@ function rehydrateSchema(fields) {
214175
214254
  }
214176
214255
  shape[field.name] = rehydrateField(field);
214177
214256
  }
214178
- return z7.object(shape);
214257
+ for (const [name, fieldSchema] of Object.entries(DEFAULT_COMPONENT_FIELDS)) {
214258
+ if (!seenNames.has(name)) {
214259
+ shape[name] = fieldSchema;
214260
+ }
214261
+ }
214262
+ return z9.object(shape);
214179
214263
  }
214180
214264
 
214181
214265
  // ../../packages/cms-schema/src/documents/schema-hash.ts
@@ -214185,24 +214269,24 @@ import hash from "object-hash";
214185
214269
  import { TRPCError } from "@trpc/server";
214186
214270
 
214187
214271
  // ../../packages/cms-schema/src/documents/parse-field-definitions-json.ts
214188
- import { z as z9 } from "zod";
214272
+ import { z as z11 } from "zod";
214189
214273
  var SNAKE_CASE = /^[a-z][a-z0-9_]*$/;
214190
- var fieldConstraintsSchema = z9.object({
214191
- minLength: z9.number().int().min(0).optional(),
214192
- maxLength: z9.number().int().min(0).optional(),
214193
- pattern: z9.string().max(500).optional(),
214194
- min: z9.number().optional(),
214195
- max: z9.number().optional(),
214196
- integer: z9.boolean().optional(),
214197
- enumValues: z9.array(z9.string()).optional(),
214198
- arrayItemType: z9.enum(["string", "number", "boolean", "reference"]).optional(),
214199
- minItems: z9.number().int().min(0).optional(),
214200
- maxItems: z9.number().int().min(0).optional(),
214201
- refSchema: z9.string().regex(SNAKE_CASE, "refSchema must be snake_case").optional()
214274
+ var fieldConstraintsSchema = z11.object({
214275
+ minLength: z11.number().int().min(0).optional(),
214276
+ maxLength: z11.number().int().min(0).optional(),
214277
+ pattern: z11.string().max(500).optional(),
214278
+ min: z11.number().optional(),
214279
+ max: z11.number().optional(),
214280
+ integer: z11.boolean().optional(),
214281
+ enumValues: z11.array(z11.string()).optional(),
214282
+ arrayItemType: z11.enum(["string", "number", "boolean", "reference"]).optional(),
214283
+ minItems: z11.number().int().min(0).optional(),
214284
+ maxItems: z11.number().int().min(0).optional(),
214285
+ refSchema: z11.string().regex(SNAKE_CASE, "refSchema must be snake_case").optional()
214202
214286
  });
214203
- var fieldDefinitionSchema = z9.object({
214204
- name: z9.string().regex(SNAKE_CASE, "must be snake_case (lowercase letters, digits, underscores only)"),
214205
- type: z9.enum([
214287
+ var fieldDefinitionSchema = z11.object({
214288
+ name: z11.string().regex(SNAKE_CASE, "must be snake_case (lowercase letters, digits, underscores only)"),
214289
+ type: z11.enum([
214206
214290
  "string",
214207
214291
  "richtext",
214208
214292
  "number",
@@ -214217,14 +214301,14 @@ var fieldDefinitionSchema = z9.object({
214217
214301
  "image",
214218
214302
  "icon"
214219
214303
  ]),
214220
- displayName: z9.string().optional(),
214221
- description: z9.string().optional(),
214222
- required: z9.boolean(),
214304
+ displayName: z11.string().optional(),
214305
+ description: z11.string().optional(),
214306
+ required: z11.boolean(),
214223
214307
  constraints: fieldConstraintsSchema.optional()
214224
214308
  });
214225
- var fieldArraySchema = z9.array(fieldDefinitionSchema).min(1, "Schema must have at least one field");
214226
- var multiSchemaFieldDefSchema = z9.record(
214227
- z9.string().regex(SNAKE_CASE, "schema name must be snake_case"),
214309
+ var fieldArraySchema = z11.array(fieldDefinitionSchema).min(1, "Schema must have at least one field");
214310
+ var multiSchemaFieldDefSchema = z11.record(
214311
+ z11.string().regex(SNAKE_CASE, "schema name must be snake_case"),
214228
214312
  fieldArraySchema
214229
214313
  );
214230
214314