@open-commune/core 0.2.1 → 0.2.3

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.
@@ -29,6 +29,35 @@ declare const fieldDefinitionSchema: z.ZodObject<{
29
29
  target: z.ZodOptional<z.ZodString>;
30
30
  }, z.core.$strip>;
31
31
  type FieldDefinition = z.infer<typeof fieldDefinitionSchema>;
32
+ /**
33
+ * A field as a read hands it back. Lenient on purpose: definitions are also
34
+ * written outside the admin's validation, straight through the repository, so a
35
+ * read returns what is stored — a field that breaks the write contract, a key
36
+ * this release does not know — rather than failing or dropping it, which the
37
+ * next admin save would make permanent. Writes are the strict side: the
38
+ * service validates them with `fieldDefinitionSchema`. The descriptions are the
39
+ * same, for the agents that read it.
40
+ */
41
+ declare const fieldReadSchema: z.ZodObject<{
42
+ name: z.ZodString;
43
+ label: z.ZodString;
44
+ type: z.ZodUnion<[z.ZodEnum<{
45
+ number: "number";
46
+ boolean: "boolean";
47
+ text: "text";
48
+ "rich-text": "rich-text";
49
+ date: "date";
50
+ media: "media";
51
+ relation: "relation";
52
+ select: "select";
53
+ steps: "steps";
54
+ json: "json";
55
+ }>, z.ZodString]>;
56
+ required: z.ZodDefault<z.ZodBoolean>;
57
+ hidden: z.ZodDefault<z.ZodBoolean>;
58
+ options: z.ZodOptional<z.ZodArray<z.ZodString>>;
59
+ target: z.ZodOptional<z.ZodString>;
60
+ }, z.core.$loose>;
32
61
  declare const FIELD_VALUE_SCHEMAS: Record<FieldType, z.ZodType>;
33
62
  /**
34
63
  * Build the Zod schema validating an entry's `data` from a collection
@@ -37,5 +66,5 @@ declare const FIELD_VALUE_SCHEMAS: Record<FieldType, z.ZodType>;
37
66
  */
38
67
  declare function buildDataSchema(fields: FieldDefinition[]): z.ZodType<Record<string, unknown>>;
39
68
 
40
- export { FIELD_VALUE_SCHEMAS, buildDataSchema, fieldDefinitionSchema };
69
+ export { FIELD_VALUE_SCHEMAS, buildDataSchema, fieldDefinitionSchema, fieldReadSchema };
41
70
  export type { FieldDefinition };
@@ -29,6 +29,35 @@ declare const fieldDefinitionSchema: z.ZodObject<{
29
29
  target: z.ZodOptional<z.ZodString>;
30
30
  }, z.core.$strip>;
31
31
  type FieldDefinition = z.infer<typeof fieldDefinitionSchema>;
32
+ /**
33
+ * A field as a read hands it back. Lenient on purpose: definitions are also
34
+ * written outside the admin's validation, straight through the repository, so a
35
+ * read returns what is stored — a field that breaks the write contract, a key
36
+ * this release does not know — rather than failing or dropping it, which the
37
+ * next admin save would make permanent. Writes are the strict side: the
38
+ * service validates them with `fieldDefinitionSchema`. The descriptions are the
39
+ * same, for the agents that read it.
40
+ */
41
+ declare const fieldReadSchema: z.ZodObject<{
42
+ name: z.ZodString;
43
+ label: z.ZodString;
44
+ type: z.ZodUnion<[z.ZodEnum<{
45
+ number: "number";
46
+ boolean: "boolean";
47
+ text: "text";
48
+ "rich-text": "rich-text";
49
+ date: "date";
50
+ media: "media";
51
+ relation: "relation";
52
+ select: "select";
53
+ steps: "steps";
54
+ json: "json";
55
+ }>, z.ZodString]>;
56
+ required: z.ZodDefault<z.ZodBoolean>;
57
+ hidden: z.ZodDefault<z.ZodBoolean>;
58
+ options: z.ZodOptional<z.ZodArray<z.ZodString>>;
59
+ target: z.ZodOptional<z.ZodString>;
60
+ }, z.core.$loose>;
32
61
  declare const FIELD_VALUE_SCHEMAS: Record<FieldType, z.ZodType>;
33
62
  /**
34
63
  * Build the Zod schema validating an entry's `data` from a collection
@@ -37,5 +66,5 @@ declare const FIELD_VALUE_SCHEMAS: Record<FieldType, z.ZodType>;
37
66
  */
