···
"github.com/bluesky-social/indigo/atproto/syntax"
"tangled.sh/tangled.sh/core/api/tangled"
···
return vt.Type == ConcreteTypeBool
-
func (vt ValueType) IsEnumType() bool {
···
···
CreatedAt: l.Created.Format(time.RFC3339),
-
Scope: l.Scope.String(),
···
-
func LabelDefinitionFromRecord(did, rkey string, record tangled.LabelDefinition) LabelDefinition {
created, err := time.Parse(time.RFC3339, record.CreatedAt)
···
vt = ValueTypeFromRecord(*record.ValueType)
-
return LabelDefinition{
-
Scope: syntax.NSID(record.Scope),
func DeleteLabelDefinition(e Execer, filters ...filter) error {
···
func AddLabelDefinition(e Execer, l *LabelDefinition) (int64, error) {
`insert into label_definitions (
···
strings.Join(l.ValueType.Enum, ","),
l.Created.Format(time.RFC3339),
···
var labelDefinition LabelDefinition
-
var createdAt, enumVariants string
var color sql.Null[string]
···
&labelDefinition.ValueType.Type,
&labelDefinition.ValueType.Format,
-
&labelDefinition.Scope,
···
labelDefinition.ValueType.Enum = strings.Split(enumVariants, ",")
labelDefinitions = append(labelDefinitions, labelDefinition)
···
-
func (s *LabelState) GetValSet(l string) set {
type LabelApplicationCtx struct {
···
func (c *LabelApplicationCtx) ApplyLabelOp(state LabelState, op LabelOp) error {
-
def := c.Defs[op.OperandKey]
···
_ = c.ApplyLabelOp(state, o)
···
"github.com/bluesky-social/indigo/atproto/syntax"
"tangled.sh/tangled.sh/core/api/tangled"
+
"tangled.sh/tangled.sh/core/consts"
···
return vt.Type == ConcreteTypeBool
+
func (vt ValueType) IsEnum() bool {
···
···
CreatedAt: l.Created.Format(time.RFC3339),
···
+
func LabelDefinitionFromRecord(did, rkey string, record tangled.LabelDefinition) (*LabelDefinition, error) {
created, err := time.Parse(time.RFC3339, record.CreatedAt)
···
vt = ValueTypeFromRecord(*record.ValueType)
+
return &LabelDefinition{
func DeleteLabelDefinition(e Execer, filters ...filter) error {
···
+
// no updating type for now
func AddLabelDefinition(e Execer, l *LabelDefinition) (int64, error) {
`insert into label_definitions (
···
strings.Join(l.ValueType.Enum, ","),
+
strings.Join(l.Scope, ","),
l.Created.Format(time.RFC3339),
···
var labelDefinition LabelDefinition
+
var createdAt, enumVariants, scopes string
var color sql.Null[string]
···
&labelDefinition.ValueType.Type,
&labelDefinition.ValueType.Format,
···
labelDefinition.ValueType.Enum = strings.Split(enumVariants, ",")
+
for s := range strings.SplitSeq(scopes, ",") {
+
labelDefinition.Scope = append(labelDefinition.Scope, s)
labelDefinitions = append(labelDefinitions, labelDefinition)
···
+
// go maps behavior in templates make this necessary,
+
// indexing a map and getting `set` in return is apparently truthy
+
func (s LabelState) ContainsLabelAndVal(l, v string) bool {
+
if valset, exists := s.inner[l]; exists {
+
if _, exists := valset[v]; exists {
+
func (s LabelState) GetValSet(l string) set {
+
if valset, exists := s.inner[l]; exists {
type LabelApplicationCtx struct {
···
func (c *LabelApplicationCtx) ApplyLabelOp(state LabelState, op LabelOp) error {
+
def, ok := c.Defs[op.OperandKey]
+
// this def was deleted, but an op exists, so we just skip over the op
···
_ = c.ApplyLabelOp(state, o)
+
// IsInverse checks if one label operation is the inverse of another
+
// returns true if one is an add and the other is a delete with the same key and value
+
func (op1 LabelOp) IsInverse(op2 LabelOp) bool {
+
if op1.OperandKey != op2.OperandKey || op1.OperandValue != op2.OperandValue {
+
return (op1.Operation == LabelOperationAdd && op2.Operation == LabelOperationDel) ||
+
(op1.Operation == LabelOperationDel && op2.Operation == LabelOperationAdd)
+
// removes pairs of label operations that are inverses of each other
+
// from the given slice. the function preserves the order of remaining operations.
+
func ReduceLabelOps(ops []LabelOp) []LabelOp {
+
keep := make([]bool, len(ops))
+
for j := i + 1; j < len(ops); j++ {
+
if ops[i].IsInverse(ops[j]) {
+
break // move to next i since this one is now eliminated
+
// build result slice with only kept operations
+
for i, op := range ops {
+
result = append(result, op)
+
func DefaultLabelDefs() []string {
+
defs := make([]string, len(rkeys))
+
for i, r := range rkeys {
+
defs[i] = fmt.Sprintf("at://%s/%s/%s", consts.TangledDid, tangled.LabelDefinitionNSID, r)