github.com/cloudwan/edgelq-sdk@v1.15.4/alerting/resources/v1/document/document.pb.fieldpath.go (about) 1 // Code generated by protoc-gen-goten-object 2 // File: edgelq/alerting/proto/v1/document.proto 3 // DO NOT EDIT!!! 4 5 package document 6 7 import ( 8 "encoding/json" 9 "fmt" 10 "reflect" 11 "strings" 12 "time" 13 14 "google.golang.org/grpc/codes" 15 "google.golang.org/grpc/status" 16 "google.golang.org/protobuf/encoding/protojson" 17 "google.golang.org/protobuf/proto" 18 "google.golang.org/protobuf/reflect/protoregistry" 19 20 gotenobject "github.com/cloudwan/goten-sdk/runtime/object" 21 "github.com/cloudwan/goten-sdk/runtime/strcase" 22 ) 23 24 // proto imports 25 import ( 26 iam_project "github.com/cloudwan/edgelq-sdk/iam/resources/v1/project" 27 meta "github.com/cloudwan/goten-sdk/types/meta" 28 ) 29 30 // ensure the imports are used 31 var ( 32 _ = new(json.Marshaler) 33 _ = new(fmt.Stringer) 34 _ = reflect.DeepEqual 35 _ = strings.Builder{} 36 _ = time.Second 37 38 _ = strcase.ToLowerCamel 39 _ = codes.NotFound 40 _ = status.Status{} 41 _ = protojson.UnmarshalOptions{} 42 _ = new(proto.Message) 43 _ = protoregistry.GlobalTypes 44 45 _ = new(gotenobject.FieldPath) 46 ) 47 48 // make sure we're using proto imports 49 var ( 50 _ = &iam_project.Project{} 51 _ = &meta.Meta{} 52 ) 53 54 // FieldPath provides implementation to handle 55 // https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/field_mask.proto 56 type Document_FieldPath interface { 57 gotenobject.FieldPath 58 Selector() Document_FieldPathSelector 59 Get(source *Document) []interface{} 60 GetSingle(source *Document) (interface{}, bool) 61 ClearValue(item *Document) 62 63 // Those methods build corresponding Document_FieldPathValue 64 // (or array of values) and holds passed value. Panics if injected type is incorrect. 65 WithIValue(value interface{}) Document_FieldPathValue 66 WithIArrayOfValues(values interface{}) Document_FieldPathArrayOfValues 67 WithIArrayItemValue(value interface{}) Document_FieldPathArrayItemValue 68 } 69 70 type Document_FieldPathSelector int32 71 72 const ( 73 Document_FieldPathSelectorName Document_FieldPathSelector = 0 74 Document_FieldPathSelectorMetadata Document_FieldPathSelector = 1 75 Document_FieldPathSelectorTitle Document_FieldPathSelector = 2 76 Document_FieldPathSelectorContent Document_FieldPathSelector = 3 77 Document_FieldPathSelectorMimeType Document_FieldPathSelector = 4 78 ) 79 80 func (s Document_FieldPathSelector) String() string { 81 switch s { 82 case Document_FieldPathSelectorName: 83 return "name" 84 case Document_FieldPathSelectorMetadata: 85 return "metadata" 86 case Document_FieldPathSelectorTitle: 87 return "title" 88 case Document_FieldPathSelectorContent: 89 return "content" 90 case Document_FieldPathSelectorMimeType: 91 return "mime_type" 92 default: 93 panic(fmt.Sprintf("Invalid selector for Document: %d", s)) 94 } 95 } 96 97 func BuildDocument_FieldPath(fp gotenobject.RawFieldPath) (Document_FieldPath, error) { 98 if len(fp) == 0 { 99 return nil, status.Error(codes.InvalidArgument, "empty field path for object Document") 100 } 101 if len(fp) == 1 { 102 switch fp[0] { 103 case "name": 104 return &Document_FieldTerminalPath{selector: Document_FieldPathSelectorName}, nil 105 case "metadata": 106 return &Document_FieldTerminalPath{selector: Document_FieldPathSelectorMetadata}, nil 107 case "title": 108 return &Document_FieldTerminalPath{selector: Document_FieldPathSelectorTitle}, nil 109 case "content": 110 return &Document_FieldTerminalPath{selector: Document_FieldPathSelectorContent}, nil 111 case "mime_type", "mimeType", "mime-type": 112 return &Document_FieldTerminalPath{selector: Document_FieldPathSelectorMimeType}, nil 113 } 114 } else { 115 switch fp[0] { 116 case "metadata": 117 if subpath, err := meta.BuildMeta_FieldPath(fp[1:]); err != nil { 118 return nil, err 119 } else { 120 return &Document_FieldSubPath{selector: Document_FieldPathSelectorMetadata, subPath: subpath}, nil 121 } 122 } 123 } 124 return nil, status.Errorf(codes.InvalidArgument, "unknown field path '%s' for object Document", fp) 125 } 126 127 func ParseDocument_FieldPath(rawField string) (Document_FieldPath, error) { 128 fp, err := gotenobject.ParseRawFieldPath(rawField) 129 if err != nil { 130 return nil, err 131 } 132 return BuildDocument_FieldPath(fp) 133 } 134 135 func MustParseDocument_FieldPath(rawField string) Document_FieldPath { 136 fp, err := ParseDocument_FieldPath(rawField) 137 if err != nil { 138 panic(err) 139 } 140 return fp 141 } 142 143 type Document_FieldTerminalPath struct { 144 selector Document_FieldPathSelector 145 } 146 147 var _ Document_FieldPath = (*Document_FieldTerminalPath)(nil) 148 149 func (fp *Document_FieldTerminalPath) Selector() Document_FieldPathSelector { 150 return fp.selector 151 } 152 153 // String returns path representation in proto convention 154 func (fp *Document_FieldTerminalPath) String() string { 155 return fp.selector.String() 156 } 157 158 // JSONString returns path representation is JSON convention 159 func (fp *Document_FieldTerminalPath) JSONString() string { 160 return strcase.ToLowerCamel(fp.String()) 161 } 162 163 // Get returns all values pointed by specific field from source Document 164 func (fp *Document_FieldTerminalPath) Get(source *Document) (values []interface{}) { 165 if source != nil { 166 switch fp.selector { 167 case Document_FieldPathSelectorName: 168 if source.Name != nil { 169 values = append(values, source.Name) 170 } 171 case Document_FieldPathSelectorMetadata: 172 if source.Metadata != nil { 173 values = append(values, source.Metadata) 174 } 175 case Document_FieldPathSelectorTitle: 176 values = append(values, source.Title) 177 case Document_FieldPathSelectorContent: 178 values = append(values, source.Content) 179 case Document_FieldPathSelectorMimeType: 180 values = append(values, source.MimeType) 181 default: 182 panic(fmt.Sprintf("Invalid selector for Document: %d", fp.selector)) 183 } 184 } 185 return 186 } 187 188 func (fp *Document_FieldTerminalPath) GetRaw(source proto.Message) []interface{} { 189 return fp.Get(source.(*Document)) 190 } 191 192 // GetSingle returns value pointed by specific field of from source Document 193 func (fp *Document_FieldTerminalPath) GetSingle(source *Document) (interface{}, bool) { 194 switch fp.selector { 195 case Document_FieldPathSelectorName: 196 res := source.GetName() 197 return res, res != nil 198 case Document_FieldPathSelectorMetadata: 199 res := source.GetMetadata() 200 return res, res != nil 201 case Document_FieldPathSelectorTitle: 202 return source.GetTitle(), source != nil 203 case Document_FieldPathSelectorContent: 204 return source.GetContent(), source != nil 205 case Document_FieldPathSelectorMimeType: 206 return source.GetMimeType(), source != nil 207 default: 208 panic(fmt.Sprintf("Invalid selector for Document: %d", fp.selector)) 209 } 210 } 211 212 func (fp *Document_FieldTerminalPath) GetSingleRaw(source proto.Message) (interface{}, bool) { 213 return fp.GetSingle(source.(*Document)) 214 } 215 216 // GetDefault returns a default value of the field type 217 func (fp *Document_FieldTerminalPath) GetDefault() interface{} { 218 switch fp.selector { 219 case Document_FieldPathSelectorName: 220 return (*Name)(nil) 221 case Document_FieldPathSelectorMetadata: 222 return (*meta.Meta)(nil) 223 case Document_FieldPathSelectorTitle: 224 return "" 225 case Document_FieldPathSelectorContent: 226 return "" 227 case Document_FieldPathSelectorMimeType: 228 return "" 229 default: 230 panic(fmt.Sprintf("Invalid selector for Document: %d", fp.selector)) 231 } 232 } 233 234 func (fp *Document_FieldTerminalPath) ClearValue(item *Document) { 235 if item != nil { 236 switch fp.selector { 237 case Document_FieldPathSelectorName: 238 item.Name = nil 239 case Document_FieldPathSelectorMetadata: 240 item.Metadata = nil 241 case Document_FieldPathSelectorTitle: 242 item.Title = "" 243 case Document_FieldPathSelectorContent: 244 item.Content = "" 245 case Document_FieldPathSelectorMimeType: 246 item.MimeType = "" 247 default: 248 panic(fmt.Sprintf("Invalid selector for Document: %d", fp.selector)) 249 } 250 } 251 } 252 253 func (fp *Document_FieldTerminalPath) ClearValueRaw(item proto.Message) { 254 fp.ClearValue(item.(*Document)) 255 } 256 257 // IsLeaf - whether field path is holds simple value 258 func (fp *Document_FieldTerminalPath) IsLeaf() bool { 259 return fp.selector == Document_FieldPathSelectorName || 260 fp.selector == Document_FieldPathSelectorTitle || 261 fp.selector == Document_FieldPathSelectorContent || 262 fp.selector == Document_FieldPathSelectorMimeType 263 } 264 265 func (fp *Document_FieldTerminalPath) SplitIntoTerminalIPaths() []gotenobject.FieldPath { 266 return []gotenobject.FieldPath{fp} 267 } 268 269 func (fp *Document_FieldTerminalPath) WithIValue(value interface{}) Document_FieldPathValue { 270 switch fp.selector { 271 case Document_FieldPathSelectorName: 272 return &Document_FieldTerminalPathValue{Document_FieldTerminalPath: *fp, value: value.(*Name)} 273 case Document_FieldPathSelectorMetadata: 274 return &Document_FieldTerminalPathValue{Document_FieldTerminalPath: *fp, value: value.(*meta.Meta)} 275 case Document_FieldPathSelectorTitle: 276 return &Document_FieldTerminalPathValue{Document_FieldTerminalPath: *fp, value: value.(string)} 277 case Document_FieldPathSelectorContent: 278 return &Document_FieldTerminalPathValue{Document_FieldTerminalPath: *fp, value: value.(string)} 279 case Document_FieldPathSelectorMimeType: 280 return &Document_FieldTerminalPathValue{Document_FieldTerminalPath: *fp, value: value.(string)} 281 default: 282 panic(fmt.Sprintf("Invalid selector for Document: %d", fp.selector)) 283 } 284 } 285 286 func (fp *Document_FieldTerminalPath) WithRawIValue(value interface{}) gotenobject.FieldPathValue { 287 return fp.WithIValue(value) 288 } 289 290 func (fp *Document_FieldTerminalPath) WithIArrayOfValues(values interface{}) Document_FieldPathArrayOfValues { 291 fpaov := &Document_FieldTerminalPathArrayOfValues{Document_FieldTerminalPath: *fp} 292 switch fp.selector { 293 case Document_FieldPathSelectorName: 294 return &Document_FieldTerminalPathArrayOfValues{Document_FieldTerminalPath: *fp, values: values.([]*Name)} 295 case Document_FieldPathSelectorMetadata: 296 return &Document_FieldTerminalPathArrayOfValues{Document_FieldTerminalPath: *fp, values: values.([]*meta.Meta)} 297 case Document_FieldPathSelectorTitle: 298 return &Document_FieldTerminalPathArrayOfValues{Document_FieldTerminalPath: *fp, values: values.([]string)} 299 case Document_FieldPathSelectorContent: 300 return &Document_FieldTerminalPathArrayOfValues{Document_FieldTerminalPath: *fp, values: values.([]string)} 301 case Document_FieldPathSelectorMimeType: 302 return &Document_FieldTerminalPathArrayOfValues{Document_FieldTerminalPath: *fp, values: values.([]string)} 303 default: 304 panic(fmt.Sprintf("Invalid selector for Document: %d", fp.selector)) 305 } 306 return fpaov 307 } 308 309 func (fp *Document_FieldTerminalPath) WithRawIArrayOfValues(values interface{}) gotenobject.FieldPathArrayOfValues { 310 return fp.WithIArrayOfValues(values) 311 } 312 313 func (fp *Document_FieldTerminalPath) WithIArrayItemValue(value interface{}) Document_FieldPathArrayItemValue { 314 switch fp.selector { 315 default: 316 panic(fmt.Sprintf("Invalid selector for Document: %d", fp.selector)) 317 } 318 } 319 320 func (fp *Document_FieldTerminalPath) WithRawIArrayItemValue(value interface{}) gotenobject.FieldPathArrayItemValue { 321 return fp.WithIArrayItemValue(value) 322 } 323 324 type Document_FieldSubPath struct { 325 selector Document_FieldPathSelector 326 subPath gotenobject.FieldPath 327 } 328 329 var _ Document_FieldPath = (*Document_FieldSubPath)(nil) 330 331 func (fps *Document_FieldSubPath) Selector() Document_FieldPathSelector { 332 return fps.selector 333 } 334 func (fps *Document_FieldSubPath) AsMetadataSubPath() (meta.Meta_FieldPath, bool) { 335 res, ok := fps.subPath.(meta.Meta_FieldPath) 336 return res, ok 337 } 338 339 // String returns path representation in proto convention 340 func (fps *Document_FieldSubPath) String() string { 341 return fps.selector.String() + "." + fps.subPath.String() 342 } 343 344 // JSONString returns path representation is JSON convention 345 func (fps *Document_FieldSubPath) JSONString() string { 346 return strcase.ToLowerCamel(fps.selector.String()) + "." + fps.subPath.JSONString() 347 } 348 349 // Get returns all values pointed by selected field from source Document 350 func (fps *Document_FieldSubPath) Get(source *Document) (values []interface{}) { 351 switch fps.selector { 352 case Document_FieldPathSelectorMetadata: 353 values = append(values, fps.subPath.GetRaw(source.GetMetadata())...) 354 default: 355 panic(fmt.Sprintf("Invalid selector for Document: %d", fps.selector)) 356 } 357 return 358 } 359 360 func (fps *Document_FieldSubPath) GetRaw(source proto.Message) []interface{} { 361 return fps.Get(source.(*Document)) 362 } 363 364 // GetSingle returns value of selected field from source Document 365 func (fps *Document_FieldSubPath) GetSingle(source *Document) (interface{}, bool) { 366 switch fps.selector { 367 case Document_FieldPathSelectorMetadata: 368 if source.GetMetadata() == nil { 369 return nil, false 370 } 371 return fps.subPath.GetSingleRaw(source.GetMetadata()) 372 default: 373 panic(fmt.Sprintf("Invalid selector for Document: %d", fps.selector)) 374 } 375 } 376 377 func (fps *Document_FieldSubPath) GetSingleRaw(source proto.Message) (interface{}, bool) { 378 return fps.GetSingle(source.(*Document)) 379 } 380 381 // GetDefault returns a default value of the field type 382 func (fps *Document_FieldSubPath) GetDefault() interface{} { 383 return fps.subPath.GetDefault() 384 } 385 386 func (fps *Document_FieldSubPath) ClearValue(item *Document) { 387 if item != nil { 388 switch fps.selector { 389 case Document_FieldPathSelectorMetadata: 390 fps.subPath.ClearValueRaw(item.Metadata) 391 default: 392 panic(fmt.Sprintf("Invalid selector for Document: %d", fps.selector)) 393 } 394 } 395 } 396 397 func (fps *Document_FieldSubPath) ClearValueRaw(item proto.Message) { 398 fps.ClearValue(item.(*Document)) 399 } 400 401 // IsLeaf - whether field path is holds simple value 402 func (fps *Document_FieldSubPath) IsLeaf() bool { 403 return fps.subPath.IsLeaf() 404 } 405 406 func (fps *Document_FieldSubPath) SplitIntoTerminalIPaths() []gotenobject.FieldPath { 407 iPaths := []gotenobject.FieldPath{&Document_FieldTerminalPath{selector: fps.selector}} 408 iPaths = append(iPaths, fps.subPath.SplitIntoTerminalIPaths()...) 409 return iPaths 410 } 411 412 func (fps *Document_FieldSubPath) WithIValue(value interface{}) Document_FieldPathValue { 413 return &Document_FieldSubPathValue{fps, fps.subPath.WithRawIValue(value)} 414 } 415 416 func (fps *Document_FieldSubPath) WithRawIValue(value interface{}) gotenobject.FieldPathValue { 417 return fps.WithIValue(value) 418 } 419 420 func (fps *Document_FieldSubPath) WithIArrayOfValues(values interface{}) Document_FieldPathArrayOfValues { 421 return &Document_FieldSubPathArrayOfValues{fps, fps.subPath.WithRawIArrayOfValues(values)} 422 } 423 424 func (fps *Document_FieldSubPath) WithRawIArrayOfValues(values interface{}) gotenobject.FieldPathArrayOfValues { 425 return fps.WithIArrayOfValues(values) 426 } 427 428 func (fps *Document_FieldSubPath) WithIArrayItemValue(value interface{}) Document_FieldPathArrayItemValue { 429 return &Document_FieldSubPathArrayItemValue{fps, fps.subPath.WithRawIArrayItemValue(value)} 430 } 431 432 func (fps *Document_FieldSubPath) WithRawIArrayItemValue(value interface{}) gotenobject.FieldPathArrayItemValue { 433 return fps.WithIArrayItemValue(value) 434 } 435 436 // Document_FieldPathValue allows storing values for Document fields according to their type 437 type Document_FieldPathValue interface { 438 Document_FieldPath 439 gotenobject.FieldPathValue 440 SetTo(target **Document) 441 CompareWith(*Document) (cmp int, comparable bool) 442 } 443 444 func ParseDocument_FieldPathValue(pathStr, valueStr string) (Document_FieldPathValue, error) { 445 fp, err := ParseDocument_FieldPath(pathStr) 446 if err != nil { 447 return nil, err 448 } 449 fpv, err := gotenobject.ParseFieldPathValue(fp, valueStr) 450 if err != nil { 451 return nil, status.Errorf(codes.InvalidArgument, "error parsing Document field path value from %s: %v", valueStr, err) 452 } 453 return fpv.(Document_FieldPathValue), nil 454 } 455 456 func MustParseDocument_FieldPathValue(pathStr, valueStr string) Document_FieldPathValue { 457 fpv, err := ParseDocument_FieldPathValue(pathStr, valueStr) 458 if err != nil { 459 panic(err) 460 } 461 return fpv 462 } 463 464 type Document_FieldTerminalPathValue struct { 465 Document_FieldTerminalPath 466 value interface{} 467 } 468 469 var _ Document_FieldPathValue = (*Document_FieldTerminalPathValue)(nil) 470 471 // GetRawValue returns raw value stored under selected path for 'Document' as interface{} 472 func (fpv *Document_FieldTerminalPathValue) GetRawValue() interface{} { 473 return fpv.value 474 } 475 func (fpv *Document_FieldTerminalPathValue) AsNameValue() (*Name, bool) { 476 res, ok := fpv.value.(*Name) 477 return res, ok 478 } 479 func (fpv *Document_FieldTerminalPathValue) AsMetadataValue() (*meta.Meta, bool) { 480 res, ok := fpv.value.(*meta.Meta) 481 return res, ok 482 } 483 func (fpv *Document_FieldTerminalPathValue) AsTitleValue() (string, bool) { 484 res, ok := fpv.value.(string) 485 return res, ok 486 } 487 func (fpv *Document_FieldTerminalPathValue) AsContentValue() (string, bool) { 488 res, ok := fpv.value.(string) 489 return res, ok 490 } 491 func (fpv *Document_FieldTerminalPathValue) AsMimeTypeValue() (string, bool) { 492 res, ok := fpv.value.(string) 493 return res, ok 494 } 495 496 // SetTo stores value for selected field for object Document 497 func (fpv *Document_FieldTerminalPathValue) SetTo(target **Document) { 498 if *target == nil { 499 *target = new(Document) 500 } 501 switch fpv.selector { 502 case Document_FieldPathSelectorName: 503 (*target).Name = fpv.value.(*Name) 504 case Document_FieldPathSelectorMetadata: 505 (*target).Metadata = fpv.value.(*meta.Meta) 506 case Document_FieldPathSelectorTitle: 507 (*target).Title = fpv.value.(string) 508 case Document_FieldPathSelectorContent: 509 (*target).Content = fpv.value.(string) 510 case Document_FieldPathSelectorMimeType: 511 (*target).MimeType = fpv.value.(string) 512 default: 513 panic(fmt.Sprintf("Invalid selector for Document: %d", fpv.selector)) 514 } 515 } 516 517 func (fpv *Document_FieldTerminalPathValue) SetToRaw(target proto.Message) { 518 typedObject := target.(*Document) 519 fpv.SetTo(&typedObject) 520 } 521 522 // CompareWith compares value in the 'Document_FieldTerminalPathValue' with the value under path in 'Document'. 523 func (fpv *Document_FieldTerminalPathValue) CompareWith(source *Document) (int, bool) { 524 switch fpv.selector { 525 case Document_FieldPathSelectorName: 526 leftValue := fpv.value.(*Name) 527 rightValue := source.GetName() 528 if leftValue == nil { 529 if rightValue != nil { 530 return -1, true 531 } 532 return 0, true 533 } 534 if rightValue == nil { 535 return 1, true 536 } 537 if leftValue.String() == rightValue.String() { 538 return 0, true 539 } else if leftValue.String() < rightValue.String() { 540 return -1, true 541 } else { 542 return 1, true 543 } 544 case Document_FieldPathSelectorMetadata: 545 return 0, false 546 case Document_FieldPathSelectorTitle: 547 leftValue := fpv.value.(string) 548 rightValue := source.GetTitle() 549 if (leftValue) == (rightValue) { 550 return 0, true 551 } else if (leftValue) < (rightValue) { 552 return -1, true 553 } else { 554 return 1, true 555 } 556 case Document_FieldPathSelectorContent: 557 leftValue := fpv.value.(string) 558 rightValue := source.GetContent() 559 if (leftValue) == (rightValue) { 560 return 0, true 561 } else if (leftValue) < (rightValue) { 562 return -1, true 563 } else { 564 return 1, true 565 } 566 case Document_FieldPathSelectorMimeType: 567 leftValue := fpv.value.(string) 568 rightValue := source.GetMimeType() 569 if (leftValue) == (rightValue) { 570 return 0, true 571 } else if (leftValue) < (rightValue) { 572 return -1, true 573 } else { 574 return 1, true 575 } 576 default: 577 panic(fmt.Sprintf("Invalid selector for Document: %d", fpv.selector)) 578 } 579 } 580 581 func (fpv *Document_FieldTerminalPathValue) CompareWithRaw(source proto.Message) (int, bool) { 582 return fpv.CompareWith(source.(*Document)) 583 } 584 585 type Document_FieldSubPathValue struct { 586 Document_FieldPath 587 subPathValue gotenobject.FieldPathValue 588 } 589 590 var _ Document_FieldPathValue = (*Document_FieldSubPathValue)(nil) 591 592 func (fpvs *Document_FieldSubPathValue) AsMetadataPathValue() (meta.Meta_FieldPathValue, bool) { 593 res, ok := fpvs.subPathValue.(meta.Meta_FieldPathValue) 594 return res, ok 595 } 596 597 func (fpvs *Document_FieldSubPathValue) SetTo(target **Document) { 598 if *target == nil { 599 *target = new(Document) 600 } 601 switch fpvs.Selector() { 602 case Document_FieldPathSelectorMetadata: 603 fpvs.subPathValue.(meta.Meta_FieldPathValue).SetTo(&(*target).Metadata) 604 default: 605 panic(fmt.Sprintf("Invalid selector for Document: %d", fpvs.Selector())) 606 } 607 } 608 609 func (fpvs *Document_FieldSubPathValue) SetToRaw(target proto.Message) { 610 typedObject := target.(*Document) 611 fpvs.SetTo(&typedObject) 612 } 613 614 func (fpvs *Document_FieldSubPathValue) GetRawValue() interface{} { 615 return fpvs.subPathValue.GetRawValue() 616 } 617 618 func (fpvs *Document_FieldSubPathValue) CompareWith(source *Document) (int, bool) { 619 switch fpvs.Selector() { 620 case Document_FieldPathSelectorMetadata: 621 return fpvs.subPathValue.(meta.Meta_FieldPathValue).CompareWith(source.GetMetadata()) 622 default: 623 panic(fmt.Sprintf("Invalid selector for Document: %d", fpvs.Selector())) 624 } 625 } 626 627 func (fpvs *Document_FieldSubPathValue) CompareWithRaw(source proto.Message) (int, bool) { 628 return fpvs.CompareWith(source.(*Document)) 629 } 630 631 // Document_FieldPathArrayItemValue allows storing single item in Path-specific values for Document according to their type 632 // Present only for array (repeated) types. 633 type Document_FieldPathArrayItemValue interface { 634 gotenobject.FieldPathArrayItemValue 635 Document_FieldPath 636 ContainsValue(*Document) bool 637 } 638 639 // ParseDocument_FieldPathArrayItemValue parses string and JSON-encoded value to its Value 640 func ParseDocument_FieldPathArrayItemValue(pathStr, valueStr string) (Document_FieldPathArrayItemValue, error) { 641 fp, err := ParseDocument_FieldPath(pathStr) 642 if err != nil { 643 return nil, err 644 } 645 fpaiv, err := gotenobject.ParseFieldPathArrayItemValue(fp, valueStr) 646 if err != nil { 647 return nil, status.Errorf(codes.InvalidArgument, "error parsing Document field path array item value from %s: %v", valueStr, err) 648 } 649 return fpaiv.(Document_FieldPathArrayItemValue), nil 650 } 651 652 func MustParseDocument_FieldPathArrayItemValue(pathStr, valueStr string) Document_FieldPathArrayItemValue { 653 fpaiv, err := ParseDocument_FieldPathArrayItemValue(pathStr, valueStr) 654 if err != nil { 655 panic(err) 656 } 657 return fpaiv 658 } 659 660 type Document_FieldTerminalPathArrayItemValue struct { 661 Document_FieldTerminalPath 662 value interface{} 663 } 664 665 var _ Document_FieldPathArrayItemValue = (*Document_FieldTerminalPathArrayItemValue)(nil) 666 667 // GetRawValue returns stored element value for array in object Document as interface{} 668 func (fpaiv *Document_FieldTerminalPathArrayItemValue) GetRawItemValue() interface{} { 669 return fpaiv.value 670 } 671 672 func (fpaiv *Document_FieldTerminalPathArrayItemValue) GetSingle(source *Document) (interface{}, bool) { 673 return nil, false 674 } 675 676 func (fpaiv *Document_FieldTerminalPathArrayItemValue) GetSingleRaw(source proto.Message) (interface{}, bool) { 677 return fpaiv.GetSingle(source.(*Document)) 678 } 679 680 // Contains returns a boolean indicating if value that is being held is present in given 'Document' 681 func (fpaiv *Document_FieldTerminalPathArrayItemValue) ContainsValue(source *Document) bool { 682 slice := fpaiv.Document_FieldTerminalPath.Get(source) 683 for _, v := range slice { 684 if asProtoMsg, ok := fpaiv.value.(proto.Message); ok { 685 if proto.Equal(asProtoMsg, v.(proto.Message)) { 686 return true 687 } 688 } else if reflect.DeepEqual(v, fpaiv.value) { 689 return true 690 } 691 } 692 return false 693 } 694 695 type Document_FieldSubPathArrayItemValue struct { 696 Document_FieldPath 697 subPathItemValue gotenobject.FieldPathArrayItemValue 698 } 699 700 // GetRawValue returns stored array item value 701 func (fpaivs *Document_FieldSubPathArrayItemValue) GetRawItemValue() interface{} { 702 return fpaivs.subPathItemValue.GetRawItemValue() 703 } 704 func (fpaivs *Document_FieldSubPathArrayItemValue) AsMetadataPathItemValue() (meta.Meta_FieldPathArrayItemValue, bool) { 705 res, ok := fpaivs.subPathItemValue.(meta.Meta_FieldPathArrayItemValue) 706 return res, ok 707 } 708 709 // Contains returns a boolean indicating if value that is being held is present in given 'Document' 710 func (fpaivs *Document_FieldSubPathArrayItemValue) ContainsValue(source *Document) bool { 711 switch fpaivs.Selector() { 712 case Document_FieldPathSelectorMetadata: 713 return fpaivs.subPathItemValue.(meta.Meta_FieldPathArrayItemValue).ContainsValue(source.GetMetadata()) 714 default: 715 panic(fmt.Sprintf("Invalid selector for Document: %d", fpaivs.Selector())) 716 } 717 } 718 719 // Document_FieldPathArrayOfValues allows storing slice of values for Document fields according to their type 720 type Document_FieldPathArrayOfValues interface { 721 gotenobject.FieldPathArrayOfValues 722 Document_FieldPath 723 } 724 725 func ParseDocument_FieldPathArrayOfValues(pathStr, valuesStr string) (Document_FieldPathArrayOfValues, error) { 726 fp, err := ParseDocument_FieldPath(pathStr) 727 if err != nil { 728 return nil, err 729 } 730 fpaov, err := gotenobject.ParseFieldPathArrayOfValues(fp, valuesStr) 731 if err != nil { 732 return nil, status.Errorf(codes.InvalidArgument, "error parsing Document field path array of values from %s: %v", valuesStr, err) 733 } 734 return fpaov.(Document_FieldPathArrayOfValues), nil 735 } 736 737 func MustParseDocument_FieldPathArrayOfValues(pathStr, valuesStr string) Document_FieldPathArrayOfValues { 738 fpaov, err := ParseDocument_FieldPathArrayOfValues(pathStr, valuesStr) 739 if err != nil { 740 panic(err) 741 } 742 return fpaov 743 } 744 745 type Document_FieldTerminalPathArrayOfValues struct { 746 Document_FieldTerminalPath 747 values interface{} 748 } 749 750 var _ Document_FieldPathArrayOfValues = (*Document_FieldTerminalPathArrayOfValues)(nil) 751 752 func (fpaov *Document_FieldTerminalPathArrayOfValues) GetRawValues() (values []interface{}) { 753 switch fpaov.selector { 754 case Document_FieldPathSelectorName: 755 for _, v := range fpaov.values.([]*Name) { 756 values = append(values, v) 757 } 758 case Document_FieldPathSelectorMetadata: 759 for _, v := range fpaov.values.([]*meta.Meta) { 760 values = append(values, v) 761 } 762 case Document_FieldPathSelectorTitle: 763 for _, v := range fpaov.values.([]string) { 764 values = append(values, v) 765 } 766 case Document_FieldPathSelectorContent: 767 for _, v := range fpaov.values.([]string) { 768 values = append(values, v) 769 } 770 case Document_FieldPathSelectorMimeType: 771 for _, v := range fpaov.values.([]string) { 772 values = append(values, v) 773 } 774 } 775 return 776 } 777 func (fpaov *Document_FieldTerminalPathArrayOfValues) AsNameArrayOfValues() ([]*Name, bool) { 778 res, ok := fpaov.values.([]*Name) 779 return res, ok 780 } 781 func (fpaov *Document_FieldTerminalPathArrayOfValues) AsMetadataArrayOfValues() ([]*meta.Meta, bool) { 782 res, ok := fpaov.values.([]*meta.Meta) 783 return res, ok 784 } 785 func (fpaov *Document_FieldTerminalPathArrayOfValues) AsTitleArrayOfValues() ([]string, bool) { 786 res, ok := fpaov.values.([]string) 787 return res, ok 788 } 789 func (fpaov *Document_FieldTerminalPathArrayOfValues) AsContentArrayOfValues() ([]string, bool) { 790 res, ok := fpaov.values.([]string) 791 return res, ok 792 } 793 func (fpaov *Document_FieldTerminalPathArrayOfValues) AsMimeTypeArrayOfValues() ([]string, bool) { 794 res, ok := fpaov.values.([]string) 795 return res, ok 796 } 797 798 type Document_FieldSubPathArrayOfValues struct { 799 Document_FieldPath 800 subPathArrayOfValues gotenobject.FieldPathArrayOfValues 801 } 802 803 var _ Document_FieldPathArrayOfValues = (*Document_FieldSubPathArrayOfValues)(nil) 804 805 func (fpsaov *Document_FieldSubPathArrayOfValues) GetRawValues() []interface{} { 806 return fpsaov.subPathArrayOfValues.GetRawValues() 807 } 808 func (fpsaov *Document_FieldSubPathArrayOfValues) AsMetadataPathArrayOfValues() (meta.Meta_FieldPathArrayOfValues, bool) { 809 res, ok := fpsaov.subPathArrayOfValues.(meta.Meta_FieldPathArrayOfValues) 810 return res, ok 811 }