38
67
  declare function buildDataSchema(fields: FieldDefinition[]): z.ZodType<Record<string, unknown>>;
39
68
 
40
- export { FIELD_VALUE_SCHEMAS, buildDataSchema, fieldDefinitionSchema };
69
+ export { FIELD_VALUE_SCHEMAS, buildDataSchema, fieldDefinitionSchema, fieldReadSchema };
41
70
  export type { FieldDefinition };
@@ -1 +1 @@
1
- import{z as e}from"zod";import{FIELD_TYPES as i}from"./constants.mjs";const a=e.object({name:e.string().regex(/^[a-zA-Z][a-zA-Z0-9_]*$/,"nom de champ invalide"),label:e.string().min(1),type:e.enum(i),required:e.boolean().default(!1),hidden:e.boolean().default(!1),options:e.array(e.string().min(1)).optional(),target:e.string().optional()}).check(t=>{t.value.type==="select"&&!t.value.options?.length&&t.issues.push({code:"custom",message:"options requises pour un champ select",input:t.value}),t.value.type==="relation"&&!t.value.target&&t.issues.push({code:"custom",message:"target requis pour un champ relation",input:t.value})}),u=e.record(e.string(),e.unknown()),s={text:e.string(),"rich-text":e.record(e.string(),e.unknown()),number:e.number().or(e.string()),boolean:e.boolean(),date:e.iso.datetime({offset:!0}).or(e.iso.date()),media:e.string().or(e.array(e.string())),relation:e.string().or(e.array(e.string())),select:e.string(),steps:e.array(u),json:e.union([e.record(e.string(),e.unknown()),e.array(e.unknown()),e.string(),e.number(),e.boolean()])};function l(t){const r={};for(const n of t){let o=s[n.type];n.type==="select"&&n.options?.length&&(o=e.enum(n.options)),r[n.name]=n.required?o:o.nullable().optional()}return e.strictObject(r)}export{s as FIELD_VALUE_SCHEMAS,l as buildDataSchema,a as fieldDefinitionSchema};
1
+ import{z as e}from"zod";import{FIELD_TYPES as s}from"./constants.mjs";const a=e.object({name:e.string().regex(/^[a-zA-Z][a-zA-Z0-9_]*$/,"nom de champ invalide").describe("Key of the value inside an entry\u2019s `data`"),label:e.string().min(1).describe("Label shown to editors"),type:e.enum(s).describe("text, rich-text (TipTap JSON document), number, boolean, date (ISO 8601), media (media id or ids), relation (entry id or ids of the `target` collection), select (one of `options`), steps (ordered rich steps), json (free structure)"),required:e.boolean().default(!1),hidden:e.boolean().default(!1).describe("Hidden fields never reach the public site"),options:e.array(e.string().min(1)).optional().describe("Allowed values of a select field"),target:e.string().optional().describe("Slug of the collection a relation field points to")}).check(t=>{t.value.type==="select"&&!t.value.options?.length&&t.issues.push({code:"custom",message:"options requises pour un champ select",input:t.value}),t.value.type==="relation"&&!t.value.target&&t.issues.push({code:"custom",message:"target requis pour un champ relation",input:t.value})}),o=(t,r)=>t.describe(a.shape[r].description??""),d=e.looseObject({name:o(e.string(),"name"),label:o(e.string(),"label"),type:o(e.enum(s).or(e.string()),"type"),required:e.boolean().default(!1),hidden:o(e.boolean().default(!1),"hidden"),options:o(e.array(e.string()).optional(),"options"),target:o(e.string().optional(),"target")}),c=e.record(e.string(),e.unknown()),l={text:e.string(),"rich-text":e.record(e.string(),e.unknown()),number:e.number().or(e.string()),boolean:e.boolean(),date:e.iso.datetime({offset:!0}).or(e.iso.date()),media:e.string().or(e.array(e.string())),relation:e.string().or(e.array(e.string())),select:e.string(),steps:e.array(c),json:e.union([e.record(e.string(),e.unknown()),e.array(e.unknown()),e.string(),e.number(),e.boolean()])};function u(t){const r={};for(const n of t){let i=l[n.type];n.type==="select"&&n.options?.length&&(i=e.enum(n.options)),r[n.name]=n.required?i:i.nullable().optional()}return e.strictObject(r)}export{l as FIELD_VALUE_SCHEMAS,u as buildDataSchema,a as fieldDefinitionSchema,d as fieldReadSchema};