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

Method insertResource

runtime/parser/parser.go:854–930  ·  view source on GitHub ↗

insertResource inserts a resource in the parser's internal state. After calling insertResource, the caller can directly modify the returned resource's spec.

(kind ResourceKind, name string, paths []string, refs ...ResourceName)

Source from the content-addressed store, hash-verified

852// insertResource inserts a resource in the parser's internal state.
853// After calling insertResource, the caller can directly modify the returned resource's spec.
854func (p *Parser) insertResource(kind ResourceKind, name string, paths []string, refs ...ResourceName) (*Resource, error) {
855 // Create the resource if not already present (ensures the spec for its kind is never nil)
856 rn := ResourceName{Kind: kind, Name: name}
857 _, ok := p.Resources[rn.Normalized()]
858 if ok {
859 return nil, externalError{err: fmt.Errorf("name collision: another resource of type %q is also named %q", rn.Kind, rn.Name)}
860 }
861
862 // Dedupe refs (it's not guaranteed by the upstream logic).
863 // Doing a simple dedupe because there usually aren't many refs.
864 var dedupedRefs []ResourceName
865 for _, ref := range refs {
866 found := false
867 for _, existing := range dedupedRefs {
868 if ref.Normalized() == existing.Normalized() {
869 found = true
870 break
871 }
872 }
873 if !found {
874 dedupedRefs = append(dedupedRefs, ref)
875 }
876 }
877 refs = dedupedRefs
878
879 // Create new resource
880 r := &Resource{
881 Name: rn,
882 Paths: paths,
883 rawRefs: refs,
884 }
885 switch kind {
886 case ResourceKindModel:
887 r.ModelSpec = &runtimev1.ModelSpec{}
888 case ResourceKindMetricsView:
889 r.MetricsViewSpec = &runtimev1.MetricsViewSpec{}
890 case ResourceKindExplore:
891 r.ExploreSpec = &runtimev1.ExploreSpec{}
892 case ResourceKindMigration:
893 r.MigrationSpec = &runtimev1.MigrationSpec{}
894 case ResourceKindReport:
895 r.ReportSpec = &runtimev1.ReportSpec{}
896 case ResourceKindAlert:
897 r.AlertSpec = &runtimev1.AlertSpec{}
898 case ResourceKindTheme:
899 r.ThemeSpec = &runtimev1.ThemeSpec{}
900 case ResourceKindComponent:
901 r.ComponentSpec = &runtimev1.ComponentSpec{}
902 case ResourceKindCanvas:
903 r.CanvasSpec = &runtimev1.CanvasSpec{}
904 case ResourceKindAPI:
905 r.APISpec = &runtimev1.APISpec{}
906 case ResourceKindConnector:
907 r.ConnectorSpec = &runtimev1.ConnectorSpec{}
908 default:
909 panic(fmt.Errorf("unexpected resource type: %s", kind.String()))
910 }
911

Callers 12

parseExploreMethod · 0.95
parseConnectorMethod · 0.95
parseReportMethod · 0.95
parseAlertMethod · 0.95
parseComponentMethod · 0.95
parseModelMethod · 0.95
parseThemeMethod · 0.95
parseMetricsViewMethod · 0.95
parseMigrationMethod · 0.95
parseCanvasMethod · 0.95
parseAPIMethod · 0.95

Calls 4

NormalizedMethod · 0.95
ambiguousRefFunction · 0.85
ErrorfMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected