-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6de8918
commit e727bc4
Showing
10 changed files
with
139 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { z } from 'zod'; | ||
|
||
const id = z.string().default(crypto.randomUUID); | ||
|
||
const nodeCommon = z.object({ | ||
id, | ||
name: z.string(), | ||
position: z.object({ x: z.number(), y: z.number() }).default({ x: 0, y: 0 }), | ||
}); | ||
|
||
export const inputNodeSchema = z | ||
.object({ | ||
type: z.literal('inputNode'), | ||
}) | ||
.merge(nodeCommon); | ||
|
||
export const outputNodeSchema = z | ||
.object({ | ||
type: z.literal('outputNode'), | ||
}) | ||
.merge(nodeCommon); | ||
|
||
export const decisionTableSchema = z | ||
.object({ | ||
type: z.literal('decisionTableNode'), | ||
content: z.object({ | ||
hitPolicy: z.enum(['first', 'collect']).default('first'), | ||
rules: z.array(z.record(z.string(), z.string())).default([]), | ||
inputs: z.array( | ||
z.object({ | ||
id, | ||
name: z.string().nullish(), | ||
field: z.string().nullish(), | ||
defaultValue: z.string().nullish(), | ||
}), | ||
), | ||
outputs: z.array( | ||
z.object({ | ||
id, | ||
name: z.string().nullish(), | ||
field: z.string().nullish(), | ||
defaultValue: z.string().nullish(), | ||
}), | ||
), | ||
}), | ||
}) | ||
.merge(nodeCommon); | ||
|
||
export const functionNodeSchema = z | ||
.object({ | ||
type: z.literal('functionNode'), | ||
content: z.string().nullish(), | ||
}) | ||
.merge(nodeCommon); | ||
|
||
export const expressionNodeSchema = z | ||
.object({ | ||
type: z.literal('expressionNode'), | ||
content: z.object({ | ||
expressions: z.array( | ||
z.object({ | ||
id, | ||
key: z.string().default(''), | ||
value: z.string().default(''), | ||
}), | ||
), | ||
}), | ||
}) | ||
.merge(nodeCommon); | ||
|
||
export const decisionNodeSchema = z | ||
.object({ | ||
type: z.literal('decisionNode'), | ||
content: z.object({ | ||
key: z.string(), | ||
}), | ||
}) | ||
.merge(nodeCommon); | ||
|
||
export const switchNodeSchema = z | ||
.object({ | ||
type: z.literal('switchNode'), | ||
content: z.object({ | ||
hitPolicy: z.enum(['first', 'collect']).default('first'), | ||
statements: z.array( | ||
z.object({ | ||
id, | ||
condition: z.string().default(''), | ||
}), | ||
), | ||
}), | ||
}) | ||
.merge(nodeCommon); | ||
|
||
export const customNodeSchema = z | ||
.object({ | ||
type: z.literal('customNode'), | ||
content: z.object({ | ||
kind: z.string(), | ||
config: z.any(), | ||
}), | ||
}) | ||
.merge(nodeCommon); | ||
|
||
export const nodeSchema = z.discriminatedUnion('type', [ | ||
decisionNodeSchema, | ||
expressionNodeSchema, | ||
functionNodeSchema, | ||
decisionTableSchema, | ||
switchNodeSchema, | ||
customNodeSchema, | ||
inputNodeSchema, | ||
outputNodeSchema, | ||
]); | ||
|
||
export const edgeSchema = z.object({ | ||
id: z.string(), | ||
sourceId: z.string(), | ||
targetId: z.string(), | ||
sourceHandle: z.string().nullish(), | ||
type: z.enum(['edge']), | ||
}); | ||
|
||
export const decisionModelSchema = z.object({ | ||
contentType: z.string().default('application/vnd.gorules.decision'), | ||
nodes: z.array(nodeSchema).default([]), | ||
edges: z.array(edgeSchema).default([]), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.