Skip to content

Commit a77925b

Browse files
move in ast types
1 parent 44e962d commit a77925b

File tree

6 files changed

+131
-19
lines changed

6 files changed

+131
-19
lines changed

src/cloud/components/Automations/WorkflowBuilder.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,17 @@ const Container = styled.div`
126126
}
127127
`
128128

129-
const defaultPipe = {
129+
const defaultPipe: SerializedPipe = {
130130
name: 'New Pipeline',
131131
event: 'github.issues.opened',
132-
action: 'boost.doc.create',
133132
configuration: {
134-
title: '$event.issue.title',
135-
content: '$event.issue.body',
136-
props: {
137-
IssueID: {
138-
type: 'number',
139-
data: '$event.issue.id',
133+
type: 'operation',
134+
identifier: 'boost.docs.create',
135+
input: {
136+
type: 'constructor',
137+
info: {
138+
type: 'struct',
139+
refs: {},
140140
},
141141
},
142142
},

src/cloud/interfaces/db/automations.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import { BoostAST } from '../../lib/automations'
2+
13
export interface SerializedPipe {
24
name: string
3-
action: string
45
event: string
56
filter?: any
6-
configuration: any
7+
configuration: BoostAST
78
}
89

910
export interface SerializedWorkflow {

src/cloud/lib/automations/ast.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { TypeDef } from './types'
2+
3+
export type ASTNode<P extends string = never> =
4+
| { type: 'operation'; identifier: string; input: ASTNode<P> }
5+
| { type: 'reference'; identifier: string }
6+
| { type: 'constructor'; info: ConstructorInfo<P> }
7+
| {
8+
type: 'literal'
9+
def: Extract<TypeDef<P>, { type: 'primitive' }>
10+
value: any
11+
}
12+
13+
export type ConstructorInfo<P extends string = never> =
14+
| { type: 'struct'; refs: Record<string, ASTNode<P>> }
15+
| { type: 'record'; refs: { key: ASTNode<P>; val: ASTNode<P> }[] }
16+
| { type: 'array'; refs: ASTNode<P>[] }

src/cloud/lib/automations/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { ASTNode } from './ast'
2+
3+
export type BoostAST = ASTNode<'folder' | 'propData'>

src/cloud/lib/automations/types.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
export type StdPrimitiveMap = {
2+
string: string
3+
number: number
4+
boolean: boolean
5+
}
6+
export type StdPrimitives = keyof StdPrimitiveMap
7+
8+
export type TypeDef<P extends string, U extends string = never> =
9+
| { type: 'struct'; def: Record<string, TypeDef<P, U>> }
10+
| { type: 'record'; def: TypeDef<P, U> }
11+
| { type: 'array'; def: TypeDef<P, U> }
12+
| { type: 'primitive'; def: P | StdPrimitives }
13+
| { type: 'optional'; def: TypeDef<P, U> }
14+
| (U extends string ? { type: 'reference'; def: U } : never)
15+
16+
export function Struct<U extends Record<string, TypeDef<any, any>>>(def: U) {
17+
return { type: 'struct' as const, def: def as U }
18+
}
19+
20+
export function Record<T extends TypeDef<any, any>>(def: T) {
21+
return { type: 'record' as const, def: def as T }
22+
}
23+
24+
export function Arr<T extends TypeDef<any, any>>(def: T) {
25+
return { type: 'array' as const, def: def as T }
26+
}
27+
28+
export function Primitive<P extends string>(def: P) {
29+
return { type: 'primitive', def } as { type: 'primitive'; def: P }
30+
}
31+
32+
export function Str() {
33+
return { type: 'primitive' as const, def: 'string' as const }
34+
}
35+
36+
export function Num() {
37+
return { type: 'primitive' as const, def: 'number' as const }
38+
}
39+
40+
export function Bool() {
41+
return { type: 'primitive' as const, def: 'boolean' as const }
42+
}
43+
44+
export function Optional<T extends TypeDef<any, any>>(def: T) {
45+
return { type: 'optional' as const, def }
46+
}
47+
48+
export function Reference<U extends string>(def: U) {
49+
return { type: 'reference' as const, def: def as U }
50+
}

src/cloud/pages/workflows/create.tsx

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import React, { useCallback, useState } from 'react'
22
import { getTeamIndexPageData } from '../../api/pages/teams'
33
import ApplicationContent from '../../components/ApplicationContent'
44
import ApplicationPage from '../../components/ApplicationPage'
5-
import { SerializedWorkflow } from '../../interfaces/db/automations'
5+
import {
6+
SerializedPipe,
7+
SerializedWorkflow,
8+
} from '../../interfaces/db/automations'
69
import Topbar from '../../../design/components/organisms/Topbar'
710
import { useToast } from '../../../design/lib/stores/toast'
811
import { createWorkflow } from '../../api/automation/workflow'
@@ -72,17 +75,56 @@ WorkflowCreatePage.getInitialProps = getTeamIndexPageData
7275

7376
export default WorkflowCreatePage
7477

75-
const defaultPipe = {
78+
const defaultPipe: SerializedPipe = {
7679
name: 'New Pipeline',
7780
event: 'github.issues.opened',
78-
action: 'boost.doc.create',
7981
configuration: {
80-
title: '$event.issue.title',
81-
content: '$event.issue.body',
82-
props: {
83-
IssueID: {
84-
type: 'number',
85-
data: '$event.issue.id',
82+
type: 'operation',
83+
identifier: 'boost.docs.create',
84+
input: {
85+
type: 'constructor',
86+
info: {
87+
type: 'struct',
88+
refs: {
89+
title: { type: 'reference', identifier: '$event.issue.title' },
90+
content: { type: 'reference', identifier: '$event.issue.body' },
91+
props: {
92+
type: 'constructor',
93+
info: {
94+
type: 'record',
95+
refs: [
96+
{
97+
key: {
98+
type: 'literal',
99+
def: { type: 'primitive', def: 'string' },
100+
value: 'IssueId',
101+
},
102+
val: {
103+
type: 'operation',
104+
identifier: 'boost.props.make',
105+
input: {
106+
type: 'constructor',
107+
info: {
108+
type: 'struct',
109+
refs: {
110+
type: {
111+
type: 'literal',
112+
def: { type: 'primitive', def: 'string' },
113+
value: 'number',
114+
},
115+
val: {
116+
type: 'reference',
117+
identifier: '$event.issue.id',
118+
},
119+
},
120+
},
121+
},
122+
},
123+
},
124+
],
125+
},
126+
},
127+
},
86128
},
87129
},
88130
},

0 commit comments

Comments
 (0)