Skip to content

Commit

Permalink
Merge pull request #154 from evomimic/3-introduce-local-holonspace
Browse files Browse the repository at this point in the history
WiP holon spaces
  • Loading branch information
evomimic authored Oct 8, 2024
2 parents 97c76aa + d6f9096 commit 5a8b416
Show file tree
Hide file tree
Showing 45 changed files with 734 additions and 246 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl SchemaNamesTrait for CoreBooleanValueTypeName {
impl CoreBooleanValueTypeName {
/// This function returns the variant definition for a given variant type
fn get_boolean_type_loader(&self) -> BooleanTypeLoader {
use CoreBooleanValueTypeName::*;
// use CoreBooleanValueTypeName::*;
match self {
CoreBooleanValueTypeName::MapBooleanType => BooleanTypeLoader {
type_name: self.derive_type_name(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use shared_types_holon::{MapBoolean, MapInteger, MapString};
use crate::core_schema_types::SchemaNamesTrait;
// use crate::core_schema_types::CoreSchemaTypeName::HolonType;
use crate::holon_type_loader::CoreHolonTypeName;
use crate::property_type_loader::CorePropertyTypeName::{Description, Name};
// use crate::property_type_loader::CorePropertyTypeName::{Description, Name};

#[derive(Debug)]
pub struct CollectionTypeSpec {
Expand Down
3 changes: 1 addition & 2 deletions crates/coordinator/core_schema/src/holon_type_loader.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use hdi::prelude::info;
use strum_macros::EnumIter;
use descriptors::descriptor_types::CoreSchemaRelationshipTypeName::TargetCollectionType;
// use descriptors::descriptor_types::CoreSchemaRelationshipTypeName::TargetCollectionType;
use descriptors::holon_descriptor::{define_holon_type, HolonTypeDefinition};
use descriptors::type_descriptor::TypeDescriptorDefinition;
use holons::context::HolonsContext;
Expand All @@ -9,7 +9,6 @@ use holons::holon_reference::HolonReference;
use holons::staged_reference::StagedReference;
use shared_types_holon::{MapBoolean, MapString};
use crate::core_schema_types::{SchemaNamesTrait};
use crate::holon_type_loader::CoreHolonTypeName::HolonType;
// use crate::holon_type_loader::CoreHolonTypeName::{DanceRequestType, DanceResponseType, HolonSpaceType, HolonType, PropertyType, RelationshipType, SchemaType};
use crate::property_type_loader::CorePropertyTypeName;
use crate::property_type_loader::CorePropertyTypeName::{Description, DescriptorName, Name, TypeName};
Expand Down
19 changes: 14 additions & 5 deletions crates/coordinator/core_schema/src/loader.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use hdi::prelude::debug;

use strum::IntoEnumIterator;
use hdk::prelude::info;
use holons::commit_manager::{CommitManager, CommitResponse};
Expand All @@ -12,7 +13,7 @@ use shared_types_holon::{MapString, PropertyName};

use descriptors::descriptor_types::{CoreSchemaName, Schema};
use holons::holon::Holon;
use holons::holon_api::get_all_holons;
// use holons::holon_api::get_all_holons;
use holons::json_adapter::as_json;
use crate::boolean_value_type_loader::CoreBooleanValueTypeName;
// use descriptors::holon_descriptor::{define_holon_type};
Expand All @@ -25,7 +26,7 @@ use crate::enum_type_loader::CoreEnumTypeName;
// use crate::string_value_type_loader::CoreStringValueTypeName;
// use crate::enum_type_loader::CoreEnumTypeName;
// use crate::holon_type_loader::CoreHolonTypeName;
use crate::holon_type_loader::CoreHolonTypeName::HolonType;
// use crate::holon_type_loader::CoreHolonTypeName::HolonType;
use crate::integer_value_type_loader::CoreIntegerValueTypeName;
use crate::meta_type_loader::CoreMetaTypeName;
use crate::property_type_loader::CorePropertyTypeName;
Expand Down Expand Up @@ -54,6 +55,11 @@ pub fn load_core_schema(context: &HolonsContext) -> Result<CommitResponse, Holon
info!("vvvvvvvv Entered: load_core_schema vvvvvvvvv");
// Begin by staging `schema`. It's HolonReference becomes the target of
// the COMPONENT_OF relationship for all schema components
let space_reference = context.get_local_holon_space()
.ok_or(HolonError::HolonNotFound(
"Local holon space not found".to_string(),
));


let schema = Schema::new(
CoreSchemaName::SchemaName.as_map_string(),
Expand All @@ -69,21 +75,24 @@ pub fn load_core_schema(context: &HolonsContext) -> Result<CommitResponse, Holon

context.add_reference_to_dance_state(staged_schema_ref.clone())?;


//context.local_holon_space.clone_from(source).borrow_mut().get_holon(commit_holon(staged_schema_ref.clone())?;

let initial_load_set = get_initial_load_set();

for type_name in initial_load_set {
info!("Attempting to load {:?}", type_name);
let _type_ref = type_name.lazy_get_core_type_definition(context, &staged_schema_ref)?;

}
// Let's add all of the CoreRelationshipTypes to the initial load set
// Let's add all the CoreRelationshipTypes to the initial load set

for variant in CoreRelationshipTypeName::iter() {
info!("Attempting to load {:?}", variant);
let _type_ref = variant.lazy_get_core_type_definition(context, &staged_schema_ref)?;
}

// Let's add all of the CorePropertyTypes to the initial load set
// Let's add all the CorePropertyTypes to the initial load set

for variant in CorePropertyTypeName::iter() {
info!("Attempting to load {:?}", variant);
Expand Down Expand Up @@ -163,7 +172,7 @@ fn get_initial_load_set() -> Vec<CoreSchemaTypeName> {

];

// Let's add all of the CoreSchemaValueTypes to the initial load set
// Let's add all the CoreSchemaValueTypes to the initial load set

for variant in CoreStringValueTypeName::iter() {
result.push(CoreSchemaTypeName::ValueType(CoreValueTypeName::StringType(variant)));
Expand Down
47 changes: 43 additions & 4 deletions crates/coordinator/core_schema/src/relationship_type_loader.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use hdi::prelude::info;
// use holons::smart_reference::SmartReference;
use inflector::cases::screamingsnakecase::to_screaming_snake_case;
use strum_macros::EnumIter;
use descriptors::descriptor_types::CoreSchemaRelationshipTypeName::CollectionFor;
// use descriptors::descriptor_types::CoreSchemaRelationshipTypeName::CollectionFor;
// use inflector::cases::snakecase::to_snake_case;
use descriptors::descriptor_types::DeletionSemantic;
use descriptors::holon_descriptor::{define_holon_type, HolonTypeDefinition};
Expand All @@ -16,13 +17,14 @@ use shared_types_holon::{MapBoolean, MapString};
use crate::collection_type_loader::CollectionTypeSpec;
use crate::core_schema_types::SchemaNamesTrait;
use crate::holon_type_loader::CoreHolonTypeName;
use crate::relationship_type_loader::CoreRelationshipTypeName::{Components, DescribedBy, HasSubtype, IsA, OwnedBy, Owns, Predecessor};
use crate::string_value_type_loader::CoreStringValueTypeName::RelationshipNameType;
// use crate::relationship_type_loader::CoreRelationshipTypeName::{Components, DescribedBy, HasSubtype, IsA, OwnedBy, Owns, Predecessor};
// use crate::string_value_type_loader::CoreStringValueTypeName::RelationshipNameType;

#[derive(Debug, Clone, Default, EnumIter)]
pub enum CoreRelationshipTypeName {
CoreSchema,
CoreSchemaFor,
CollectionFor,

Components,
ComponentOf,
// Dances,
Expand Down Expand Up @@ -105,6 +107,43 @@ impl CoreRelationshipTypeName {
let label = self.derive_label();

match self {
CoreSchemaFor => RelationshipTypeLoader {
descriptor_name,
description : MapString(
format!("Specifies the HolonSpace(s) for which this Schema is used to create instances of L0 types.")
),
label,
described_by: None,
owned_by: None,
relationship_type_name,
source_owns_relationship: MapBoolean(true),
deletion_semantic: DeletionSemantic::Allow,
load_links_immediate: MapBoolean(false),
target_collection_type: CollectionTypeSpec{
semantic: CollectionSemantic::SingleInstance,
holon_type: CoreHolonTypeName::HolonSpaceType,
},
has_inverse: Some(CoreSchema),
},
CoreSchema => RelationshipTypeLoader {
descriptor_name,
description : MapString(
format!("Specifies the (single) Core Schema used to create instances of L0 types within this HolonSpace.")
),
label,
described_by: None,
owned_by: None,
relationship_type_name,
source_owns_relationship: MapBoolean(false),
deletion_semantic: DeletionSemantic::Allow,
load_links_immediate: MapBoolean(false),
target_collection_type: CollectionTypeSpec{
semantic: CollectionSemantic::SingleInstance,
holon_type: CoreHolonTypeName::SchemaType,
},
has_inverse: None, // Should be None because `source_owns_relationship` is `false`

},
CollectionFor => RelationshipTypeLoader {
descriptor_name,
description : MapString(
Expand Down
5 changes: 2 additions & 3 deletions crates/coordinator/core_schema/src/value_type_loader.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use strum_macros::EnumIter;
use holons::context::HolonsContext;
use holons::holon_error::HolonError;
use holons::holon_reference::HolonReference;
use holons::staged_reference::StagedReference;
use shared_types_holon::MapString;
use crate::boolean_value_type_loader::CoreBooleanValueTypeName;

use crate::core_schema_types::{SchemaNamesTrait};
use crate::boolean_value_type_loader::CoreBooleanValueTypeName;
use crate::core_schema_types::SchemaNamesTrait;
use crate::enum_type_loader::CoreEnumTypeName;
use crate::integer_value_type_loader::CoreIntegerValueTypeName;
use crate::string_value_type_loader::CoreStringValueTypeName;
Expand Down
36 changes: 33 additions & 3 deletions crates/coordinator/dances/src/dance_request.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
use crate::staging_area::StagingArea;
use hdk::prelude::*;
use holons::cache_manager::HolonCacheManager;
use holons::commit_manager::StagedIndex;
use holons::context::HolonsContext;
use holons::holon::Holon;
use holons::holon_reference::HolonReference;
use holons::query::{NodeCollection, QueryExpression};
use holons::relationship::RelationshipName;


use shared_types_holon::{HolonId, LocalId, MapString, PropertyMap};
use crate::session_state::SessionState;


#[hdk_entry_helper]
#[derive(Clone, Eq, PartialEq)]
pub struct DanceRequest {
pub dance_name: MapString, // unique key within the (single) dispatch table
pub dance_type: DanceType,
pub body: RequestBody,
pub staging_area: StagingArea,
// pub staging_area: StagingArea,
state: SessionState,
//pub descriptor: Option<HolonReference>, // space_id+holon_id of DanceDescriptor
}


#[hdk_entry_helper]
#[derive(Clone, Eq, PartialEq)]
pub enum DanceType {
Expand Down Expand Up @@ -73,13 +80,36 @@ impl DanceRequest {
dance_name: MapString,
dance_type: DanceType,
body: RequestBody,
staging_area: StagingArea,
state: SessionState,
) -> Self {

Self {
dance_name,
dance_type,
body,
staging_area,
state,
}
}
pub fn get_state(&self) -> &SessionState {
&self.state
}
// Optionally, you can provide a mutable getter for state if needed
pub fn get_state_mut(&mut self) -> &mut SessionState {
&mut self.state
}
pub fn init_context_from_state(&self) -> HolonsContext {
let commit_manager = self.get_state().get_staging_area().to_commit_manager();
// assert_eq!(request.staging_area.staged_holons.len(),commit_manager.staged_holons.len());

let local_holon_space = self.get_state().get_local_holon_space();
info!("initializing context from session state in dance request");
HolonsContext::init_context(
commit_manager,
HolonCacheManager::new(),
local_holon_space,
)
}

}


19 changes: 15 additions & 4 deletions crates/coordinator/dances/src/dance_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ use holons::query::NodeCollection;
use crate::staging_area::StagingArea;
use hdk::prelude::*;
use holons::commit_manager::StagedIndex;
use holons::context::HolonsContext;
use holons::holon::Holon;
use holons::holon_error::HolonError;
use holons::holon_reference::HolonReference;
use shared_types_holon::MapString;
use crate::session_state::SessionState;

#[hdk_entry_helper]
#[derive(Clone, Eq, PartialEq)]
Expand All @@ -17,7 +19,7 @@ pub struct DanceResponse {
pub description: MapString,
pub body: ResponseBody,
pub descriptor: Option<HolonReference>, // space_id+holon_id of DanceDescriptor
pub staging_area: StagingArea,
pub state: SessionState,
}

/// Define a standard set of statuses that may be returned by DanceRequests.
Expand Down Expand Up @@ -58,6 +60,7 @@ impl From<HolonError> for ResponseStatusCode {
match error {
HolonError::EmptyField(_) => ResponseStatusCode::BadRequest,
HolonError::InvalidParameter(_) => ResponseStatusCode::BadRequest,
HolonError::InvalidType(_) => ResponseStatusCode::ServerError,
HolonError::HolonNotFound(_) => ResponseStatusCode::NotFound,
HolonError::CommitFailure(_) => ResponseStatusCode::ServerError,
HolonError::WasmError(_) => ResponseStatusCode::ServerError,
Expand All @@ -69,7 +72,7 @@ impl From<HolonError> for ResponseStatusCode {
HolonError::MissingStagedCollection(_) => ResponseStatusCode::BadRequest,
HolonError::FailedToBorrow(_) => ResponseStatusCode::ServerError,
HolonError::UnableToAddHolons(_) => ResponseStatusCode::ServerError,
HolonError::InvalidRelationship(_, _) => ResponseStatusCode::BadRequest,
HolonError::InvalidRelationship(_,_) => ResponseStatusCode::BadRequest,
HolonError::CacheError(_) => ResponseStatusCode::ServerError,
HolonError::NotAccessible(_, _) => ResponseStatusCode::Conflict,
HolonError::ValidationError(_) => ResponseStatusCode::BadRequest,
Expand Down Expand Up @@ -103,14 +106,22 @@ impl DanceResponse {
description: MapString,
body: ResponseBody,
descriptor: Option<HolonReference>,
staging_area: StagingArea,
state: SessionState,
) -> DanceResponse {
DanceResponse {
status_code,
description,
body,
descriptor,
staging_area,
state,
}
}
/// Restores the session state within the DanceResponse from context. This should always
/// be called before returning DanceResponse since the state is intended to be "ping-ponged"
/// between client and guest.
/// NOTE: Errors in restoring the state are not handled (i.e., will cause panic)
pub fn restore_state(&mut self, context: &HolonsContext) {
self.state.set_staging_area(StagingArea::from_commit_manager(&context.commit_manager.borrow()));
self.state.set_local_holon_space(context.get_local_holon_space());
}
}
Loading

0 comments on commit 5a8b416

Please sign in to comment.