MCPcopy Index your code
hub / github.com/rilldata/rill / parseComponent

Method parseComponent

runtime/parser/parse_component.go:43–79  ·  view source on GitHub ↗
(node *Node)

Source from the content-addressed store, hash-verified

41}
42
43func (p *Parser) parseComponent(node *Node) error {
44 // Parse YAML
45 tmp := &ComponentYAML{}
46 err := p.decodeNodeYAML(node, true, tmp)
47 if err != nil {
48 return err
49 }
50
51 // Validate SQL or connector isn't set
52 if node.SQL != "" {
53 return fmt.Errorf("components cannot have SQL")
54 }
55 if !node.ConnectorInferred && node.Connector != "" {
56 return fmt.Errorf("components cannot have a connector")
57 }
58
59 // Parse into a ComponentSpec
60 spec, refs, err := p.parseComponentYAML(tmp)
61 if err != nil {
62 return err
63 }
64 node.Refs = append(node.Refs, refs...)
65
66 // Track component
67 r, err := p.insertResource(ResourceKindComponent, node.Name, node.Paths, node.Refs...)
68 if err != nil {
69 return err
70 }
71 // NOTE: After calling insertResource, an error must not be returned. Any validation should be done before calling it.
72
73 r.ComponentSpec = spec
74 if r.ComponentSpec.DisplayName == "" {
75 r.ComponentSpec.DisplayName = ToDisplayName(node.Name)
76 }
77
78 return nil
79}
80
81// parseComponentYAML parses and validates a ComponentYAML.
82// It is separated from parseComponent to allow inline creation of components from a canvas YAML file.

Callers 1

parseNodeMethod · 0.95

Calls 5

decodeNodeYAMLMethod · 0.95
parseComponentYAMLMethod · 0.95
insertResourceMethod · 0.95
ToDisplayNameFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected