Completely rework return values from storage operations

This commit is contained in:
Tim Wojtulewicz 2025-02-24 14:37:11 -07:00
parent 8ddda016ff
commit 9ed3e33f97
50 changed files with 859 additions and 586 deletions

View file

@ -22,17 +22,19 @@ export {
## well as for type conversions for return values from
## :zeek:see:`Storage::Async::get`.
##
## Returns: A handle to the new backend connection, or ``F`` if the connection
## failed.
## Returns: A record containing the status of the operation, and either an error
## string on failure or a value on success. The value returned here will
## be an ``opaque of BackendHandle``.
global open_backend: function(btype: Storage::Backend, options: Storage::BackendOptions, key_type: any,
val_type: any): opaque of Storage::BackendHandle;
val_type: any): Storage::OperationResult;
## Closes an existing backend connection asynchronously.
##
## backend: A handle to a backend connection.
##
## Returns: A boolean indicating success or failure of the operation.
global close_backend: function(backend: opaque of Storage::BackendHandle): bool;
## Returns: A record containing the status of the operation and an optional error
## string for failures.
global close_backend: function(backend: opaque of Storage::BackendHandle): Storage::OperationResult;
## Inserts a new entry into a backend asynchronously.
##
@ -41,11 +43,9 @@ export {
## args: A :zeek:see:`Storage::PutArgs` record containing the arguments for the
## operation.
##
## Returns: A boolean indicating success or failure of the operation. Type
## comparison failures against the types passed to
## :zeek:see:`Storage::open_backend` for the backend will cause ``F`` to
## be returned.
global put: function(backend: opaque of Storage::BackendHandle, args: Storage::PutArgs): bool;
## Returns: A record containing the status of the operation and an optional error
## string for failures.
global put: function(backend: opaque of Storage::BackendHandle, args: Storage::PutArgs): Storage::OperationResult;
## Gets an entry from the backend asynchronously.
##
@ -53,13 +53,11 @@ export {
##
## key: The key to look up.
##
## Returns: A boolean indicating success or failure of the operation. Type
## comparison failures against the types passed to
## :zeek:see:`Storage::open_backend` for the backend will cause ``F`` to
## be returned. The caller should check the validity of the value before
## attempting to use it. If the value is unset, an error string may be
## available to describe the failure.
global get: function(backend: opaque of Storage::BackendHandle, key: any): val_result;
## Returns: A record containing the status of the operation, an optional error
## string for failures, and an optional value for success. The value
## returned here will be of the type passed into
## :zeek:see:`Storage::open_backend`.
global get: function(backend: opaque of Storage::BackendHandle, key: any): Storage::OperationResult;
## Erases an entry from the backend asynchronously.
##
@ -67,35 +65,33 @@ export {
##
## key: The key to erase.
##
## Returns: A boolean indicating success or failure of the operation. Type
## comparison failures against the types passed to
## :zeek:see:`Storage::open_backend` for the backend will cause ``F`` to
## be returned.
global erase: function(backend: opaque of Storage::BackendHandle, key: any): bool;
## Returns: A record containing the status of the operation and an optional error
## string for failures.
global erase: function(backend: opaque of Storage::BackendHandle, key: any): Storage::OperationResult;
}
function open_backend(btype: Storage::Backend, options: Storage::BackendOptions, key_type: any,
val_type: any): opaque of Storage::BackendHandle
val_type: any): Storage::OperationResult
{
return Storage::Async::__open_backend(btype, options, key_type, val_type);
}
function close_backend(backend: opaque of Storage::BackendHandle): bool
function close_backend(backend: opaque of Storage::BackendHandle): Storage::OperationResult
{
return Storage::Async::__close_backend(backend);
}
function put(backend: opaque of Storage::BackendHandle, args: Storage::PutArgs): bool
function put(backend: opaque of Storage::BackendHandle, args: Storage::PutArgs): Storage::OperationResult
{
return Storage::Async::__put(backend, args$key, args$value, args$overwrite, args$expire_time);
}
function get(backend: opaque of Storage::BackendHandle, key: any): val_result
function get(backend: opaque of Storage::BackendHandle, key: any): Storage::OperationResult
{
return Storage::Async::__get(backend, key);
}
function erase(backend: opaque of Storage::BackendHandle, key: any): bool
function erase(backend: opaque of Storage::BackendHandle, key: any): Storage::OperationResult
{
return Storage::Async::__erase(backend, key);
}

View file

@ -5,9 +5,9 @@
module Storage;
export {
## Base record for backend options. Backend plugins can redef this record to add
## relevant fields to it.
type BackendOptions: record {};
## Base record for backend options. Backend plugins can redef this record to add
## relevant fields to it.
type BackendOptions: record { };
## Record for passing arguments to :zeek:see:`Storage::Async::put` and
## :zeek:see:`Storage::Sync::put`.

View file

@ -20,17 +20,19 @@ export {
## as for type conversions for return values from
## :zeek:see:`Storage::Sync::get`.
##
## Returns: A handle to the new backend connection, or ``F`` if the connection
## failed.
## Returns: A record containing the status of the operation, and either an error
## string on failure or a value on success. The value returned here will
## be an ``opaque of BackendHandle``.
global open_backend: function(btype: Storage::Backend, options: Storage::BackendOptions, key_type: any,
val_type: any): opaque of Storage::BackendHandle;
val_type: any): Storage::OperationResult;
## Closes an existing backend connection.
##
## backend: A handle to a backend connection.
##
## Returns: A boolean indicating success or failure of the operation.
global close_backend: function(backend: opaque of Storage::BackendHandle): bool;
## Returns: A record containing the status of the operation and an optional error
## string for failures.
global close_backend: function(backend: opaque of Storage::BackendHandle): Storage::OperationResult;
## Inserts a new entry into a backend.
##
@ -39,11 +41,9 @@ export {
## args: A :zeek:see:`Storage::PutArgs` record containing the arguments for the
## operation.
##
## Returns: A boolean indicating success or failure of the operation. Type
## comparison failures against the types passed to
## :zeek:see:`Storage::open_backend` for the backend will cause ``F`` to
## be returned.
global put: function(backend: opaque of Storage::BackendHandle, args: Storage::PutArgs): bool;
## Returns: A record containing the status of the operation and an optional error
## string for failures.
global put: function(backend: opaque of Storage::BackendHandle, args: Storage::PutArgs): Storage::OperationResult;
## Gets an entry from the backend.
##
@ -51,13 +51,11 @@ export {
##
## key: The key to look up.
##
## Returns: A boolean indicating success or failure of the operation. Type
## comparison failures against the types passed to
## :zeek:see:`Storage::open_backend` for the backend will cause ``F`` to
## be returned. The caller should check the validity of the value before
## attempting to use it. If the value is unset, an error string may be
## available to describe the failure.
global get: function(backend: opaque of Storage::BackendHandle, key: any): val_result;
## Returns: A record containing the status of the operation, an optional error
## string for failures, and an optional value for success. The value
## returned here will be of the type passed into
## :zeek:see:`Storage::open_backend`.
global get: function(backend: opaque of Storage::BackendHandle, key: any): Storage::OperationResult;
## Erases an entry from the backend.
##
@ -65,35 +63,33 @@ export {
##
## key: The key to erase.
##
## Returns: A boolean indicating success or failure of the operation. Type
## comparison failures against the types passed to
## :zeek:see:`Storage::open_backend` for the backend will cause ``F`` to
## be returned.
global erase: function(backend: opaque of Storage::BackendHandle, key: any): bool;
## Returns: A record containing the status of the operation and an optional error
## string for failures.
global erase: function(backend: opaque of Storage::BackendHandle, key: any): Storage::OperationResult;
}
function open_backend(btype: Storage::Backend, options: Storage::BackendOptions, key_type: any,
val_type: any): opaque of Storage::BackendHandle
val_type: any): Storage::OperationResult
{
return Storage::Sync::__open_backend(btype, options, key_type, val_type);
}
function close_backend(backend: opaque of Storage::BackendHandle): bool
function close_backend(backend: opaque of Storage::BackendHandle): Storage::OperationResult
{
return Storage::Sync::__close_backend(backend);
}
function put(backend: opaque of Storage::BackendHandle, args: Storage::PutArgs): bool
function put(backend: opaque of Storage::BackendHandle, args: Storage::PutArgs): Storage::OperationResult
{
return Storage::Sync::__put(backend, args$key, args$value, args$overwrite, args$expire_time);
}
function get(backend: opaque of Storage::BackendHandle, key: any): val_result
function get(backend: opaque of Storage::BackendHandle, key: any): Storage::OperationResult
{
return Storage::Sync::__get(backend, key);
}
function erase(backend: opaque of Storage::BackendHandle, key: any): bool
function erase(backend: opaque of Storage::BackendHandle, key: any): Storage::OperationResult
{
return Storage::Sync::__erase(backend, key);
}