github.com/cloudwan/edgelq-sdk@v1.15.4/alerting/resources/v1/document/document.pb.access.go (about)

     1  // Code generated by protoc-gen-goten-resource
     2  // Resource: Document
     3  // DO NOT EDIT!!!
     4  
     5  package document
     6  
     7  import (
     8  	"context"
     9  
    10  	"google.golang.org/grpc/codes"
    11  	"google.golang.org/grpc/status"
    12  
    13  	gotenobject "github.com/cloudwan/goten-sdk/runtime/object"
    14  	gotenresource "github.com/cloudwan/goten-sdk/runtime/resource"
    15  	"github.com/cloudwan/goten-sdk/types/watch_type"
    16  )
    17  
    18  // proto imports
    19  import (
    20  	iam_project "github.com/cloudwan/edgelq-sdk/iam/resources/v1/project"
    21  	meta "github.com/cloudwan/goten-sdk/types/meta"
    22  )
    23  
    24  // ensure the imports are used
    25  var (
    26  	_ = new(context.Context)
    27  
    28  	_ = codes.Internal
    29  	_ = status.Status{}
    30  
    31  	_ = watch_type.WatchType_STATEFUL
    32  	_ = new(gotenobject.FieldPath)
    33  	_ = new(gotenresource.ListQuery)
    34  )
    35  
    36  // make sure we're using proto imports
    37  var (
    38  	_ = &iam_project.Project{}
    39  	_ = &meta.Meta{}
    40  )
    41  
    42  type DocumentAccess interface {
    43  	GetDocument(context.Context, *GetQuery, ...gotenresource.GetOption) (*Document, error)
    44  	BatchGetDocuments(context.Context, []*Reference, ...gotenresource.BatchGetOption) error
    45  	QueryDocuments(context.Context, *ListQuery, ...gotenresource.QueryOption) (*QueryResultSnapshot, error)
    46  	SearchDocuments(context.Context, *SearchQuery, ...gotenresource.QueryOption) (*QueryResultSnapshot, error)
    47  	WatchDocument(context.Context, *GetQuery, func(*DocumentChange) error) error
    48  	WatchDocuments(context.Context, *WatchQuery, func(*QueryResultChange) error) error
    49  	SaveDocument(context.Context, *Document, ...gotenresource.SaveOption) error
    50  	DeleteDocument(context.Context, *Reference, ...gotenresource.DeleteOption) error
    51  }
    52  
    53  type anyCastAccess struct {
    54  	DocumentAccess
    55  }
    56  
    57  func AsAnyCastAccess(access DocumentAccess) gotenresource.Access {
    58  	return &anyCastAccess{DocumentAccess: access}
    59  }
    60  
    61  func (a *anyCastAccess) Get(ctx context.Context, q gotenresource.GetQuery, opts ...gotenresource.GetOption) (gotenresource.Resource, error) {
    62  	if asDocumentQuery, ok := q.(*GetQuery); ok {
    63  		return a.GetDocument(ctx, asDocumentQuery, opts...)
    64  	}
    65  	return nil, status.Errorf(codes.Internal,
    66  		"Unrecognized descriptor, expected Document, got: %s",
    67  		q.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
    68  }
    69  
    70  func (a *anyCastAccess) Query(ctx context.Context, q gotenresource.ListQuery, opts ...gotenresource.QueryOption) (gotenresource.QueryResultSnapshot, error) {
    71  	if asDocumentQuery, ok := q.(*ListQuery); ok {
    72  		return a.QueryDocuments(ctx, asDocumentQuery, opts...)
    73  	}
    74  	return nil, status.Errorf(codes.Internal,
    75  		"Unrecognized descriptor, expected Document, got: %s",
    76  		q.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
    77  }
    78  
    79  func (a *anyCastAccess) Search(ctx context.Context, q gotenresource.SearchQuery, opts ...gotenresource.QueryOption) (gotenresource.QueryResultSnapshot, error) {
    80  	if asDocumentQuery, ok := q.(*SearchQuery); ok {
    81  		return a.SearchDocuments(ctx, asDocumentQuery, opts...)
    82  	}
    83  	return nil, status.Errorf(codes.Internal,
    84  		"Unrecognized descriptor, expected Document, got: %s",
    85  		q.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
    86  }
    87  
    88  func (a *anyCastAccess) Watch(ctx context.Context, q gotenresource.GetQuery, cb func(ch gotenresource.ResourceChange) error) error {
    89  	if asDocumentQuery, ok := q.(*GetQuery); ok {
    90  		return a.WatchDocument(ctx, asDocumentQuery, func(change *DocumentChange) error {
    91  			return cb(change)
    92  		})
    93  	}
    94  	return status.Errorf(codes.Internal,
    95  		"Unrecognized descriptor, expected Document, got: %s",
    96  		q.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
    97  }
    98  
    99  func (a *anyCastAccess) WatchQuery(ctx context.Context, q gotenresource.WatchQuery, cb func(ch gotenresource.QueryResultChange) error) error {
   100  	if asDocumentQuery, ok := q.(*WatchQuery); ok {
   101  		return a.WatchDocuments(ctx, asDocumentQuery, func(change *QueryResultChange) error {
   102  			return cb(change)
   103  		})
   104  	}
   105  	return status.Errorf(codes.Internal,
   106  		"Unrecognized descriptor, expected Document, got: %s",
   107  		q.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
   108  }
   109  
   110  func (a *anyCastAccess) Save(ctx context.Context, res gotenresource.Resource, opts ...gotenresource.SaveOption) error {
   111  	if asDocumentRes, ok := res.(*Document); ok {
   112  		return a.SaveDocument(ctx, asDocumentRes, opts...)
   113  	}
   114  	return status.Errorf(codes.Internal,
   115  		"Unrecognized descriptor, expected Document, got: %s",
   116  		res.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
   117  }
   118  
   119  func (a *anyCastAccess) Delete(ctx context.Context, ref gotenresource.Reference, opts ...gotenresource.DeleteOption) error {
   120  	if asDocumentRef, ok := ref.(*Reference); ok {
   121  		return a.DeleteDocument(ctx, asDocumentRef, opts...)
   122  	}
   123  	return status.Errorf(codes.Internal,
   124  		"Unrecognized descriptor, expected Document, got: %s",
   125  		ref.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
   126  }
   127  
   128  func (a *anyCastAccess) BatchGet(ctx context.Context, toGet []gotenresource.Reference, opts ...gotenresource.BatchGetOption) error {
   129  	documentRefs := make([]*Reference, 0, len(toGet))
   130  	for _, ref := range toGet {
   131  		if asDocumentRef, ok := ref.(*Reference); !ok {
   132  			return status.Errorf(codes.Internal,
   133  				"Unrecognized descriptor, expected Document, got: %s",
   134  				ref.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
   135  		} else {
   136  			documentRefs = append(documentRefs, asDocumentRef)
   137  		}
   138  	}
   139  	return a.BatchGetDocuments(ctx, documentRefs, opts...)
   140  }
   141  
   142  func (a *anyCastAccess) GetResourceDescriptors() []gotenresource.Descriptor {
   143  	return []gotenresource.Descriptor{
   144  		GetDescriptor(),
   145  	}
   146  }