amduat/include/amduat/tgk/store.h

191 lines
6.5 KiB
C

#ifndef AMDUAT_TGK_STORE_H
#define AMDUAT_TGK_STORE_H
#include "amduat/asl/core.h"
#include "amduat/asl/store.h"
#include "amduat/tgk/core.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
GS_ERR_NOT_EDGE = 1,
GS_ERR_ARTIFACT_ERROR = 2,
GS_ERR_UNSUPPORTED = 3,
GS_ERR_INTEGRITY = 4
} amduat_tgk_graph_error_t;
typedef uint64_t amduat_tgk_snapshot_id_t;
typedef struct {
amduat_tgk_edge_type_id_t *types;
size_t types_len;
} amduat_tgk_edge_type_filter_t;
typedef enum {
AMDUAT_TGK_GRAPH_DIR_OUT = 1,
AMDUAT_TGK_GRAPH_DIR_IN = 2,
AMDUAT_TGK_GRAPH_DIR_BOTH = 3
} amduat_tgk_graph_direction_t;
typedef struct {
amduat_reference_t edge_ref;
amduat_tgk_edge_body_t body;
} amduat_tgk_graph_edge_view_t;
typedef struct {
amduat_tgk_graph_edge_view_t *edges;
size_t len;
} amduat_tgk_graph_edge_view_list_t;
typedef struct {
amduat_reference_t *nodes;
size_t len;
} amduat_tgk_node_list_t;
typedef struct {
amduat_tgk_graph_edge_view_list_t edges;
amduat_octets_t next_page_token;
bool has_next_page;
} amduat_tgk_graph_scan_result_t;
typedef struct {
amduat_asl_encoding_profile_id_t encoding_profile;
amduat_hash_id_t hash_id;
} amduat_tgk_identity_domain_t;
typedef struct {
amduat_tgk_identity_domain_t *domains;
size_t domains_len;
} amduat_tgk_id_space_config_t;
typedef struct {
amduat_octets_t description;
} amduat_tgk_artifact_scope_t;
typedef struct {
uint32_t *edge_tags;
size_t edge_tags_len;
amduat_tgk_edge_type_id_t *edge_types;
size_t edge_types_len;
amduat_asl_encoding_profile_id_t *encodings;
size_t encodings_len;
} amduat_tgk_profile_set_t;
typedef struct {
amduat_tgk_id_space_config_t id_space;
amduat_tgk_artifact_scope_t artifact_scope;
amduat_tgk_profile_set_t tgk_profiles;
} amduat_tgk_store_config_t;
typedef struct {
bool (*get_config)(void *ctx, amduat_tgk_store_config_t *out_config);
bool (*snapshot_id)(void *ctx, amduat_tgk_snapshot_id_t *out_id);
bool (*ingest_artifact)(void *ctx,
amduat_reference_t ref,
amduat_artifact_t artifact);
bool (*remove_artifact)(void *ctx, amduat_reference_t ref);
amduat_tgk_graph_error_t (*resolve_edge)(void *ctx,
amduat_reference_t ref,
amduat_tgk_edge_body_t *out_body);
bool (*edges_from)(void *ctx,
amduat_reference_t node,
amduat_tgk_edge_type_filter_t type_filter,
amduat_tgk_graph_edge_view_list_t *out_edges);
bool (*edges_to)(void *ctx,
amduat_reference_t node,
amduat_tgk_edge_type_filter_t type_filter,
amduat_tgk_graph_edge_view_list_t *out_edges);
bool (*edges_incident)(void *ctx,
amduat_reference_t node,
amduat_tgk_edge_type_filter_t type_filter,
amduat_tgk_graph_edge_view_list_t *out_edges);
bool (*scan_edges)(void *ctx,
amduat_tgk_edge_type_filter_t type_filter,
amduat_octets_t page_token,
bool has_page_token,
amduat_tgk_graph_scan_result_t *out_scan);
bool (*neighbors)(void *ctx,
amduat_reference_t node,
amduat_tgk_edge_type_filter_t type_filter,
amduat_tgk_graph_direction_t direction,
amduat_tgk_node_list_t *out_nodes);
} amduat_tgk_store_ops_t;
typedef struct {
amduat_tgk_store_config_t config;
amduat_tgk_store_ops_t ops;
void *ctx;
} amduat_tgk_store_t;
void amduat_tgk_store_init(amduat_tgk_store_t *store,
amduat_tgk_store_config_t config,
amduat_tgk_store_ops_t ops,
void *ctx);
bool amduat_tgk_store_get_config(amduat_tgk_store_t *store,
amduat_tgk_store_config_t *out_config);
bool amduat_tgk_store_snapshot_id(amduat_tgk_store_t *store,
amduat_tgk_snapshot_id_t *out_id);
bool amduat_tgk_store_ingest_artifact(amduat_tgk_store_t *store,
amduat_reference_t ref,
amduat_artifact_t artifact);
bool amduat_tgk_store_remove_artifact(amduat_tgk_store_t *store,
amduat_reference_t ref);
amduat_tgk_graph_error_t amduat_tgk_store_resolve_edge(
amduat_tgk_store_t *store,
amduat_reference_t ref,
amduat_tgk_edge_body_t *out_body);
bool amduat_tgk_store_edges_from(amduat_tgk_store_t *store,
amduat_reference_t node,
amduat_tgk_edge_type_filter_t type_filter,
amduat_tgk_graph_edge_view_list_t *out_edges);
bool amduat_tgk_store_edges_to(amduat_tgk_store_t *store,
amduat_reference_t node,
amduat_tgk_edge_type_filter_t type_filter,
amduat_tgk_graph_edge_view_list_t *out_edges);
bool amduat_tgk_store_edges_incident(
amduat_tgk_store_t *store,
amduat_reference_t node,
amduat_tgk_edge_type_filter_t type_filter,
amduat_tgk_graph_edge_view_list_t *out_edges);
bool amduat_tgk_store_scan_edges(amduat_tgk_store_t *store,
amduat_tgk_edge_type_filter_t type_filter,
amduat_octets_t page_token,
bool has_page_token,
amduat_tgk_graph_scan_result_t *out_scan);
/* Cursor format note: the in-memory TGK store adapter encodes page tokens as
* ASL1 ReferenceBytes (hash_id + digest) for the last edge_ref returned. */
bool amduat_tgk_store_neighbors(amduat_tgk_store_t *store,
amduat_reference_t node,
amduat_tgk_edge_type_filter_t type_filter,
amduat_tgk_graph_direction_t direction,
amduat_tgk_node_list_t *out_nodes);
/* Query results are owned by the caller; free with helpers below. */
void amduat_tgk_graph_edge_view_list_free(
amduat_tgk_graph_edge_view_list_t *list);
void amduat_tgk_node_list_free(amduat_tgk_node_list_t *list);
void amduat_tgk_graph_scan_result_free(amduat_tgk_graph_scan_result_t *scan);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* AMDUAT_TGK_STORE_H */