Skip to content

Commit

Permalink
fix: add tx-document-get-result for use insid transactions
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Adossi <vadossi@cosmonic.com>
  • Loading branch information
vados-cosmonic committed Jul 1, 2024
1 parent 58d6b4d commit 757e346
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 16 deletions.
38 changes: 31 additions & 7 deletions wit/couchbase/transactions.wit
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ package wasmcloud:couchbase@0.1.0-draft;
interface transactions {
use types.{
document-id, request-span, document, subdocument-path, document-error, retry-strategy, mutation-metadata,
query-scan-consistency, query-profile-mode, collection
query-scan-consistency, query-profile-mode, collection, time
};
use document.{document-get-result};
use sqlpp.{sqlpp-value, sqlpp-query-status, sqlpp-query-metrics, sqlpp-query-warning};

/// A token representing a transaction (pseudo resource)
Expand Down Expand Up @@ -42,31 +41,56 @@ interface transactions {
unexpected(string),
}

/// Result of a successfully executed document get
record tx-document-get-result {
/// Document that was retrieved
document: document,

/// CAS revision of the document
cas: u64,

/// When the document should expire (nanoseconds)
///
/// Deprecated: use expires-at instead
expires-in-ns: option<u64>,

/// Time when the document expires
///
/// This field may not be present if `document-get-options.with-expiry` is not set
expires-at: option<time>,

/// ID for metadata related to the operation
///
/// This ID is provided by and used by the implementer to manage in-tx metadata,
/// and should not be manipulated by callers but rather passed verbatim.
tx-metadata-id: string,
}

/// Retrieve a document, inside a transaction
tx-document-get: func(
tx: tx-token,
collection: collection,
id: document-id
) -> result<document-get-result, tx-error>;
) -> result<tx-document-get-result, tx-error>;

/// Insert a document, inside a transaction
tx-document-insert: func(
tx: tx-token,
id: document-id,
document: document,
) -> result<document-get-result, tx-error>;
) -> result<tx-document-get-result, tx-error>;

/// Replace a document, inside a transaction
tx-document-replace: func(
tx: tx-token,
old: document-get-result,
old: tx-document-get-result,
new: document,
) -> result<document-get-result, tx-error>;
) -> result<tx-document-get-result, tx-error>;

/// Remove a document, inside a transaction
tx-document-remove: func(
tx: tx-token,
doc: document,
doc: tx-document-get-result,
) -> result<_, tx-error>;

/// Options to perform a query inside a transaction
Expand Down
4 changes: 2 additions & 2 deletions wit/deps.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[couchbase]
path = "couchbase"
sha256 = "3d40df73562805e07f6a2aa5f618fa7fa022717cab4aadd065bd2749275b243a"
sha512 = "2458459dd253299a3aa32594ae6bbd09aac5f740cdf4b6bef6b49bd0f99c3d42f2e5bc92d8b91ae53fe6bfd42403a87c3e683fb6aef51a840cfdb63cff74badf"
sha256 = "1c4502722fe222e4c4ca9fe94afde60e10e90808b615a2d11c6380c28bda4a1f"
sha512 = "d530a661e4727a36de87dd354cc82e9f32b3dc2ca985c946afe618930a9b2794e9ed344c0142592a16ad4a0e10d7916b2c5741d935ff49deef5f4cf8bf3735c9"

[keyvalue]
path = "keyvalue"
Expand Down
38 changes: 31 additions & 7 deletions wit/deps/couchbase/transactions.wit
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ package wasmcloud:couchbase@0.1.0-draft;
interface transactions {
use types.{
document-id, request-span, document, subdocument-path, document-error, retry-strategy, mutation-metadata,
query-scan-consistency, query-profile-mode, collection
query-scan-consistency, query-profile-mode, collection, time
};
use document.{document-get-result};
use sqlpp.{sqlpp-value, sqlpp-query-status, sqlpp-query-metrics, sqlpp-query-warning};

/// A token representing a transaction (pseudo resource)
Expand Down Expand Up @@ -42,31 +41,56 @@ interface transactions {
unexpected(string),
}

/// Result of a successfully executed document get
record tx-document-get-result {
/// Document that was retrieved
document: document,

/// CAS revision of the document
cas: u64,

/// When the document should expire (nanoseconds)
///
/// Deprecated: use expires-at instead
expires-in-ns: option<u64>,

/// Time when the document expires
///
/// This field may not be present if `document-get-options.with-expiry` is not set
expires-at: option<time>,

/// ID for metadata related to the operation
///
/// This ID is provided by and used by the implementer to manage in-tx metadata,
/// and should not be manipulated by callers but rather passed verbatim.
tx-metadata-id: string,
}

/// Retrieve a document, inside a transaction
tx-document-get: func(
tx: tx-token,
collection: collection,
id: document-id
) -> result<document-get-result, tx-error>;
) -> result<tx-document-get-result, tx-error>;

/// Insert a document, inside a transaction
tx-document-insert: func(
tx: tx-token,
id: document-id,
document: document,
) -> result<document-get-result, tx-error>;
) -> result<tx-document-get-result, tx-error>;

/// Replace a document, inside a transaction
tx-document-replace: func(
tx: tx-token,
old: document-get-result,
old: tx-document-get-result,
new: document,
) -> result<document-get-result, tx-error>;
) -> result<tx-document-get-result, tx-error>;

/// Remove a document, inside a transaction
tx-document-remove: func(
tx: tx-token,
doc: document,
doc: tx-document-get-result,
) -> result<_, tx-error>;

/// Options to perform a query inside a transaction
Expand Down

0 comments on commit 757e346

Please sign in to comment.