create-feltdb 0.11.2 → 0.11.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package-versions.js +1 -1
- package/dist/server-source/crates/feltdb/src/lib.rs +31 -30
- package/dist/server-source/crates/feltdb/src/semantic_decision.rs +1917 -0
- package/dist/server-source/crates/feltdb/tests/semantic_decision.rs +1165 -0
- package/dist/server-source/crates/feltdb-server/src/main.rs +232 -95
- package/dist/server-source/crates/feltdb-wasm/src/lib.rs +73 -8
- package/package.json +1 -1
|
@@ -97,6 +97,46 @@ pub fn compare_state_schemas(before: &str, after: &str) -> std::result::Result<S
|
|
|
97
97
|
.map_err(|e| JsValue::from_str(&e.to_string()))
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
/// Validate and canonicalize a typed semantic decision definition in the Rust core.
|
|
101
|
+
#[wasm_bindgen]
|
|
102
|
+
pub fn validate_semantic_decision_definition(
|
|
103
|
+
definition: &str,
|
|
104
|
+
) -> std::result::Result<String, JsValue> {
|
|
105
|
+
let definition: feltdb::DecisionDefinition =
|
|
106
|
+
serde_json::from_str(definition).map_err(|e| JsValue::from_str(&e.to_string()))?;
|
|
107
|
+
let validated = feltdb::validate_decision_definition(&definition).map_err(|e| {
|
|
108
|
+
JsValue::from_str(&serde_json::to_string(&e).unwrap_or_else(|_| e.to_string()))
|
|
109
|
+
})?;
|
|
110
|
+
serde_json::to_string(&validated).map_err(|e| JsValue::from_str(&e.to_string()))
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/// Validate a runtime-produced semantic decision result against the Rust contract.
|
|
114
|
+
#[wasm_bindgen]
|
|
115
|
+
pub fn validate_semantic_decision_result(
|
|
116
|
+
request: &str,
|
|
117
|
+
result: &str,
|
|
118
|
+
) -> std::result::Result<String, JsValue> {
|
|
119
|
+
let request: feltdb::DecisionRequest =
|
|
120
|
+
serde_json::from_str(request).map_err(|e| JsValue::from_str(&e.to_string()))?;
|
|
121
|
+
let result: feltdb::DecisionResult =
|
|
122
|
+
serde_json::from_str(result).map_err(|e| JsValue::from_str(&e.to_string()))?;
|
|
123
|
+
let validated = feltdb::validate_decision_result(&request, &result).map_err(|e| {
|
|
124
|
+
JsValue::from_str(&serde_json::to_string(&e).unwrap_or_else(|_| e.to_string()))
|
|
125
|
+
})?;
|
|
126
|
+
serde_json::to_string(&validated).map_err(|e| JsValue::from_str(&e.to_string()))
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/// Execute one semantic decision through the Rust-authoritative WASM boundary.
|
|
130
|
+
#[wasm_bindgen]
|
|
131
|
+
pub fn execute_semantic_decision(request: &str) -> std::result::Result<String, JsValue> {
|
|
132
|
+
let request: feltdb::DecisionTransportExecutionRequest =
|
|
133
|
+
serde_json::from_str(request).map_err(|e| JsValue::from_str(&e.to_string()))?;
|
|
134
|
+
let response = feltdb::execute_inline_decision_transport(&request).map_err(|e| {
|
|
135
|
+
JsValue::from_str(&serde_json::to_string(&e).unwrap_or_else(|_| e.to_string()))
|
|
136
|
+
})?;
|
|
137
|
+
serde_json::to_string(&response).map_err(|e| JsValue::from_str(&e.to_string()))
|
|
138
|
+
}
|
|
139
|
+
|
|
100
140
|
/// Verify a portable signed grant with the exact Rust canonicalization used by
|
|
101
141
|
/// the server. The verification key is provisioned with the offline app shell.
|
|
102
142
|
#[wasm_bindgen]
|
|
@@ -349,6 +389,27 @@ impl JsDb {
|
|
|
349
389
|
},
|
|
350
390
|
}
|
|
351
391
|
}
|
|
392
|
+
pub fn execute_semantic_decision(&self, request: &str) -> JsResult {
|
|
393
|
+
let result = (|| {
|
|
394
|
+
let request: feltdb::DecisionTransportExecutionRequest =
|
|
395
|
+
serde_json::from_str(request).map_err(|e| e.to_string())?;
|
|
396
|
+
feltdb::execute_decision_transport(&self.db, &request)
|
|
397
|
+
.map_err(|e| serde_json::to_string(&e).unwrap_or_else(|_| e.to_string()))
|
|
398
|
+
})()
|
|
399
|
+
.and_then(|v| serde_json::to_string(&v).map_err(|e| e.to_string()));
|
|
400
|
+
match result {
|
|
401
|
+
Ok(data) => JsResult {
|
|
402
|
+
success: true,
|
|
403
|
+
data: Some(data),
|
|
404
|
+
error: None,
|
|
405
|
+
},
|
|
406
|
+
Err(error) => JsResult {
|
|
407
|
+
success: false,
|
|
408
|
+
data: None,
|
|
409
|
+
error: Some(error),
|
|
410
|
+
},
|
|
411
|
+
}
|
|
412
|
+
}
|
|
352
413
|
/// Insert a record into the database
|
|
353
414
|
///
|
|
354
415
|
/// # Arguments
|
|
@@ -729,7 +790,8 @@ impl WasmIndexManager {
|
|
|
729
790
|
pub fn create_index(&mut self, config: &str) -> Result<(), JsValue> {
|
|
730
791
|
let index_config: feltdb::IndexConfig =
|
|
731
792
|
serde_json::from_str(config).map_err(|e| JsValue::from_str(&e.to_string()))?;
|
|
732
|
-
self.manager
|
|
793
|
+
self.manager
|
|
794
|
+
.create_index(index_config)
|
|
733
795
|
.map_err(|e| JsValue::from_str(&e))
|
|
734
796
|
}
|
|
735
797
|
|
|
@@ -754,7 +816,8 @@ impl WasmIndexManager {
|
|
|
754
816
|
operator: &str,
|
|
755
817
|
value: &str,
|
|
756
818
|
) -> Result<String, JsValue> {
|
|
757
|
-
let results = self
|
|
819
|
+
let results = self
|
|
820
|
+
.manager
|
|
758
821
|
.query_index(index_name, operator, value)
|
|
759
822
|
.map_err(|e| JsValue::from_str(&e))?;
|
|
760
823
|
serde_json::to_string(&results).map_err(|e| JsValue::from_str(&e.to_string()))
|
|
@@ -770,7 +833,8 @@ impl WasmIndexManager {
|
|
|
770
833
|
/// Get statistics for an index.
|
|
771
834
|
#[wasm_bindgen]
|
|
772
835
|
pub fn get_stats(&self, name: &str) -> Result<String, JsValue> {
|
|
773
|
-
let stats = self
|
|
836
|
+
let stats = self
|
|
837
|
+
.manager
|
|
774
838
|
.get_stats(name)
|
|
775
839
|
.ok_or_else(|| JsValue::from_str("Index not found"))?;
|
|
776
840
|
serde_json::to_string(&stats).map_err(|e| JsValue::from_str(&e.to_string()))
|
|
@@ -807,8 +871,8 @@ impl WasmShardManager {
|
|
|
807
871
|
/// Initialize shards
|
|
808
872
|
#[wasm_bindgen]
|
|
809
873
|
pub fn initialize_shards(&mut self, shard_ids_json: &str) -> Result<(), JsValue> {
|
|
810
|
-
let shard_ids: Vec<String> =
|
|
811
|
-
.map_err(|e| JsValue::from_str(&e.to_string()))?;
|
|
874
|
+
let shard_ids: Vec<String> =
|
|
875
|
+
serde_json::from_str(shard_ids_json).map_err(|e| JsValue::from_str(&e.to_string()))?;
|
|
812
876
|
|
|
813
877
|
let shard_ids: Vec<_> = shard_ids
|
|
814
878
|
.into_iter()
|
|
@@ -978,7 +1042,8 @@ impl WasmAnalytics {
|
|
|
978
1042
|
/// Record an index usage event.
|
|
979
1043
|
#[wasm_bindgen]
|
|
980
1044
|
pub fn record_index_usage(&mut self, index_name: &str, operation: &str, time_ms: f64) {
|
|
981
|
-
self.analytics
|
|
1045
|
+
self.analytics
|
|
1046
|
+
.record_index_usage(index_name, operation, time_ms);
|
|
982
1047
|
}
|
|
983
1048
|
|
|
984
1049
|
/// Record a query execution with performance metrics.
|
|
@@ -992,8 +1057,8 @@ impl WasmAnalytics {
|
|
|
992
1057
|
result_count: u64,
|
|
993
1058
|
index_used: Option<String>,
|
|
994
1059
|
) -> Result<(), JsValue> {
|
|
995
|
-
let fields: Vec<String> =
|
|
996
|
-
.map_err(|e| JsValue::from_str(&e.to_string()))?;
|
|
1060
|
+
let fields: Vec<String> =
|
|
1061
|
+
serde_json::from_str(fields_json).map_err(|e| JsValue::from_str(&e.to_string()))?;
|
|
997
1062
|
self.analytics.record_query(
|
|
998
1063
|
fields,
|
|
999
1064
|
operator.to_string(),
|