storage.proto 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. syntax = "proto3";
  2. package smartbotic.proto;
  3. import "common.proto";
  4. option cc_enable_arenas = true;
  5. // Document with metadata
  6. message Document {
  7. string id = 1;
  8. string collection = 2;
  9. string data = 3; // JSON string
  10. int64 version = 4;
  11. int64 created_at = 5;
  12. int64 updated_at = 6;
  13. int64 expires_at = 7; // 0 = no expiry
  14. }
  15. // Query filter operation
  16. enum FilterOp {
  17. FILTER_OP_UNSPECIFIED = 0;
  18. FILTER_OP_EQ = 1; // Equal
  19. FILTER_OP_NE = 2; // Not equal
  20. FILTER_OP_GT = 3; // Greater than
  21. FILTER_OP_GTE = 4; // Greater than or equal
  22. FILTER_OP_LT = 5; // Less than
  23. FILTER_OP_LTE = 6; // Less than or equal
  24. FILTER_OP_IN = 7; // In array
  25. FILTER_OP_NIN = 8; // Not in array
  26. FILTER_OP_CONTAINS = 9; // Contains substring
  27. FILTER_OP_REGEX = 10; // Regular expression match
  28. FILTER_OP_EXISTS = 11; // Field exists
  29. }
  30. // Single filter condition
  31. message Filter {
  32. string field = 1;
  33. FilterOp op = 2;
  34. string value = 3; // JSON encoded value
  35. }
  36. // Sort direction
  37. enum SortDirection {
  38. SORT_DIRECTION_UNSPECIFIED = 0;
  39. SORT_DIRECTION_ASC = 1;
  40. SORT_DIRECTION_DESC = 2;
  41. }
  42. // Sort specification
  43. message Sort {
  44. string field = 1;
  45. SortDirection direction = 2;
  46. }
  47. // Query request
  48. message QueryRequest {
  49. string collection = 1;
  50. repeated Filter filters = 2;
  51. repeated Sort sorts = 3;
  52. PaginationRequest pagination = 4;
  53. repeated string fields = 5; // Projection - empty means all fields
  54. }
  55. // Query response
  56. message QueryResponse {
  57. repeated Document documents = 1;
  58. PaginationResponse pagination = 2;
  59. }
  60. // Get document request
  61. message GetRequest {
  62. string collection = 1;
  63. string id = 2;
  64. }
  65. // Insert request
  66. message InsertRequest {
  67. string collection = 1;
  68. string id = 2; // Optional - generated if empty
  69. string data = 3; // JSON string
  70. int64 ttl_ms = 4; // Time to live in milliseconds (0 = no expiry)
  71. }
  72. // Update request
  73. message UpdateRequest {
  74. string collection = 1;
  75. string id = 2;
  76. string data = 3; // JSON string - full document or partial update
  77. int64 expected_version = 4; // Optimistic locking (0 = no check)
  78. bool partial = 5; // If true, merge with existing document
  79. }
  80. // Delete request
  81. message DeleteRequest {
  82. string collection = 1;
  83. string id = 2;
  84. int64 expected_version = 3; // Optimistic locking (0 = no check)
  85. }
  86. // Batch operations
  87. message BatchInsertRequest {
  88. string collection = 1;
  89. repeated InsertRequest documents = 2;
  90. }
  91. message BatchDeleteRequest {
  92. string collection = 1;
  93. repeated string ids = 2;
  94. }
  95. // Versioning configuration
  96. message VersioningConfig {
  97. bool enabled = 1;
  98. int32 max_versions = 2; // 0 = unlimited
  99. int64 version_ttl_ms = 3; // 0 = no expiry
  100. bool keep_on_delete = 4; // Archive deleted documents
  101. }
  102. // Collection management
  103. message CreateCollectionRequest {
  104. string name = 1;
  105. string schema = 2; // JSON Schema for validation (optional)
  106. int64 default_ttl_ms = 3; // Default TTL for documents
  107. VersioningConfig versioning = 4; // Versioning configuration
  108. }
  109. message DropCollectionRequest {
  110. string name = 1;
  111. }
  112. message ListCollectionsRequest {}
  113. message ListCollectionsResponse {
  114. repeated string collections = 1;
  115. }
  116. // Mutation response
  117. message MutationResponse {
  118. string id = 1;
  119. int64 version = 2;
  120. bool success = 3;
  121. Error error = 4;
  122. }
  123. message BatchMutationResponse {
  124. repeated MutationResponse results = 1;
  125. int32 success_count = 2;
  126. int32 failure_count = 3;
  127. }
  128. // Document version for version history
  129. message DocumentVersion {
  130. string id = 1; // "{documentId}__v{version}"
  131. string document_id = 2;
  132. int64 version = 3;
  133. string data = 4; // JSON string
  134. int64 created_at = 5;
  135. int64 expires_at = 6;
  136. }
  137. // Get specific document version
  138. message GetVersionRequest {
  139. string collection = 1;
  140. string id = 2;
  141. int64 version = 3;
  142. }
  143. // List versions for a document
  144. message ListVersionsRequest {
  145. string collection = 1;
  146. string id = 2;
  147. int32 limit = 3;
  148. int32 offset = 4;
  149. }
  150. message ListVersionsResponse {
  151. repeated DocumentVersion versions = 1;
  152. int64 total_count = 2;
  153. bool has_more = 3;
  154. }
  155. // Storage service definition
  156. service StorageService {
  157. // Document operations
  158. rpc Get(GetRequest) returns (Document);
  159. rpc Query(QueryRequest) returns (QueryResponse);
  160. rpc Insert(InsertRequest) returns (MutationResponse);
  161. rpc Update(UpdateRequest) returns (MutationResponse);
  162. rpc Delete(DeleteRequest) returns (MutationResponse);
  163. // Batch operations
  164. rpc BatchInsert(BatchInsertRequest) returns (BatchMutationResponse);
  165. rpc BatchDelete(BatchDeleteRequest) returns (BatchMutationResponse);
  166. // Collection management
  167. rpc CreateCollection(CreateCollectionRequest) returns (Empty);
  168. rpc DropCollection(DropCollectionRequest) returns (Empty);
  169. rpc ListCollections(ListCollectionsRequest) returns (ListCollectionsResponse);
  170. // Version operations
  171. rpc GetVersion(GetVersionRequest) returns (Document);
  172. rpc ListVersions(ListVersionsRequest) returns (ListVersionsResponse);
  173. }