• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / cli / 13918644911

18 Mar 2025 08:29AM UTC coverage: 51.06% (-6.7%) from 57.735%
13918644911

push

github

sweatybridge
chore(deps): bump supabase/studio in /pkg/config/templates

Bumps supabase/studio from 20250224-d10db0f to 20250317-6955350.

---
updated-dependencies:
- dependency-name: supabase/studio
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

6959 of 13629 relevant lines covered (51.06%)

186.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

21.65
/pkg/function/batch.go
1
package function
2

3
import (
4
        "bytes"
5
        "context"
6
        "fmt"
7
        "io"
8
        "os"
9

10
        "github.com/cenkalti/backoff/v4"
11
        "github.com/docker/go-units"
12
        "github.com/go-errors/errors"
13
        "github.com/supabase/cli/pkg/api"
14
        "github.com/supabase/cli/pkg/config"
15
)
16

17
const (
18
        eszipContentType = "application/vnd.denoland.eszip"
19
        maxRetries       = 3
20
)
21

22
func (s *EdgeRuntimeAPI) UpsertFunctions(ctx context.Context, functionConfig config.FunctionConfig, filter ...func(string) bool) error {
4✔
23
        var result []api.FunctionResponse
4✔
24
        if resp, err := s.client.V1ListAllFunctionsWithResponse(ctx, s.project); err != nil {
5✔
25
                return errors.Errorf("failed to list functions: %w", err)
1✔
26
        } else if resp.JSON200 == nil {
5✔
27
                return errors.Errorf("unexpected list functions status %d: %s", resp.StatusCode(), string(resp.Body))
1✔
28
        } else {
3✔
29
                result = *resp.JSON200
2✔
30
        }
2✔
31
        exists := make(map[string]struct{}, len(result))
2✔
32
        for _, f := range result {
3✔
33
                exists[f.Slug] = struct{}{}
1✔
34
        }
1✔
35
        var toUpdate []api.BulkUpdateFunctionBody
2✔
36
OUTER:
2✔
37
        for slug, function := range functionConfig {
4✔
38
                if !function.Enabled {
4✔
39
                        fmt.Fprintln(os.Stderr, "Skipped deploying Function:", slug)
2✔
40
                        continue
2✔
41
                }
42
                for _, keep := range filter {
×
43
                        if !keep(slug) {
×
44
                                continue OUTER
×
45
                        }
46
                }
47
                var body bytes.Buffer
×
48
                meta, err := s.eszip.Bundle(ctx, slug, function.Entrypoint, function.ImportMap, function.StaticFiles, &body)
×
49
                if err != nil {
×
50
                        return err
×
51
                }
×
52
                meta.VerifyJwt = &function.VerifyJWT
×
53
                // Update if function already exists
×
54
                upsert := func() (api.BulkUpdateFunctionBody, error) {
×
55
                        if _, ok := exists[slug]; ok {
×
56
                                return s.updateFunction(ctx, slug, meta, bytes.NewReader(body.Bytes()))
×
57
                        }
×
58
                        return s.createFunction(ctx, slug, meta, bytes.NewReader(body.Bytes()))
×
59
                }
60
                functionSize := units.HumanSize(float64(body.Len()))
×
61
                fmt.Fprintf(os.Stderr, "Deploying Function: %s (script size: %s)\n", slug, functionSize)
×
62
                policy := backoff.WithContext(backoff.WithMaxRetries(backoff.NewExponentialBackOff(), maxRetries), ctx)
×
63
                result, err := backoff.RetryWithData(upsert, policy)
×
64
                if err != nil {
×
65
                        return err
×
66
                }
×
67
                toUpdate = append(toUpdate, result)
×
68
        }
69
        if len(toUpdate) > 1 {
2✔
70
                if resp, err := s.client.V1BulkUpdateFunctionsWithResponse(ctx, s.project, toUpdate); err != nil {
×
71
                        return errors.Errorf("failed to bulk update: %w", err)
×
72
                } else if resp.JSON200 == nil {
×
73
                        return errors.Errorf("unexpected bulk update status %d: %s", resp.StatusCode(), string(resp.Body))
×
74
                }
×
75
        }
76
        return nil
2✔
77
}
78

