MCPcopy
hub / github.com/pocketbase/pocketbase / normalizeExpands

Function normalizeExpands

core/record_query_expand.go:260–291  ·  view source on GitHub ↗

normalizeExpands normalizes expand strings and merges self containing paths (eg. ["a.b.c", "a.b", " test ", " ", "test"] -> ["a.b.c", "test"]).

(paths []string)

Source from the content-addressed store, hash-verified

258// normalizeExpands normalizes expand strings and merges self containing paths
259// (eg. ["a.b.c", "a.b", " test ", " ", "test"] -> ["a.b.c", "test"]).
260func normalizeExpands(paths []string) []string {
261 // normalize paths
262 normalized := make([]string, 0, len(paths))
263 for _, p := range paths {
264 p = strings.ReplaceAll(p, " ", "") // replace spaces
265 p = strings.Trim(p, ".") // trim incomplete paths
266 if p != "" {
267 normalized = append(normalized, p)
268 }
269 }
270
271 // merge containing paths
272 result := make([]string, 0, len(normalized))
273 for i, p1 := range normalized {
274 var skip bool
275 for j, p2 := range normalized {
276 if i == j {
277 continue
278 }
279 if strings.HasPrefix(p2, p1+".") {
280 // skip because there is more detailed expand path
281 skip = true
282 break
283 }
284 }
285 if !skip {
286 result = append(result, p1)
287 }
288 }
289
290 return list.ToUniqueStringSlice(result)
291}

Callers 1

ExpandRecordsMethod · 0.85

Calls 1

ToUniqueStringSliceFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…