Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions cmd/polyform/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import (
"github.com/EliCDavis/polyform/generator/manifest/basics"
_ "github.com/EliCDavis/polyform/generator/manifest/basics"
_ "github.com/EliCDavis/polyform/generator/parameter"
"github.com/EliCDavis/polyform/generator/schema"
_ "github.com/EliCDavis/polyform/generator/subgraph/register"
"github.com/EliCDavis/polyform/generator/persistence"
"github.com/EliCDavis/polyform/generator/serialize"
"github.com/EliCDavis/polyform/generator/variable"

Expand Down Expand Up @@ -137,10 +138,10 @@ func main() {
app := generator.App{
Name: "Polyform",
Description: "Immutable mesh processing pipelines",
Authors: []schema.Author{
Authors: []persistence.Author{
{
Name: "Eli C Davis",
ContactInfo: []schema.AuthorContact{
ContactInfo: []persistence.AuthorContact{
{Medium: "bsky.app", Value: "@elicdavis.bsky.social"},
{Medium: "github.com", Value: "EliCDavis"},
},
Expand Down
10 changes: 5 additions & 5 deletions generator/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/EliCDavis/polyform/generator/manifest"
"github.com/EliCDavis/polyform/generator/room"
"github.com/EliCDavis/polyform/generator/run"
"github.com/EliCDavis/polyform/generator/schema"
"github.com/EliCDavis/polyform/generator/persistence"
"github.com/EliCDavis/polyform/generator/serialize"
"github.com/EliCDavis/polyform/generator/variable"
)
Expand All @@ -26,7 +26,7 @@ type App struct {
Name string
Version string
Description string
Authors []schema.Author
Authors []persistence.Author
VariableFactory func(variableType string) (variable.Variable, error)
NodeOutputSerialization *serialize.TypeSwitch[manifest.Entry]

Expand Down Expand Up @@ -64,7 +64,7 @@ type appCLI struct {
Name string
Version string
Description string
Authors []schema.Author
Authors []persistence.Author
Commands []*cli.Command
}

Expand Down Expand Up @@ -172,15 +172,15 @@ func (a *App) Run(args []string) error {
},
},
Run: func(state *cli.RunState) error {
graph := schema.App{
graph := persistence.App{
Name: state.String("name"),
Version: state.String("version"),
Description: state.String("description"),
}

authorFlag := state.String("author")
if authorFlag != "" {
graph.Authors = append(graph.Authors, schema.Author{Name: authorFlag})
graph.Authors = append(graph.Authors, persistence.Author{Name: authorFlag})
}

data, err := json.MarshalIndent(graph, "", "\t")
Expand Down
6 changes: 3 additions & 3 deletions generator/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/EliCDavis/polyform/generator/manifest"
"github.com/EliCDavis/polyform/generator/manifest/basics"
"github.com/EliCDavis/polyform/generator/parameter"
"github.com/EliCDavis/polyform/generator/schema"
"github.com/EliCDavis/polyform/generator/persistence"
"github.com/EliCDavis/polyform/nodes"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -310,10 +310,10 @@ func TestAppCommand_Help(t *testing.T) {
Name: "Test App",
Version: "test",
Description: "This is just a test app",
Authors: []schema.Author{
Authors: []persistence.Author{
{
Name: "Test Runner",
ContactInfo: []schema.AuthorContact{
ContactInfo: []persistence.AuthorContact{
{
Medium: "package",
Value: "testing",
Expand Down
4 changes: 2 additions & 2 deletions generator/edit/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/EliCDavis/polyform/generator/endpoint"
"github.com/EliCDavis/polyform/generator/graph"
"github.com/EliCDavis/polyform/generator/schema"
"github.com/EliCDavis/polyform/generator/persistence"
)

func exampleGraphEndpoint(as *Server) endpoint.Handler {
Expand Down Expand Up @@ -54,7 +54,7 @@ func newGraphEndpoint(editServer *Server) endpoint.Handler {
Name: clean(request.Body.Name, "New Graph"),
Description: clean(request.Body.Description, ""),
Version: clean(request.Body.Version, "v0.0.1"),
Authors: []schema.Author{{Name: clean(request.Body.Author, "")}},
Authors: []persistence.Author{{Name: clean(request.Body.Author, "")}},
})
return nil
},
Expand Down
32 changes: 12 additions & 20 deletions generator/edit/graph_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,19 @@ import (
"github.com/EliCDavis/polyform/generator/graph"
)

func graphMetadataEndpoint(graphInstance *graph.Instance, saver *GraphSaver) endpoint.Handler {

urlToMetadataKey := func(url string) string {
// We're making the assumption the url starts like this,
// so assert it.
if strings.Index(url, "/graph/metadata") != 0 {
panic("url should begin with /graph/metadata")
}

metadataPath := url[len("/graph/metadata"):]

if metadataPath[0] == '/' {
metadataPath = metadataPath[1:]
}
func metadataKeyFromRequestURL(url string) string {
metadataPath, err := pathSuffixAfterMarker(url, "/metadata/")
if err != nil {
panic(err.Error())
}

if len(metadataPath) > 0 {
metadataPath = strings.Replace(metadataPath, "/", ".", -1)
}
return metadataPath
if len(metadataPath) > 0 {
metadataPath = strings.Replace(metadataPath, "/", ".", -1)
}
return metadataPath
}

func graphMetadataEndpointForInstance(target *graph.Instance, saver *GraphSaver) endpoint.Handler {
type EditRequest any

type EmptyResponse struct{}
Expand All @@ -37,14 +29,14 @@ func graphMetadataEndpoint(graphInstance *graph.Instance, saver *GraphSaver) end
Methods: map[string]endpoint.Method{
http.MethodPost: endpoint.JsonMethod(
func(request endpoint.Request[EditRequest]) (EmptyResponse, error) {
graphInstance.SetMetadata(urlToMetadataKey(request.Url), request.Body)
target.SetMetadata(metadataKeyFromRequestURL(request.Url), request.Body)
saver.Save()
return EmptyResponse{}, nil
},
),

http.MethodDelete: endpoint.Func(func(r *http.Request) error {
graphInstance.DeleteMetadata(urlToMetadataKey(r.URL.Path))
target.DeleteMetadata(metadataKeyFromRequestURL(r.URL.Path))
saver.Save()
return nil
}),
Expand Down
20 changes: 17 additions & 3 deletions generator/edit/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,32 @@ import (
"github.com/EliCDavis/polyform/generator/manifest"
"github.com/EliCDavis/polyform/generator/schema"
"github.com/EliCDavis/polyform/generator/serialize"
"github.com/EliCDavis/polyform/generator/subgraph"
"github.com/EliCDavis/polyform/nodes"
)

const (
nodeOutputEndpointPath = "/node/output/"
)

// createNodeFromRequest routes node creation to the right constructor: only
// sub-graph boundary nodes carry a port type.
func createNodeFromRequest(instance *graph.Instance, nodeType, portType string) (nodes.Node, string, error) {
if portType != "" {
return instance.CreateBoundaryNode(nodeType, portType)
}
return instance.CreateNode(nodeType)
}

func nodeEndpoint(graphInstance *graph.Instance, saver *GraphSaver) endpoint.Handler {
type CreateRequest struct {
NodeType string `json:"nodeType"`
PortType string `json:"portType,omitempty"`
}

type CreateResponse struct {
NodeID string `json:"nodeID"`
Data schema.NodeInstance `json:"data"`
NodeID string `json:"nodeID"`
Data schema.Node `json:"data"`
}

type DeleteRequest struct {
Expand All @@ -35,7 +47,7 @@ func nodeEndpoint(graphInstance *graph.Instance, saver *GraphSaver) endpoint.Han
Methods: map[string]endpoint.Method{
http.MethodPost: endpoint.JsonMethod(
func(request endpoint.Request[CreateRequest]) (CreateResponse, error) {
node, id, err := graphInstance.CreateNode(request.Body.NodeType)
node, id, err := createNodeFromRequest(graphInstance, request.Body.NodeType, request.Body.PortType)
if err != nil {
return CreateResponse{}, err
}
Expand Down Expand Up @@ -104,6 +116,7 @@ func (as *Server) NodeOutputEndpoint(w http.ResponseWriter, r *http.Request) {
type RegisteredTypes struct {
NodeTypes []schema.NodeType `json:"nodeTypes"`
SerializeOutputTypes []string `json:"serializableOutputTypes"`
PortTypes []string `json:"portTypes"`
}

func nodeTypesEndpoint(graphInstance *graph.Instance, serializer *serialize.TypeSwitch[manifest.Entry]) endpoint.Handler {
Expand All @@ -113,6 +126,7 @@ func nodeTypesEndpoint(graphInstance *graph.Instance, serializer *serialize.Type
func(r *http.Request) (RegisteredTypes, error) {
b := RegisteredTypes{
NodeTypes: graphInstance.BuildSchemaForAllNodeTypes(),
PortTypes: subgraph.KnownPortTypes(),
}
if serializer != nil {
b.SerializeOutputTypes = serializer.Types()
Expand Down
15 changes: 9 additions & 6 deletions generator/edit/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
"github.com/EliCDavis/polyform/generator/endpoint"
"github.com/EliCDavis/polyform/generator/graph"
"github.com/EliCDavis/polyform/generator/manifest"
"github.com/EliCDavis/polyform/generator/persistence"
"github.com/EliCDavis/polyform/generator/room"
"github.com/EliCDavis/polyform/generator/schema"
"github.com/EliCDavis/polyform/generator/serialize"
"github.com/EliCDavis/polyform/generator/variable"
)
Expand Down Expand Up @@ -66,7 +66,7 @@ type Server struct {
Autosave bool
ConfigPath string

Webscene *schema.WebScene
Webscene *persistence.WebScene

ClientConfig *room.ClientConfig

Expand Down Expand Up @@ -145,9 +145,9 @@ func (as *Server) Handler(indexFile string) (*http.ServeMux, error) {
mux.HandleFunc("/schema", as.SchemaEndpoint)
mux.Handle("/scene", endpoint.Handler{
Methods: map[string]endpoint.Method{
http.MethodGet: endpoint.ResponseMethod[*schema.WebScene]{
ResponseWriter: endpoint.JsonResponseWriter[*schema.WebScene]{},
Handler: func(r *http.Request) (*schema.WebScene, error) {
http.MethodGet: endpoint.ResponseMethod[*persistence.WebScene]{
ResponseWriter: endpoint.JsonResponseWriter[*persistence.WebScene]{},
Handler: func(r *http.Request) (*persistence.WebScene, error) {
return as.Webscene, nil
},
},
Expand All @@ -157,6 +157,9 @@ func (as *Server) Handler(indexFile string) (*http.ServeMux, error) {
mux.Handle("/node-types", nodeTypesEndpoint(as.Graph, as.NodeOutputSerialization))
mux.Handle("/node", nodeEndpoint(as.Graph, graphSaver))
mux.Handle("/node/connection", nodeConnectionEndpoint(as.Graph, graphSaver))
mux.Handle(subGraphDefinitionEndpointPath, subGraphDefinitionEndpoint(as.Graph, graphSaver))
mux.Handle(subGraphBoundaryEndpointPath, subGraphBoundaryEndpoint(as.Graph, graphSaver))
mux.Handle("/graph/subgraph/", scopedGraphHandler(as.Graph, graphSaver))
mux.HandleFunc(nodeOutputEndpointPath, as.NodeOutputEndpoint)
mux.Handle("/parameter/value/", parameterValueEndpoint(as.Graph, graphSaver))
mux.Handle("/parameter/name/", parameterNameEndpoint(as.Graph, graphSaver))
Expand All @@ -171,7 +174,7 @@ func (as *Server) Handler(indexFile string) (*http.ServeMux, error) {
mux.Handle("/load-example", exampleGraphEndpoint(as))
mux.Handle("/graph", graphEndpoint(as))
mux.Handle("/graph/execution-report", executionReportEndpoint(as))
mux.Handle("/graph/metadata/", graphMetadataEndpoint(as.Graph, graphSaver))
mux.Handle("/graph/metadata/", graphMetadataEndpointForInstance(as.Graph, graphSaver))
mux.HandleFunc("/started", as.StartedEndpoint)
mux.HandleFunc("/mermaid", as.MermaidEndpoint)
mux.HandleFunc("/swagger", as.SwaggerEndpoint)
Expand Down
Loading
Loading