···
"github.com/bluesky-social/indigo/atproto/syntax"
"tangled.sh/tangled.sh/core/api/tangled"
16
+
"tangled.sh/tangled.sh/core/consts"
···
return vt.Type == ConcreteTypeBool
80
-
func (vt ValueType) IsEnumType() bool {
81
+
func (vt ValueType) IsEnum() bool {
···
···
CreatedAt: l.Created.Format(time.RFC3339),
116
-
Scope: l.Scope.String(),
···
142
-
func LabelDefinitionFromRecord(did, rkey string, record tangled.LabelDefinition) LabelDefinition {
143
+
func LabelDefinitionFromRecord(did, rkey string, record tangled.LabelDefinition) (*LabelDefinition, error) {
created, err := time.Parse(time.RFC3339, record.CreatedAt)
···
vt = ValueTypeFromRecord(*record.ValueType)
158
-
return LabelDefinition{
159
+
return &LabelDefinition{
164
-
Scope: syntax.NSID(record.Scope),
165
+
Scope: record.Scope,
func DeleteLabelDefinition(e Execer, filters ...filter) error {
···
188
+
// no updating type for now
func AddLabelDefinition(e Execer, l *LabelDefinition) (int64, error) {
`insert into label_definitions (
···
strings.Join(l.ValueType.Enum, ","),
215
+
strings.Join(l.Scope, ","),
l.Created.Format(time.RFC3339),
···
var labelDefinition LabelDefinition
277
-
var createdAt, enumVariants string
279
+
var createdAt, enumVariants, scopes string
var color sql.Null[string]
···
&labelDefinition.ValueType.Type,
&labelDefinition.ValueType.Format,
289
-
&labelDefinition.Scope,
···
labelDefinition.ValueType.Enum = strings.Split(enumVariants, ",")
316
+
for s := range strings.SplitSeq(scopes, ",") {
317
+
labelDefinition.Scope = append(labelDefinition.Scope, s)
labelDefinitions = append(labelDefinitions, labelDefinition)
···
634
-
func (s *LabelState) GetValSet(l string) set {
640
+
// go maps behavior in templates make this necessary,
641
+
// indexing a map and getting `set` in return is apparently truthy
642
+
func (s LabelState) ContainsLabelAndVal(l, v string) bool {
643
+
if valset, exists := s.inner[l]; exists {
644
+
if _, exists := valset[v]; exists {
652
+
func (s LabelState) GetValSet(l string) set {
653
+
if valset, exists := s.inner[l]; exists {
type LabelApplicationCtx struct {
···
func (c *LabelApplicationCtx) ApplyLabelOp(state LabelState, op LabelOp) error {
661
-
def := c.Defs[op.OperandKey]
683
+
def, ok := c.Defs[op.OperandKey]
685
+
// this def was deleted, but an op exists, so we just skip over the op
···
_ = c.ApplyLabelOp(state, o)
749
+
// IsInverse checks if one label operation is the inverse of another
750
+
// returns true if one is an add and the other is a delete with the same key and value
751
+
func (op1 LabelOp) IsInverse(op2 LabelOp) bool {
752
+
if op1.OperandKey != op2.OperandKey || op1.OperandValue != op2.OperandValue {
756
+
return (op1.Operation == LabelOperationAdd && op2.Operation == LabelOperationDel) ||
757
+
(op1.Operation == LabelOperationDel && op2.Operation == LabelOperationAdd)
760
+
// removes pairs of label operations that are inverses of each other
761
+
// from the given slice. the function preserves the order of remaining operations.
762
+
func ReduceLabelOps(ops []LabelOp) []LabelOp {
767
+
keep := make([]bool, len(ops))
768
+
for i := range keep {
772
+
for i := range ops {
777
+
for j := i + 1; j < len(ops); j++ {
782
+
if ops[i].IsInverse(ops[j]) {
785
+
break // move to next i since this one is now eliminated
790
+
// build result slice with only kept operations
791
+
var result []LabelOp
792
+
for i, op := range ops {
794
+
result = append(result, op)
801
+
func DefaultLabelDefs() []string {
806
+
"good-first-issue",
810
+
defs := make([]string, len(rkeys))
811
+
for i, r := range rkeys {
812
+
defs[i] = fmt.Sprintf("at://%s/%s/%s", consts.TangledDid, tangled.LabelDefinitionNSID, r)