79
func (s *EdgeRuntimeAPI) updateFunction(ctx context.Context, slug string, meta api.FunctionDeployMetadata, body io.Reader) (api.BulkUpdateFunctionBody, error) {
×
80
        resp, err := s.client.V1UpdateAFunctionWithBodyWithResponse(ctx, s.project, slug, &api.V1UpdateAFunctionParams{
×
81
                VerifyJwt:      meta.VerifyJwt,
×
82
                ImportMapPath:  meta.ImportMapPath,
×
83
                EntrypointPath: &meta.EntrypointPath,
×
84
        }, eszipContentType, body)
×
85
        if err != nil {
×
86
                return api.BulkUpdateFunctionBody{}, errors.Errorf("failed to update function: %w", err)
×
87
        } else if resp.JSON200 == nil {
×
88
                return api.BulkUpdateFunctionBody{}, errors.Errorf("unexpected update function status %d: %s", resp.StatusCode(), string(resp.Body))
×
89
        }
×
90
        return api.BulkUpdateFunctionBody{
×
91
                Id:             resp.JSON200.Id,
×
92
                Name:           resp.JSON200.Name,
×
93
                Slug:           resp.JSON200.Slug,
×
94
                Version:        resp.JSON200.Version,
×
95
                EntrypointPath: resp.JSON200.EntrypointPath,
×
96
                ImportMap:      resp.JSON200.ImportMap,
×
97
                ImportMapPath:  resp.JSON200.ImportMapPath,
×
98
                VerifyJwt:      resp.JSON200.VerifyJwt,
×
99
                Status:         api.BulkUpdateFunctionBodyStatus(resp.JSON200.Status),
×
100
                CreatedAt:      &resp.JSON200.CreatedAt,
×
101
        }, nil
×
102
}
103

104
func (s *EdgeRuntimeAPI) createFunction(ctx context.Context, slug string, meta api.FunctionDeployMetadata, body io.Reader) (api.BulkUpdateFunctionBody, error) {
×
105
        resp, err := s.client.V1CreateAFunctionWithBodyWithResponse(ctx, s.project, &api.V1CreateAFunctionParams{
×
106
                Slug:           &slug,
×
107
                Name:           &slug,
×
108
                VerifyJwt:      meta.VerifyJwt,
×
109
                ImportMapPath:  meta.ImportMapPath,
×
110
                EntrypointPath: &meta.EntrypointPath,
×
111
        }, eszipContentType, body)
×
112
        if err != nil {
×
113
                return api.BulkUpdateFunctionBody{}, errors.Errorf("failed to create function: %w", err)
×
114
        } else if resp.JSON201 == nil {
×
115
                return api.BulkUpdateFunctionBody{}, errors.Errorf("unexpected create function status %d: %s", resp.StatusCode(), string(resp.Body))
×
116
        }
×
117
        return api.BulkUpdateFunctionBody{
×
118
                Id:             resp.JSON201.Id,
×
119
                Name:           resp.JSON201.Name,
×
120
                Slug:           resp.JSON201.Slug,
×
121
                Version:        resp.JSON201.Version,
×
122
                EntrypointPath: resp.JSON201.EntrypointPath,
×
123
                ImportMap:      resp.JSON201.ImportMap,
×
124
                ImportMapPath:  resp.JSON201.ImportMapPath,
×
125
                VerifyJwt:      resp.JSON201.VerifyJwt,
×
126
                Status:         api.BulkUpdateFunctionBodyStatus(resp.JSON201.Status),
×
127
                CreatedAt:      &resp.JSON201.CreatedAt,
×
128
        }, nil
×
129
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc