Skip to content

Commit 53e6b10

Browse files
authored
Merge pull request #109 from josephschorr/transaction-metadata
Add API support for transaction metadata
2 parents 699bace + 1c22b5c commit 53e6b10

4 files changed

Lines changed: 52 additions & 2 deletions

File tree

authzed/api/v1/error_reason.proto

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,4 +399,18 @@ enum ErrorReason {
399399
// "metadata": { "disallowed_field": "subject_id" }
400400
// }
401401
ERROR_REASON_WILDCARD_NOT_ALLOWED = 28;
402+
403+
// The request failed because the transaction metadata was too large.
404+
//
405+
// Example of an ErrorInfo:
406+
//
407+
// {
408+
// "reason": "ERROR_REASON_TRANSACTION_METADATA_TOO_LARGE",
409+
// "domain": "authzed.com",
410+
// "metadata": {
411+
// "metadata_byte_size": "1024",
412+
// "maximum_allowed_metadata_byte_size": "512",
413+
// }
414+
// }
415+
ERROR_REASON_TRANSACTION_METADATA_TOO_LARGE = 29;
402416
}

authzed/api/v1/experimental_service.proto

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,18 @@ message BulkCheckPermissionResponseItem {
222222
// BulkImportRelationshipsRequest represents one batch of the streaming
223223
// BulkImportRelationships API. The maximum size is only limited by the backing
224224
// datastore, and optimal size should be determined by the calling client
225-
// experimentally.
225+
// experimentally. Any relationships within the same request are guaranteed to
226+
// be written in a single transaction. If any of the relationships already
227+
// exist, the transaction will fail and no relationships will be written.
226228
message BulkImportRelationshipsRequest {
227229
repeated Relationship relationships = 1
228230
[ (validate.rules).repeated .items.message.required = true ];
231+
232+
233+
// optional_transaction_metadata is an optional field that can be used to store metadata about the transaction.
234+
// If specified, this metadata will be supplied in the WatchResponse for the creations associated with
235+
// this transaction.
236+
google.protobuf.Struct optional_transaction_metadata = 2 [ (validate.rules).message.required = false ];
229237
}
230238

231239
// BulkImportRelationshipsResponse is returned on successful completion of the

authzed/api/v1/permission_service.proto

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,20 @@ message Precondition {
282282
// WriteRelationshipsRequest contains a list of Relationship mutations that
283283
// should be applied to the service. If the optional_preconditions parameter
284284
// is included, all of the specified preconditions must also be satisfied before
285-
// the write will be committed.
285+
// the write will be committed. All updates will be applied transactionally,
286+
// and if any preconditions fail, the entire transaction will be reverted.
286287
message WriteRelationshipsRequest {
287288
repeated RelationshipUpdate updates = 1
288289
[ (validate.rules).repeated .items.message.required = true ];
289290

290291
repeated Precondition optional_preconditions = 2
291292
[ (validate.rules).repeated .items.message.required =
292293
true ]; // To be bounded by configuration
294+
295+
// optional_transaction_metadata is an optional field that can be used to store metadata about the transaction.
296+
// If specified, this metadata will be supplied in the WatchResponse for the updates associated with this
297+
// transaction.
298+
google.protobuf.Struct optional_transaction_metadata = 3 [ (validate.rules).message.required = false ];
293299
}
294300

295301
message WriteRelationshipsResponse { ZedToken written_at = 1; }
@@ -317,6 +323,11 @@ message DeleteRelationshipsRequest {
317323
// optional_allow_partial_deletions, if true and a limit is specified, will delete matching found
318324
// relationships up to the count specified in optional_limit, and no more.
319325
bool optional_allow_partial_deletions = 4;
326+
327+
// optional_transaction_metadata is an optional field that can be used to store metadata about the transaction.
328+
// If specified, this metadata will be supplied in the WatchResponse for the deletions associated with
329+
// this transaction.
330+
google.protobuf.Struct optional_transaction_metadata = 5 [ (validate.rules).message.required = false ];
320331
}
321332

322333
message DeleteRelationshipsResponse {
@@ -662,6 +673,11 @@ message ResolvedSubject {
662673
message ImportBulkRelationshipsRequest {
663674
repeated Relationship relationships = 1
664675
[ (validate.rules).repeated .items.message.required = true ];
676+
677+
// optional_transaction_metadata is an optional field that can be used to store metadata about the transaction.
678+
// If specified, this metadata will be supplied in the WatchResponse for the creations associated with
679+
// this transaction.
680+
google.protobuf.Struct optional_transaction_metadata = 2 [ (validate.rules).message.required = false ];
665681
}
666682

667683
// ImportBulkRelationshipsResponse is returned on successful completion of the

authzed/api/v1/watch_service.proto

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ option java_package = "com.authzed.api.v1";
66
option java_multiple_files = true;
77

88
import "google/api/annotations.proto";
9+
import "google/protobuf/struct.proto";
910
import "validate/validate.proto";
1011

1112
import "authzed/api/v1/core.proto";
@@ -58,6 +59,17 @@ message WatchRequest {
5859
// encoded in the watch response. The client can use the snapshot to resume
5960
// watching where the previous watch response left off.
6061
message WatchResponse {
62+
// updates are the RelationshipUpdate events that have occurred since the
63+
// last watch response.
6164
repeated RelationshipUpdate updates = 1;
65+
66+
// changes_through is the ZedToken that represents the point in time
67+
// that the watch response is current through. This token can be used
68+
// in a subsequent WatchRequest to resume watching from this point.
6269
ZedToken changes_through = 2;
70+
71+
// optional_transaction_metadata is an optional field that returns the transaction metadata
72+
// given to SpiceDB during the transaction that produced the changes in this response.
73+
// This field may not exist if no transaction metadata was provided.
74+
google.protobuf.Struct optional_transaction_metadata = 3;
6375
}

0 commit comments

Comments
 (0)