Class ApiUtil

java.lang.Object
org.rapidcontext.app.model.ApiUtil

public class ApiUtil extends Object
A set of utility methods for API responses, etc.
Version:
1.0
  • Method Details

    • options

      public static Dict options(String defaultKey, Object value)
      Creates or extracts an options object from a value. If the value isn't a dictionary, a new one will be created with a default key set to the specified value.
      Parameters:
      defaultKey - the default key
      value - the value to convert
      Returns:
      an options dictionary
    • lookup

      public static Stream<Metadata> lookup(Storage storage, Path path, String perm, Dict opts)
      Search for object metadata in storage.
      Parameters:
      storage - the storage to search
      path - the base path to query
      perm - the access permission required
      opts - the query options
      Returns:
      a stream of metadata for matching objects
    • load

      public static Stream<Object> load(Storage storage, Path path, String perm, Dict opts)
      Load objects from storage and serializes the results.
      Parameters:
      storage - the storage to search
      path - the base path to query
      perm - the access permission required
      opts - the query options
      Returns:
      a stream of serialized matching objects
    • store

      public static boolean store(Storage storage, Path path, Object data)
      Writes a data object to the storage.
      Parameters:
      storage - the storage to modify
      path - the storage path
      data - the data object
      Returns:
      true if the data was successfully written, or false otherwise
    • update

      public static boolean update(Storage storage, Path src, Path dst, Dict patch)
      Updates and/or moves an existing data object in the storage. The object must be serializable to a dictionary, which may be merged with a dictionary of changes. Keys with a value will be overwritten, and keys with a null value will be removed. Omitted keys will be will be left unmodified in the source object.
      Parameters:
      storage - the storage to modify
      src - the source storage path
      dst - the destination storage path
      patch - the data object changes, or null
      Returns:
      true if the data was successfully written, or false otherwise
    • delete

      public static boolean delete(Storage storage, Path path)
      Deletes a storage object or path.
      Parameters:
      storage - the storage to modify
      path - the storage path
      Returns:
      true if the data was successfully removed, or false otherwise
    • serialize

      public static Object serialize(Metadata meta, Object obj, Dict opts, boolean limitedTypes)
      Returns a serialized representation of an object and its metadata.
      Parameters:
      meta - the object metadata
      obj - the object to serialize
      opts - the serialization options
      limitedTypes - limit allowed object value types
      Returns:
      the serialized representation of the object, or null if no suitable serialization existed
    • serialize

      public static Object serialize(Path path, Object obj, Dict opts, boolean limitedTypes)
      Returns a serialized representation of an object.
      Parameters:
      path - the storage path
      obj - the object to serialize
      opts - the serialization options
      limitedTypes - limit allowed object value types
      Returns:
      the serialized representation of the object, or null if no suitable serialization existed