@middlewr/contracts 0.0.44 → 0.0.46

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.
@@ -86,12 +86,20 @@ const PasswordNodeSchema = z.object({
86
86
  next: z.string().nullable(),
87
87
  });
88
88
 
89
+ const EntryNodeSchema = z.object({
90
+ id: z.string(),
91
+ type: z.literal('entry'),
92
+ position: PositionSchema,
93
+ next: z.string().nullable(),
94
+ });
95
+
89
96
  export const RuleGraphNodeSchema = z.discriminatedUnion('type', [
90
97
  ConditionNodeSchema,
91
98
  SplitNodeSchema,
92
99
  DestinationNodeSchema,
93
100
  TransformNodeSchema,
94
101
  PasswordNodeSchema,
102
+ EntryNodeSchema,
95
103
  ]);
96
104
 
97
105
  export const RuleGraphSchema = z
@@ -102,4 +110,24 @@ export const RuleGraphSchema = z
102
110
  .refine((data) => data.nodes[data.entry] !== undefined, {
103
111
  message: 'Entry node must reference an existing node in the graph',
104
112
  path: ['entry'],
105
- });
113
+ })
114
+ .refine(
115
+ (data) => {
116
+ const entryNode = data.nodes[data.entry];
117
+ return entryNode !== undefined && entryNode.type === 'entry';
118
+ },
119
+ {
120
+ message: 'Entry must point to a node of type "entry"',
121
+ path: ['entry'],
122
+ },
123
+ )
124
+ .refine(
125
+ (data) => {
126
+ const entryNodes = Object.values(data.nodes).filter((n) => n.type === 'entry');
127
+ return entryNodes.length === 1;
128
+ },
129
+ {
130
+ message: 'Graph must contain exactly one entry node',
131
+ path: ['nodes'],
132
+ },
133
+ );