-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.go
More file actions
50 lines (42 loc) · 1.14 KB
/
handler.go
File metadata and controls
50 lines (42 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"context"
"errors"
"fmt"
"io"
"github.com/protobuf-orm/protobuf-orm/graph"
"github.com/protobuf-orm/protoc-gen-orm-ts/internal/build"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/types/descriptorpb"
"google.golang.org/protobuf/types/pluginpb"
)
type Handler struct {
Client ClientOpts
Db DbOpts
}
func (h *Handler) Run(p *protogen.Plugin) error {
p.SupportedEditionsMinimum = descriptorpb.Edition_EDITION_PROTO2
p.SupportedEditionsMaximum = descriptorpb.Edition_EDITION_MAX
p.SupportedFeatures = uint64(0 |
pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL |
pluginpb.CodeGeneratorResponse_FEATURE_SUPPORTS_EDITIONS,
)
ctx := context.Background()
// TODO: set logger
g := graph.NewGraph()
for _, f := range p.Files {
if err := graph.Parse(ctx, g, f.Desc); err != nil {
return fmt.Errorf("parse entity at %s: %w", *f.Proto.Name, err)
}
}
frame, err := build.ParseFrame(p, g)
if err != nil {
if errors.Is(err, io.EOF) {
return nil
}
return fmt.Errorf("parse build frame: %w", err)
}
h.Client.Run(ctx, p, "", frame)
h.Db.Run(ctx, p, "", frame)
return nil
}