~bigbes/sr-ht-dolt

ref: bd2d8a3680e62716440ea0165d2271d79f9d526e sr-ht-dolt/graph/model/models_gen.go -rw-r--r-- 4.2 KiB
bd2d8a36 — Eugene Blikh doltsrht: serve /query and the api-meta.json beside it 3 days ago
                                                                                
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.

package model

import (
	"bytes"
	"fmt"
	"io"
	"strconv"
	"time"

	"sourcecraft.dev/bigbes/sr-ht-core/model"
)

// An access grant on a database.
type ACLEntry struct {
	User *User      `json:"user"`
	Mode AccessMode `json:"mode"`
}

// A branch and the commit it points at.
type Branch struct {
	Name string `json:"name"`
	Head string `json:"head"`
}

// A column of a table, as the stored schema declares it.
type Column struct {
	Name       string `json:"name"`
	Type       string `json:"type"`
	PrimaryKey bool   `json:"primaryKey"`
	Nullable   bool   `json:"nullable"`
}

// One commit of a database's history.
type Commit struct {
	Hash    string    `json:"hash"`
	Author  string    `json:"author"`
	Email   string    `json:"email"`
	Date    time.Time `json:"date"`
	Message string    `json:"message"`
	Parents []string  `json:"parents"`
}

type CommitCursor struct {
	Results []*Commit     `json:"results"`
	Cursor  *model.Cursor `json:"cursor,omitempty"`
}

type DatabaseCursor struct {
	Results []*Database   `json:"results"`
	Cursor  *model.Cursor `json:"cursor,omitempty"`
}

type Query struct {
}

// A table at a ref: its schema and how many rows it holds there.
type Table struct {
	Name     string    `json:"name"`
	Columns  []*Column `json:"columns"`
	RowCount int       `json:"rowCount"`
}

// A SourceHut account, mirrored from meta.sr.ht.
type User struct {
	// The username with no leading "~". This is the name that addresses the account
	// in `database(owner:)` and in a clone URL's path.
	Username string `json:"username"`
	// The username with its leading "~", as SourceHut writes it in prose and in the
	// web UI.
	CanonicalName string `json:"canonicalName"`
}

// An ACL grant: read-only (browse and clone) or read-write (and push).
type AccessMode string

const (
	AccessModeRo AccessMode = "RO"
	AccessModeRw AccessMode = "RW"
)

var AllAccessMode = []AccessMode{
	AccessModeRo,
	AccessModeRw,
}

func (e AccessMode) IsValid() bool {
	switch e {
	case AccessModeRo, AccessModeRw:
		return true
	}
	return false
}

func (e AccessMode) String() string {
	return string(e)
}

func (e *AccessMode) UnmarshalGQL(v any) error {
	str, ok := v.(string)
	if !ok {
		return fmt.Errorf("enums must be strings")
	}

	*e = AccessMode(str)
	if !e.IsValid() {
		return fmt.Errorf("%s is not a valid AccessMode", str)
	}
	return nil
}

func (e AccessMode) MarshalGQL(w io.Writer) {
	fmt.Fprint(w, strconv.Quote(e.String()))
}

func (e *AccessMode) UnmarshalJSON(b []byte) error {
	s, err := strconv.Unquote(string(b))
	if err != nil {
		return err
	}
	return e.UnmarshalGQL(s)
}

func (e AccessMode) MarshalJSON() ([]byte, error) {
	var buf bytes.Buffer
	e.MarshalGQL(&buf)
	return buf.Bytes(), nil
}

// Who may see a database, and how it is listed.
//
// PUBLIC is listed to everyone including anonymous callers. UNLISTED is reachable
// by direct address but never appears in a listing to a stranger. PRIVATE is
// neither: to a caller who may not see it, it does not exist — this schema answers
// null rather than an authorization error, exactly as the web UI answers "no such
// database" rather than "forbidden".
type Visibility string

const (
	VisibilityPublic   Visibility = "PUBLIC"
	VisibilityUnlisted Visibility = "UNLISTED"
	VisibilityPrivate  Visibility = "PRIVATE"
)

var AllVisibility = []Visibility{
	VisibilityPublic,
	VisibilityUnlisted,
	VisibilityPrivate,
}

func (e Visibility) IsValid() bool {
	switch e {
	case VisibilityPublic, VisibilityUnlisted, VisibilityPrivate:
		return true
	}
	return false
}

func (e Visibility) String() string {
	return string(e)
}

func (e *Visibility) UnmarshalGQL(v any) error {
	str, ok := v.(string)
	if !ok {
		return fmt.Errorf("enums must be strings")
	}

	*e = Visibility(str)
	if !e.IsValid() {
		return fmt.Errorf("%s is not a valid Visibility", str)
	}
	return nil
}

func (e Visibility) MarshalGQL(w io.Writer) {
	fmt.Fprint(w, strconv.Quote(e.String()))
}

func (e *Visibility) UnmarshalJSON(b []byte) error {
	s, err := strconv.Unquote(string(b))
	if err != nil {
		return err
	}
	return e.UnmarshalGQL(s)
}

func (e Visibility) MarshalJSON() ([]byte, error) {
	var buf bytes.Buffer
	e.MarshalGQL(&buf)
	return buf.Bytes(), nil
}