@@ -69,26 +69,26 @@ func (F) isFilter() {}
6969// }
7070type A []any
7171
72- // FilterOperator represents the operation type (Eq, Gt, etc.)
73- type FilterOperator string
72+ // Operator represents the operation type (Eq, Gt, etc.)
73+ type Operator string
7474
7575const (
76- OpAnd FilterOperator = "$and"
77- OpOr FilterOperator = "$or"
78- OpNot FilterOperator = "$not"
79- OpGreaterThan FilterOperator = "$gt"
80- OpGreaterThanEqual FilterOperator = "$gte"
81- OpLessThan FilterOperator = "$lt"
82- OpLessThanEqual FilterOperator = "$lte"
83- OpEqual FilterOperator = "$eq"
84- OpNotEqual FilterOperator = "$ne"
85- OpIn FilterOperator = "$in"
86- OpNotIn FilterOperator = "$nin"
87- OpExists FilterOperator = "$exists"
88- OpAll FilterOperator = "$all"
89- OpSize FilterOperator = "$size"
90- OpLexical FilterOperator = "$lexical"
91- OpMatch FilterOperator = "$match"
76+ OpAnd Operator = "$and"
77+ OpOr Operator = "$or"
78+ OpNot Operator = "$not"
79+ OpGreaterThan Operator = "$gt"
80+ OpGreaterThanEqual Operator = "$gte"
81+ OpLessThan Operator = "$lt"
82+ OpLessThanEqual Operator = "$lte"
83+ OpEqual Operator = "$eq"
84+ OpNotEqual Operator = "$ne"
85+ OpIn Operator = "$in"
86+ OpNotIn Operator = "$nin"
87+ OpExists Operator = "$exists"
88+ OpAll Operator = "$all"
89+ OpSize Operator = "$size"
90+ OpLexical Operator = "$lexical"
91+ OpMatch Operator = "$match"
9292)
9393
9494// Filter represents a collection of filters. Compose filters with
@@ -106,33 +106,33 @@ const (
106106// )
107107type Filter struct {
108108 // The operator. Such as "$or"
109- op FilterOperator
109+ op Operator
110110 // The field to perform an operation on. Example: "_id".
111111 field string
112112 // The value to filter for based on `op`.
113113 value any
114114 // Child filters. Should never be populated if field/value are also populated.
115- children [] Filter
115+ children any
116116}
117117
118118// Satisfy interface to allow Filter to be used as a filter.
119119func (Filter ) isFilter () {}
120120
121121// Construct a field filter operator. Used to reduce boilerplate.
122- func fieldOp (op FilterOperator , field string , value any ) Filter {
122+ func fieldOp (op Operator , field string , value any ) Filter {
123123 return Filter {op : op , field : field , value : value }
124124}
125125
126126// Construct a slice filter operator. Used to reduce boilerplate.
127- func sliceOp (op FilterOperator , field string , vals []any ) Filter {
127+ func sliceOp (op Operator , field string , vals []any ) Filter {
128128 return Filter {op : op , field : field , value : vals }
129129}
130130
131131func (f Filter ) MarshalAstraRaw (ctx serdes.EncodeCtx , dst []byte ) ([]byte , error ) {
132- if len ( f .children ) > 0 {
132+ if f .children != nil {
133133 // We have child commands. Create a map and marshal them like this:
134134 // "$or": [...]
135- filters := make (map [FilterOperator ][] Filter )
135+ filters := make (map [Operator ] any )
136136 filters [f .op ] = f .children
137137 return serdes .SerializeInto (filters , ctx .Target , dst , ctx .Flags )
138138 }
@@ -146,8 +146,8 @@ func (f Filter) MarshalAstraRaw(ctx serdes.EncodeCtx, dst []byte) ([]byte, error
146146 }
147147 // We have another op. Marshal it into something like:
148148 // "number_of_pages": { "$lt": 300 }
149- filters := make (map [string ]map [FilterOperator ]any )
150- filters [f .field ] = map [FilterOperator ]any {f .op : f .value }
149+ filters := make (map [string ]map [Operator ]any )
150+ filters [f .field ] = map [Operator ]any {f .op : f .value }
151151 return serdes .SerializeInto (filters , ctx .Target , dst , ctx .Flags )
152152 }
153153 return append (dst , "null" ... ), nil
@@ -182,7 +182,10 @@ func Or(children ...Filter) Filter {
182182}
183183
184184func Not (child Filter ) Filter {
185- return Filter {op : OpNot , children : []Filter {child }}
185+ return Filter {
186+ op : OpNot ,
187+ children : child ,
188+ }
186189}
187190
188191// LexicalMatch creates a filter that matches documents against the collection's
0 commit comments