11//! This module contains [`SchemaVariant`](crate::SchemaVariant), which is t/he "class" of a
22//! [`Component`](crate::Component).
33
4- use petgraph:: { Direction , Incoming } ;
4+ use petgraph:: { Direction , Incoming , Outgoing } ;
55use serde:: { Deserialize , Serialize } ;
66use serde_json:: Value ;
77use si_events:: ContentHash ;
@@ -20,7 +20,7 @@ use crate::attribute::prototype::AttributePrototypeError;
2020use crate :: change_set_pointer:: ChangeSetPointerError ;
2121use crate :: func:: argument:: { FuncArgument , FuncArgumentError } ;
2222use crate :: func:: intrinsics:: IntrinsicFunc ;
23- use crate :: func:: FuncError ;
23+ use crate :: func:: { FuncError , FuncKind } ;
2424use crate :: layer_db_types:: {
2525 InputSocketContent , OutputSocketContent , SchemaVariantContent ,
2626 SchemaVariantContentDiscriminants , SchemaVariantContentV1 ,
@@ -41,16 +41,14 @@ use crate::workspace_snapshot::WorkspaceSnapshotError;
4141use crate :: {
4242 pk,
4343 schema:: variant:: leaves:: { LeafInput , LeafInputLocation , LeafKind } ,
44- AttributePrototype , AttributePrototypeId , ComponentId , ComponentType , DalContext , Func ,
45- FuncBackendKind , FuncId , InputSocket , OutputSocket , OutputSocketId , Prop , PropId , PropKind ,
46- Schema , SchemaError , SchemaId , SocketArity , Timestamp , TransactionsError ,
44+ ActionPrototype , ActionPrototypeError , AttributePrototype , AttributePrototypeId , ComponentId ,
45+ ComponentType , DalContext , Func , FuncId , InputSocket , OutputSocket , OutputSocketId , Prop ,
46+ PropId , PropKind , Schema , SchemaError , SchemaId , SocketArity , Timestamp , TransactionsError ,
4747} ;
4848use crate :: { FuncBackendResponseType , InputSocketId } ;
4949
5050use self :: root_prop:: RootPropChild ;
5151
52- // use self::leaves::{LeafInput, LeafInputLocation, LeafKind};
53-
5452pub mod definition;
5553pub mod leaves;
5654pub mod root_prop;
@@ -64,6 +62,8 @@ pub const SCHEMA_VARIANT_VERSION: SchemaVariantContentDiscriminants =
6462#[ remain:: sorted]
6563#[ derive( Error , Debug ) ]
6664pub enum SchemaVariantError {
65+ #[ error( "action prototype error: {0}" ) ]
66+ ActionPrototype ( String ) ,
6767 #[ error( "attribute prototype error: {0}" ) ]
6868 AttributePrototype ( #[ from] AttributePrototypeError ) ,
6969 #[ error( "attribute argument prototype error: {0}" ) ]
@@ -305,7 +305,7 @@ impl SchemaVariant {
305305 . await ?;
306306
307307 let func_node_weight = node_weight. get_func_node_weight ( ) ?;
308- if func_node_weight. backend_kind ( ) == FuncBackendKind :: JsSchemaVariantDefinition {
308+ if func_node_weight. func_kind ( ) == FuncKind :: SchemaVariantDefinition {
309309 return Ok ( Some ( func_node_weight. id ( ) . into ( ) ) ) ;
310310 }
311311 }
@@ -1040,39 +1040,81 @@ impl SchemaVariant {
10401040 ctx : & DalContext ,
10411041 schema_variant_id : SchemaVariantId ,
10421042 ) -> SchemaVariantResult < Vec < Func > > {
1043+ let workspace_snapshot = ctx. workspace_snapshot ( ) ?;
10431044 let mut all_funcs = vec ! [ ] ;
1044- // auth funcs
1045- for func_id in Self :: list_auth_func_ids_for_schema_variant ( ctx, schema_variant_id) . await ? {
1046- let func = Func :: get_by_id ( ctx, func_id) . await ?;
1047- all_funcs. push ( func) ;
1048- }
1049- // attribute funcs
1050- for func_id in
1051- Self :: list_attribute_func_ids_for_schema_variant ( ctx, schema_variant_id) . await ?
1052- {
1053- let func = Func :: get_by_id ( ctx, func_id) . await ?;
1054- all_funcs. push ( func) ;
1055- }
1056- // qualification funcs
1057- for func_id in
1058- Self :: list_qualification_func_ids_for_schema_variant ( ctx, schema_variant_id) . await ?
1059- {
1060- let func = Func :: get_by_id ( ctx, func_id) . await ?;
1061- all_funcs. push ( func) ;
1045+
1046+ let sv = Self :: get_by_id ( ctx, schema_variant_id) . await ?;
1047+
1048+ let prop_list = sv. dump_props_as_list ( ctx) . await ?;
1049+ for prop_path in prop_list {
1050+ let prop_id = Prop :: find_prop_id_by_path ( ctx, schema_variant_id, & prop_path) . await ?;
1051+ // Let's get the Attribute funcs now
1052+ if let Some ( ap_id) = AttributePrototype :: find_for_prop ( ctx, prop_id, & None ) . await ? {
1053+ let func_id = AttributePrototype :: func_id ( ctx, ap_id) . await ?;
1054+
1055+ let node_weight = workspace_snapshot
1056+ . get_node_weight_by_id ( func_id)
1057+ . await ?
1058+ . get_func_node_weight ( ) ?;
1059+
1060+ match node_weight. func_kind ( ) {
1061+ FuncKind :: Attribute => {
1062+ let func = Func :: get_by_id ( ctx, func_id) . await ?;
1063+ all_funcs. push ( func) ;
1064+ }
1065+
1066+ _ => { }
1067+ }
1068+ }
1069+
1070+ // Now let's get all of the outgoing edges for the Prop
1071+ for ( edge_weight, _source, _target) in
1072+ workspace_snapshot. edges_directed ( prop_id, Outgoing ) . await ?
1073+ {
1074+ if let EdgeWeightKind :: Prototype ( Some ( key) ) = edge_weight. kind ( ) {
1075+ if let Some ( func_id) = Func :: find_by_name ( ctx, key) . await ? {
1076+ let func = Func :: get_by_id ( ctx, func_id) . await ?;
1077+ all_funcs. push ( func) ;
1078+ }
1079+ }
1080+ }
10621081 }
1063- // action funcs
1064- for func_id in Self :: list_action_func_ids_for_schema_variant ( ctx, schema_variant_id) . await ?
1065- {
1066- let func = Func :: get_by_id ( ctx, func_id) . await ?;
1067- all_funcs. push ( func) ;
1082+
1083+ // Let's get all of the Authentication funcs
1084+ let auth_func_ids =
1085+ Self :: list_auth_func_ids_for_schema_variant ( ctx, schema_variant_id) . await ?;
1086+ for auth_func_id in auth_func_ids {
1087+ let auth_func = Func :: get_by_id ( ctx, auth_func_id) . await ?;
1088+ // We may not need this - the list_auth_func_ids_for_schema_variant returns multiple
1089+ // of the same type
1090+ if !all_funcs. contains ( & auth_func) {
1091+ all_funcs. push ( auth_func) ;
1092+ }
10681093 }
1069- //code gen
1070- for func_id in
1071- Self :: list_code_gen_func_ids_for_schema_variant ( ctx, schema_variant_id) . await ?
1072- {
1073- let func = Func :: get_by_id ( ctx, func_id) . await ?;
1094+
1095+ let action_prototype_nodes = workspace_snapshot
1096+ . outgoing_targets_for_edge_weight_kind (
1097+ schema_variant_id,
1098+ EdgeWeightKindDiscriminants :: ActionPrototype ,
1099+ )
1100+ . await ?;
1101+ for action_prototype_node in action_prototype_nodes {
1102+ let weight = workspace_snapshot
1103+ . get_node_weight ( action_prototype_node)
1104+ . await ?;
1105+ let ap = ActionPrototype :: get_by_id ( ctx, weight. id ( ) . into ( ) )
1106+ . await
1107+ . map_err ( |e| SchemaVariantError :: ActionPrototype ( e. to_string ( ) ) ) ?;
1108+ let func = Func :: get_by_id (
1109+ ctx,
1110+ ap. func_id ( ctx)
1111+ . await
1112+ . map_err ( |e| SchemaVariantError :: ActionPrototype ( e. to_string ( ) ) ) ?,
1113+ )
1114+ . await ?;
10741115 all_funcs. push ( func) ;
10751116 }
1117+
10761118 Ok ( all_funcs)
10771119 }
10781120
0 commit comments