@feltdb/core 0.13.0 → 0.16.0

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.
Files changed (300) hide show
  1. package/dist/agent-runtime.d.ts +64 -2
  2. package/dist/agent-runtime.d.ts.map +1 -1
  3. package/dist/agent-runtime.js +121 -11
  4. package/dist/agent-state.d.ts +68 -0
  5. package/dist/agent-state.d.ts.map +1 -1
  6. package/dist/agent-state.js +210 -12
  7. package/dist/agent.d.ts +10 -1
  8. package/dist/agent.d.ts.map +1 -1
  9. package/dist/agent.js +10 -1
  10. package/dist/build-identity.json +12 -4
  11. package/dist/cli/commands.js +214 -10
  12. package/dist/cli/publish-engine.js +116 -16
  13. package/dist/collection.d.ts +3 -1
  14. package/dist/collection.d.ts.map +1 -1
  15. package/dist/collection.js +33 -8
  16. package/dist/create/build-identity.json +12 -4
  17. package/dist/create/cli.js +1 -1
  18. package/dist/create/create.js +4 -6
  19. package/dist/create/managed-account.js +93 -35
  20. package/dist/create/package-versions.js +1 -1
  21. package/dist/create/server-source/Cargo.lock +8 -511
  22. package/dist/create/server-source/Cargo.toml +2 -13
  23. package/dist/create/server-source/crates/feltdb-client/Cargo.toml +1 -1
  24. package/dist/create/server-source/crates/feltdb-server/Cargo.toml +1 -1
  25. package/dist/create/server-source/crates/feltdb-server/README.md +6 -1
  26. package/dist/create/server-source/crates/feltdb-server/src/app_state.rs +9 -1
  27. package/dist/create/server-source/crates/feltdb-server/src/auth.rs +85 -25
  28. package/dist/create/server-source/crates/feltdb-server/src/backup.rs +4 -0
  29. package/dist/create/server-source/crates/feltdb-server/src/console_accounts.rs +1009 -0
  30. package/dist/create/server-source/crates/feltdb-server/src/control_authorization.rs +441 -0
  31. package/dist/create/server-source/crates/feltdb-server/src/identity.rs +68 -6
  32. package/dist/create/server-source/crates/feltdb-server/src/key_management.rs +355 -23
  33. package/dist/create/server-source/crates/feltdb-server/src/lib.rs +3 -0
  34. package/dist/create/server-source/crates/feltdb-server/src/main.rs +1134 -96
  35. package/dist/create/server-source/crates/feltdb-server/src/redaction.rs +208 -0
  36. package/dist/create/server-source/crates/feltdb-server/src/tenancy.rs +198 -19
  37. package/dist/create/server-source/crates/feltdb-server/tests/transaction_precondition_contract.rs +403 -0
  38. package/dist/create/server-source/crates/feltdb-wasm/Cargo.toml +1 -1
  39. package/dist/db.d.ts +75 -10
  40. package/dist/db.d.ts.map +1 -1
  41. package/dist/db.js +168 -29
  42. package/dist/deployment.d.ts +19 -0
  43. package/dist/deployment.d.ts.map +1 -1
  44. package/dist/deployment.js +38 -2
  45. package/dist/embedded-query.d.ts.map +1 -1
  46. package/dist/embedded-query.js +5 -4
  47. package/dist/embedded-transaction.d.ts +8 -4
  48. package/dist/embedded-transaction.d.ts.map +1 -1
  49. package/dist/embedded-transaction.js +55 -19
  50. package/dist/error-codes.d.ts +36 -2
  51. package/dist/error-codes.d.ts.map +1 -1
  52. package/dist/error-codes.js +50 -3
  53. package/dist/feltdb.d.ts +7 -0
  54. package/dist/feltdb.d.ts.map +1 -1
  55. package/dist/file-db.d.ts +27 -0
  56. package/dist/file-db.d.ts.map +1 -1
  57. package/dist/file-db.js +145 -7
  58. package/dist/http-client.d.ts +11 -3
  59. package/dist/http-client.d.ts.map +1 -1
  60. package/dist/http-client.js +27 -14
  61. package/dist/http-db.d.ts +43 -1
  62. package/dist/http-db.d.ts.map +1 -1
  63. package/dist/http-db.js +287 -59
  64. package/dist/index.js +1 -1
  65. package/dist/local-state-lock.d.ts +34 -0
  66. package/dist/local-state-lock.d.ts.map +1 -0
  67. package/dist/local-state-lock.js +225 -0
  68. package/dist/managed-recovery.d.ts +6 -0
  69. package/dist/managed-recovery.d.ts.map +1 -1
  70. package/dist/managed-recovery.js +9 -0
  71. package/dist/reactive-graph.d.ts +0 -3
  72. package/dist/reactive-graph.d.ts.map +1 -1
  73. package/dist/reactive-graph.js +11 -1
  74. package/dist/runtime-registry.d.ts +7 -2
  75. package/dist/runtime-registry.d.ts.map +1 -1
  76. package/dist/runtime-registry.js +2 -2
  77. package/dist/studio/components/index.js +1 -1
  78. package/dist/studio/{components-BSGmHfif.js → components-CJmzntBi.js} +2 -1
  79. package/dist/studio/index.js +1 -1
  80. package/dist/studio-app/assets/{feltdb_wasm-3hDngl1h.js → feltdb_wasm-DtybUY0q.js} +1 -1
  81. package/dist/studio-app/assets/feltdb_wasm_bg-DsgIUwaB.wasm +0 -0
  82. package/dist/studio-app/assets/index-C4OffsZl.js +37 -0
  83. package/dist/studio-app/index.html +1 -1
  84. package/dist/transaction.d.ts +27 -11
  85. package/dist/transaction.d.ts.map +1 -1
  86. package/dist/transaction.js +20 -14
  87. package/dist/wasm/feltdb_wasm_bg.wasm +0 -0
  88. package/dist/wasm/package.json +1 -1
  89. package/dist/workload.d.ts +86 -6
  90. package/dist/workload.d.ts.map +1 -1
  91. package/dist/workload.js +51 -3
  92. package/dist/workspace/workspace-connection.d.ts.map +1 -1
  93. package/dist/workspace/workspace-connection.js +14 -3
  94. package/package.json +1 -1
  95. package/dist/create/server-source/crates/feltdb/Cargo.lock +0 -175
  96. package/dist/create/server-source/crates/feltdb/Cargo.toml +0 -102
  97. package/dist/create/server-source/crates/feltdb/LICENSE +0 -21
  98. package/dist/create/server-source/crates/feltdb/README.md +0 -75
  99. package/dist/create/server-source/crates/feltdb/benches/baselines/gate-13-redux.json +0 -370
  100. package/dist/create/server-source/crates/feltdb/benches/gate13_baseline.rs +0 -589
  101. package/dist/create/server-source/crates/feltdb/benches/gate13_phase_7_1_release_economics.rs +0 -247
  102. package/dist/create/server-source/crates/feltdb/benches/gate_13_redux.rs +0 -440
  103. package/dist/create/server-source/crates/feltdb/benches/gate_13_regression_runner.rs +0 -275
  104. package/dist/create/server-source/crates/feltdb/benches/gate_14a_concurrent_writer_scaling.rs +0 -381
  105. package/dist/create/server-source/crates/feltdb/benches/gate_14a_production_admission_revalidation.rs +0 -467
  106. package/dist/create/server-source/crates/feltdb/benches/gate_14a_rc2_admission_contract.rs +0 -489
  107. package/dist/create/server-source/crates/feltdb/benches/gate_14a_rc_root_cause.rs +0 -281
  108. package/dist/create/server-source/crates/feltdb/benches/gate_14a_sync1_queued_prototype.rs +0 -606
  109. package/dist/create/server-source/crates/feltdb/benches/gate_14a_sync_economics.rs +0 -531
  110. package/dist/create/server-source/crates/feltdb/benches/gate_14b_causal_backlog_scaling.rs +0 -462
  111. package/dist/create/server-source/crates/feltdb/benches/gate_14c_replication_contract_test.rs +0 -505
  112. package/dist/create/server-source/crates/feltdb/benches/gate_14c_replication_scaling.rs +0 -484
  113. package/dist/create/server-source/crates/feltdb/benches/gate_14d_combined_dimension_scaling.rs +0 -758
  114. package/dist/create/server-source/crates/feltdb/benches/phase_7_1_2_optimization_benchmark.rs +0 -421
  115. package/dist/create/server-source/crates/feltdb/benches/phase_7_1_3_crossover_analysis.rs +0 -329
  116. package/dist/create/server-source/crates/feltdb/src/acceptance_tests.rs +0 -1705
  117. package/dist/create/server-source/crates/feltdb/src/acquisition.rs +0 -286
  118. package/dist/create/server-source/crates/feltdb/src/admission.rs +0 -185
  119. package/dist/create/server-source/crates/feltdb/src/admission_contract_tests.rs +0 -507
  120. package/dist/create/server-source/crates/feltdb/src/adversarial_transport.rs +0 -539
  121. package/dist/create/server-source/crates/feltdb/src/agent_state.rs +0 -320
  122. package/dist/create/server-source/crates/feltdb/src/agent_transition_contract.rs +0 -1545
  123. package/dist/create/server-source/crates/feltdb/src/analytics.rs +0 -521
  124. package/dist/create/server-source/crates/feltdb/src/application.rs +0 -2674
  125. package/dist/create/server-source/crates/feltdb/src/application_runtime.rs +0 -1070
  126. package/dist/create/server-source/crates/feltdb/src/authority.rs +0 -479
  127. package/dist/create/server-source/crates/feltdb/src/authority_failover.rs +0 -847
  128. package/dist/create/server-source/crates/feltdb/src/authorization.rs +0 -1030
  129. package/dist/create/server-source/crates/feltdb/src/authorization_security_tests.rs +0 -1122
  130. package/dist/create/server-source/crates/feltdb/src/bin/feltdb-authority-client.rs +0 -32
  131. package/dist/create/server-source/crates/feltdb/src/bin/feltdb-authority.rs +0 -19
  132. package/dist/create/server-source/crates/feltdb/src/bin/feltdb_node.rs +0 -1474
  133. package/dist/create/server-source/crates/feltdb/src/capabilities/mod.rs +0 -8
  134. package/dist/create/server-source/crates/feltdb/src/capabilities/search.rs +0 -418
  135. package/dist/create/server-source/crates/feltdb/src/capabilities/vector.rs +0 -482
  136. package/dist/create/server-source/crates/feltdb/src/capability.rs +0 -903
  137. package/dist/create/server-source/crates/feltdb/src/cardinality_diagnostics.rs +0 -263
  138. package/dist/create/server-source/crates/feltdb/src/cardinality_endpoint.rs +0 -77
  139. package/dist/create/server-source/crates/feltdb/src/causal_backlog_bound.rs +0 -496
  140. package/dist/create/server-source/crates/feltdb/src/causal_dependency_barrier.rs +0 -2574
  141. package/dist/create/server-source/crates/feltdb/src/causal_dependency_barrier_phase_7_1.rs +0 -212
  142. package/dist/create/server-source/crates/feltdb/src/concurrency_fuzzing.rs +0 -422
  143. package/dist/create/server-source/crates/feltdb/src/consistency_contract.rs +0 -445
  144. package/dist/create/server-source/crates/feltdb/src/content_distribution.rs +0 -465
  145. package/dist/create/server-source/crates/feltdb/src/convergence.rs +0 -634
  146. package/dist/create/server-source/crates/feltdb/src/crash_atomic_boundary.rs +0 -427
  147. package/dist/create/server-source/crates/feltdb/src/crash_injection.rs +0 -376
  148. package/dist/create/server-source/crates/feltdb/src/crash_recovery_tests.rs +0 -365
  149. package/dist/create/server-source/crates/feltdb/src/cron.rs +0 -294
  150. package/dist/create/server-source/crates/feltdb/src/dedup_bound_investigation.rs +0 -483
  151. package/dist/create/server-source/crates/feltdb/src/distributed_indexing.rs +0 -477
  152. package/dist/create/server-source/crates/feltdb/src/distributed_tests.rs +0 -1003
  153. package/dist/create/server-source/crates/feltdb/src/distributed_transactions.rs +0 -1334
  154. package/dist/create/server-source/crates/feltdb/src/durability_guarantees.rs +0 -368
  155. package/dist/create/server-source/crates/feltdb/src/durable_dedup_set.rs +0 -231
  156. package/dist/create/server-source/crates/feltdb/src/durable_operation_identity.rs +0 -482
  157. package/dist/create/server-source/crates/feltdb/src/durable_operation_log.rs +0 -203
  158. package/dist/create/server-source/crates/feltdb/src/durable_sync.rs +0 -317
  159. package/dist/create/server-source/crates/feltdb/src/equality_index.rs +0 -595
  160. package/dist/create/server-source/crates/feltdb/src/execution.rs +0 -426
  161. package/dist/create/server-source/crates/feltdb/src/in_process_transport.rs +0 -214
  162. package/dist/create/server-source/crates/feltdb/src/indexing.rs +0 -776
  163. package/dist/create/server-source/crates/feltdb/src/lib.rs +0 -7274
  164. package/dist/create/server-source/crates/feltdb/src/managed_cas_tests.rs +0 -234
  165. package/dist/create/server-source/crates/feltdb/src/materialization.rs +0 -184
  166. package/dist/create/server-source/crates/feltdb/src/metrics.rs +0 -266
  167. package/dist/create/server-source/crates/feltdb/src/multi_node_convergence.rs +0 -310
  168. package/dist/create/server-source/crates/feltdb/src/multi_operation_transaction.rs +0 -736
  169. package/dist/create/server-source/crates/feltdb/src/observability.rs +0 -379
  170. package/dist/create/server-source/crates/feltdb/src/operation.rs +0 -290
  171. package/dist/create/server-source/crates/feltdb/src/operation_algebra.rs +0 -439
  172. package/dist/create/server-source/crates/feltdb/src/operation_log.rs +0 -349
  173. package/dist/create/server-source/crates/feltdb/src/p1_application_atomicity.rs +0 -332
  174. package/dist/create/server-source/crates/feltdb/src/p1_atomicity_acceptance.rs +0 -718
  175. package/dist/create/server-source/crates/feltdb/src/partition_reconciliation.rs +0 -487
  176. package/dist/create/server-source/crates/feltdb/src/peer_registry.rs +0 -166
  177. package/dist/create/server-source/crates/feltdb/src/permutation_scheduler.rs +0 -289
  178. package/dist/create/server-source/crates/feltdb/src/persistence_reality.rs +0 -566
  179. package/dist/create/server-source/crates/feltdb/src/phase1b_acceptance.rs +0 -3391
  180. package/dist/create/server-source/crates/feltdb/src/phase1c1_acceptance.rs +0 -203
  181. package/dist/create/server-source/crates/feltdb/src/phase1c2_acceptance.rs +0 -261
  182. package/dist/create/server-source/crates/feltdb/src/phase1c3_acceptance.rs +0 -502
  183. package/dist/create/server-source/crates/feltdb/src/phase1c_atomicity_proof.rs +0 -216
  184. package/dist/create/server-source/crates/feltdb/src/phase5_integration.rs +0 -303
  185. package/dist/create/server-source/crates/feltdb/src/phase5_scenarios.rs +0 -323
  186. package/dist/create/server-source/crates/feltdb/src/phase6_adversarial_scenarios.rs +0 -531
  187. package/dist/create/server-source/crates/feltdb/src/phase6_convergence_validator.rs +0 -406
  188. package/dist/create/server-source/crates/feltdb/src/phase6_persistence.rs +0 -436
  189. package/dist/create/server-source/crates/feltdb/src/phase_1c_real_tcp.rs +0 -387
  190. package/dist/create/server-source/crates/feltdb/src/phase_2a_failures.rs +0 -378
  191. package/dist/create/server-source/crates/feltdb/src/phase_2b_network.rs +0 -359
  192. package/dist/create/server-source/crates/feltdb/src/phase_2c_cascading.rs +0 -372
  193. package/dist/create/server-source/crates/feltdb/src/phase_3_durability.rs +0 -404
  194. package/dist/create/server-source/crates/feltdb/src/phase_4_baseline.rs +0 -376
  195. package/dist/create/server-source/crates/feltdb/src/phase_5_soak.rs +0 -461
  196. package/dist/create/server-source/crates/feltdb/src/policy_evaluation.rs +0 -2125
  197. package/dist/create/server-source/crates/feltdb/src/production_api.rs +0 -418
  198. package/dist/create/server-source/crates/feltdb/src/provenance.rs +0 -207
  199. package/dist/create/server-source/crates/feltdb/src/query_execution_diagnostics.rs +0 -126
  200. package/dist/create/server-source/crates/feltdb/src/query_performance.rs +0 -218
  201. package/dist/create/server-source/crates/feltdb/src/read_basis.rs +0 -257
  202. package/dist/create/server-source/crates/feltdb/src/references.rs +0 -404
  203. package/dist/create/server-source/crates/feltdb/src/replay_fuzzing.rs +0 -401
  204. package/dist/create/server-source/crates/feltdb/src/replica_acknowledgements.rs +0 -501
  205. package/dist/create/server-source/crates/feltdb/src/replica_membership.rs +0 -680
  206. package/dist/create/server-source/crates/feltdb/src/replication_manager.rs +0 -163
  207. package/dist/create/server-source/crates/feltdb/src/replication_protocol.rs +0 -133
  208. package/dist/create/server-source/crates/feltdb/src/routing.rs +0 -409
  209. package/dist/create/server-source/crates/feltdb/src/semantic_decision.rs +0 -2029
  210. package/dist/create/server-source/crates/feltdb/src/semantic_query.rs +0 -599
  211. package/dist/create/server-source/crates/feltdb/src/sharding.rs +0 -549
  212. package/dist/create/server-source/crates/feltdb/src/state_conflict_contract.rs +0 -516
  213. package/dist/create/server-source/crates/feltdb/src/state_contract.rs +0 -5894
  214. package/dist/create/server-source/crates/feltdb/src/state_diff_contract.rs +0 -222
  215. package/dist/create/server-source/crates/feltdb/src/state_facade.rs +0 -320
  216. package/dist/create/server-source/crates/feltdb/src/state_hash.rs +0 -291
  217. package/dist/create/server-source/crates/feltdb/src/state_model.rs +0 -4158
  218. package/dist/create/server-source/crates/feltdb/src/state_transition_store.rs +0 -379
  219. package/dist/create/server-source/crates/feltdb/src/state_trigger.rs +0 -673
  220. package/dist/create/server-source/crates/feltdb/src/storage.rs +0 -273
  221. package/dist/create/server-source/crates/feltdb/src/submission.rs +0 -471
  222. package/dist/create/server-source/crates/feltdb/src/sync.rs +0 -495
  223. package/dist/create/server-source/crates/feltdb/src/sync_contract.rs +0 -822
  224. package/dist/create/server-source/crates/feltdb/src/tcp_transport.rs +0 -433
  225. package/dist/create/server-source/crates/feltdb/src/transaction_api.rs +0 -462
  226. package/dist/create/server-source/crates/feltdb/src/transaction_invariants.rs +0 -965
  227. package/dist/create/server-source/crates/feltdb/src/transaction_preconditions.rs +0 -1120
  228. package/dist/create/server-source/crates/feltdb/src/transactions.rs +0 -643
  229. package/dist/create/server-source/crates/feltdb/src/trigger.rs +0 -390
  230. package/dist/create/server-source/crates/feltdb/src/trigger_contract.rs +0 -749
  231. package/dist/create/server-source/crates/feltdb/src/versioned_object_substrate.rs +0 -708
  232. package/dist/create/server-source/crates/feltdb/src/worker_mesh.rs +0 -1133
  233. package/dist/create/server-source/crates/feltdb/src/workflow.rs +0 -713
  234. package/dist/create/server-source/crates/feltdb/src/workflow_acceptance_tests.rs +0 -510
  235. package/dist/create/server-source/crates/feltdb/src/workflow_integration.rs +0 -354
  236. package/dist/create/server-source/crates/feltdb/src/workflow_runtime.rs +0 -594
  237. package/dist/create/server-source/crates/feltdb/src/workload.rs +0 -2886
  238. package/dist/create/server-source/crates/feltdb/src/workload_diagnostics.rs +0 -456
  239. package/dist/create/server-source/crates/feltdb/tests/agent_state_native.rs +0 -1188
  240. package/dist/create/server-source/crates/feltdb/tests/agent_transition_contract_conformance.rs +0 -2884
  241. package/dist/create/server-source/crates/feltdb/tests/authority_process.rs +0 -297
  242. package/dist/create/server-source/crates/feltdb/tests/authority_transaction_identity.rs +0 -534
  243. package/dist/create/server-source/crates/feltdb/tests/bounded_read_contract.rs +0 -132
  244. package/dist/create/server-source/crates/feltdb/tests/branching_evidence.rs +0 -299
  245. package/dist/create/server-source/crates/feltdb/tests/common/mod.rs +0 -96
  246. package/dist/create/server-source/crates/feltdb/tests/compaction_stall_contract.rs +0 -272
  247. package/dist/create/server-source/crates/feltdb/tests/crash_durability_contract.rs +0 -467
  248. package/dist/create/server-source/crates/feltdb/tests/current_revision_authority_evidence.rs +0 -309
  249. package/dist/create/server-source/crates/feltdb/tests/durable_backup_contract.rs +0 -445
  250. package/dist/create/server-source/crates/feltdb/tests/durable_corruption_contract.rs +0 -518
  251. package/dist/create/server-source/crates/feltdb/tests/durable_format_compatibility.rs +0 -392
  252. package/dist/create/server-source/crates/feltdb/tests/feltdb_state_boundary_tests.rs +0 -850
  253. package/dist/create/server-source/crates/feltdb/tests/fixtures/agent_transition_corpus.json +0 -23340
  254. package/dist/create/server-source/crates/feltdb/tests/fixtures/state_conflict_contract_corpus.json +0 -1916
  255. package/dist/create/server-source/crates/feltdb/tests/fixtures/state_diff_contract_corpus.json +0 -1878
  256. package/dist/create/server-source/crates/feltdb/tests/fixtures/trigger_contract_corpus.json +0 -1862
  257. package/dist/create/server-source/crates/feltdb/tests/generalized_version_control_evidence.rs +0 -123
  258. package/dist/create/server-source/crates/feltdb/tests/generalized_version_control_substrate_completion.rs +0 -299
  259. package/dist/create/server-source/crates/feltdb/tests/local_process_ownership.rs +0 -69
  260. package/dist/create/server-source/crates/feltdb/tests/managed_incident_regression.rs +0 -191
  261. package/dist/create/server-source/crates/feltdb/tests/operational_health_contract.rs +0 -278
  262. package/dist/create/server-source/crates/feltdb/tests/pr34_query_collection.rs +0 -234
  263. package/dist/create/server-source/crates/feltdb/tests/pr35_equality_index.rs +0 -947
  264. package/dist/create/server-source/crates/feltdb/tests/pr7_self_authorization_proof.rs +0 -404
  265. package/dist/create/server-source/crates/feltdb/tests/pr8_vocabulary_assessment.rs +0 -916
  266. package/dist/create/server-source/crates/feltdb/tests/pr9_phase2_boundary_tests.rs +0 -1045
  267. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3a_path_a_tests.rs +0 -347
  268. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_authorized_mutations.rs +0 -361
  269. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_role_based_authorization.rs +0 -330
  270. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_simple_auth_delete.rs +0 -93
  271. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_team_delete_role_authorization.rs +0 -622
  272. package/dist/create/server-source/crates/feltdb/tests/pr9_teams_role_based_access.rs +0 -517
  273. package/dist/create/server-source/crates/feltdb/tests/production_certification.rs +0 -1153
  274. package/dist/create/server-source/crates/feltdb/tests/production_contract.rs +0 -771
  275. package/dist/create/server-source/crates/feltdb/tests/production_readiness_contract.rs +0 -1383
  276. package/dist/create/server-source/crates/feltdb/tests/reconciliation_application.rs +0 -868
  277. package/dist/create/server-source/crates/feltdb/tests/reconciliation_wire_format_evidence.rs +0 -221
  278. package/dist/create/server-source/crates/feltdb/tests/replicated_history_contract.rs +0 -417
  279. package/dist/create/server-source/crates/feltdb/tests/resource_scoped_revisions.rs +0 -338
  280. package/dist/create/server-source/crates/feltdb/tests/revision_identity_contract.rs +0 -1039
  281. package/dist/create/server-source/crates/feltdb/tests/revision_model_decision.rs +0 -739
  282. package/dist/create/server-source/crates/feltdb/tests/revision_retention_boundary_evidence.rs +0 -452
  283. package/dist/create/server-source/crates/feltdb/tests/saas_authorization_integration.rs +0 -81
  284. package/dist/create/server-source/crates/feltdb/tests/saas_invitation_lifecycle.rs +0 -438
  285. package/dist/create/server-source/crates/feltdb/tests/semantic_decision.rs +0 -1165
  286. package/dist/create/server-source/crates/feltdb/tests/semantic_query.rs +0 -767
  287. package/dist/create/server-source/crates/feltdb/tests/semantic_query_contract.rs +0 -363
  288. package/dist/create/server-source/crates/feltdb/tests/state_conflict_contract_conformance.rs +0 -1799
  289. package/dist/create/server-source/crates/feltdb/tests/state_diff_contract_conformance.rs +0 -1316
  290. package/dist/create/server-source/crates/feltdb/tests/state_model_integration.rs +0 -358
  291. package/dist/create/server-source/crates/feltdb/tests/state_persistence_integration.rs +0 -365
  292. package/dist/create/server-source/crates/feltdb/tests/state_ref_authority.rs +0 -918
  293. package/dist/create/server-source/crates/feltdb/tests/state_store_boundary_evidence.rs +0 -299
  294. package/dist/create/server-source/crates/feltdb/tests/storage_independent_versioned_object_substrate.rs +0 -328
  295. package/dist/create/server-source/crates/feltdb/tests/sync_divergence_evidence.rs +0 -255
  296. package/dist/create/server-source/crates/feltdb/tests/three_way_input_boundary_evidence.rs +0 -249
  297. package/dist/create/server-source/crates/feltdb/tests/trigger_contract_conformance.rs +0 -994
  298. package/dist/create/server-source/crates/feltdb/tests/workload_envelope_contract.rs +0 -484
  299. package/dist/studio-app/assets/feltdb_wasm_bg-CFQT4gCy.wasm +0 -0
  300. package/dist/studio-app/assets/index-Dql1hS5m.js +0 -30
@@ -1,903 +0,0 @@
1
- use crate::Operation;
2
- /// Capability and Extension Runtime module
3
- ///
4
- /// Capabilities are extensible projections that consume the FeltDB operation stream
5
- /// and maintain rebuildable derived state. They follow a generic contract:
6
- ///
7
- /// canonical operation → capability → derived state → capability query
8
- ///
9
- /// This keeps the core log generic while allowing specialized behavior.
10
- use serde::{Deserialize, Serialize};
11
- use serde_json::Value;
12
- use std::collections::HashMap;
13
- use std::fmt;
14
-
15
- /// Unique capability identifier
16
- #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
17
- pub struct CapabilityId(pub String);
18
-
19
- impl fmt::Display for CapabilityId {
20
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21
- write!(f, "{}", self.0)
22
- }
23
- }
24
-
25
- impl CapabilityId {
26
- pub fn new(id: String) -> Self {
27
- CapabilityId(id)
28
- }
29
- }
30
-
31
- /// The roles a capability can fulfill
32
- #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
33
- pub enum CapabilityRole {
34
- /// Triggers and executes business logic
35
- ExecutionEngine,
36
- /// Maintains a projection/index of canonical state
37
- Projection,
38
- /// Both executes and maintains a projection
39
- ExecutionWithProjection,
40
- }
41
-
42
- /// Lifecycle states for a capability
43
- #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
44
- pub enum CapabilityLifecycleState {
45
- /// Capability has been registered but not yet initialized
46
- Registered,
47
- /// Capability is initializing its state
48
- Initializing,
49
- /// Capability is catching up with historical operations
50
- CatchingUp,
51
- /// Capability is active and processing new operations
52
- Active,
53
- /// Capability is paused
54
- Paused,
55
- /// Capability is being rebuilt
56
- Rebuilding,
57
- /// Capability has been removed
58
- Removed,
59
- }
60
-
61
- /// Context passed to capability operations
62
- #[derive(Debug, Clone, Serialize, Deserialize)]
63
- pub struct CapabilityContext {
64
- /// The capability ID
65
- pub capability_id: CapabilityId,
66
- /// Instance ID of the FeltDB instance
67
- pub instance_id: String,
68
- /// Current sequence number
69
- pub sequence: u64,
70
- /// Capability version
71
- pub version: u32,
72
- }
73
-
74
- /// Query structure for capability queries
75
- #[derive(Debug, Clone, Serialize, Deserialize)]
76
- pub struct CapabilityQuery {
77
- /// Query type (e.g., "search", "vector_find", "analytics")
78
- pub query_type: String,
79
- /// Query parameters
80
- pub params: Value,
81
- }
82
-
83
- impl CapabilityQuery {
84
- pub fn new(query_type: String, params: Value) -> Self {
85
- Self { query_type, params }
86
- }
87
- }
88
-
89
- /// Checkpoint for capability progress tracking
90
- #[derive(Debug, Clone, Serialize, Deserialize)]
91
- pub struct CapabilityCheckpoint {
92
- /// The capability ID
93
- pub capability_id: CapabilityId,
94
- /// Last processed instance ID
95
- pub last_processed_instance_id: String,
96
- /// Last processed sequence number
97
- pub last_processed_sequence: u64,
98
- /// Current lifecycle state
99
- pub lifecycle_state: CapabilityLifecycleState,
100
- /// Timestamp of last checkpoint (ms since UNIX epoch)
101
- pub checkpoint_ms: u128,
102
- /// Capability version
103
- pub version: u32,
104
- }
105
-
106
- impl CapabilityCheckpoint {
107
- pub fn new(capability_id: CapabilityId, instance_id: String) -> Self {
108
- Self {
109
- capability_id,
110
- last_processed_instance_id: instance_id,
111
- last_processed_sequence: 0,
112
- lifecycle_state: CapabilityLifecycleState::Registered,
113
- checkpoint_ms: crate::now_ms(),
114
- version: 1,
115
- }
116
- }
117
-
118
- /// Update checkpoint with new processed position
119
- pub fn update_position(&mut self, instance_id: String, sequence: u64) {
120
- self.last_processed_instance_id = instance_id;
121
- self.last_processed_sequence = sequence;
122
- self.checkpoint_ms = crate::now_ms();
123
- }
124
-
125
- /// Set lifecycle state
126
- pub fn set_state(&mut self, state: CapabilityLifecycleState) {
127
- self.lifecycle_state = state;
128
- self.checkpoint_ms = crate::now_ms();
129
- }
130
- }
131
-
132
- /// Result of processing an operation through a capability
133
- #[derive(Debug, Clone, Serialize, Deserialize)]
134
- pub struct CapabilityOperationResult {
135
- /// Whether the operation was successfully processed
136
- pub success: bool,
137
- /// Optional error message
138
- pub error: Option<String>,
139
- /// Optional result data
140
- pub result: Option<Value>,
141
- /// Whether this capability produced derived state
142
- pub produced_derived_state: bool,
143
- }
144
-
145
- impl CapabilityOperationResult {
146
- pub fn success() -> Self {
147
- Self {
148
- success: true,
149
- error: None,
150
- result: None,
151
- produced_derived_state: false,
152
- }
153
- }
154
-
155
- pub fn with_derived_state(result: Value) -> Self {
156
- Self {
157
- success: true,
158
- error: None,
159
- result: Some(result),
160
- produced_derived_state: true,
161
- }
162
- }
163
-
164
- pub fn error(msg: String) -> Self {
165
- Self {
166
- success: false,
167
- error: Some(msg),
168
- result: None,
169
- produced_derived_state: false,
170
- }
171
- }
172
- }
173
-
174
- /// Result of a capability query
175
- #[derive(Debug, Clone, Serialize, Deserialize)]
176
- pub struct CapabilityQueryResult {
177
- /// Whether the query succeeded
178
- pub success: bool,
179
- /// Query results
180
- pub results: Vec<Value>,
181
- /// Optional error message
182
- pub error: Option<String>,
183
- }
184
-
185
- impl CapabilityQueryResult {
186
- pub fn success(results: Vec<Value>) -> Self {
187
- Self {
188
- success: true,
189
- results,
190
- error: None,
191
- }
192
- }
193
-
194
- pub fn empty() -> Self {
195
- Self {
196
- success: true,
197
- results: Vec::new(),
198
- error: None,
199
- }
200
- }
201
-
202
- pub fn error(msg: String) -> Self {
203
- Self {
204
- success: false,
205
- results: Vec::new(),
206
- error: Some(msg),
207
- }
208
- }
209
- }
210
-
211
- /// Access model for capability security
212
- #[derive(Debug, Clone, Serialize, Deserialize)]
213
- pub struct CapabilityAccessModel {
214
- /// Collections this capability can read from
215
- pub reads: Vec<String>,
216
- /// Collections this capability can write to
217
- pub writes: Vec<String>,
218
- /// External systems this capability can execute
219
- pub executes: Vec<String>,
220
- }
221
-
222
- impl CapabilityAccessModel {
223
- pub fn new(reads: Vec<String>, writes: Vec<String>, executes: Vec<String>) -> Self {
224
- Self {
225
- reads,
226
- writes,
227
- executes,
228
- }
229
- }
230
-
231
- /// Check if capability can read from collection
232
- pub fn can_read(&self, collection: &str) -> bool {
233
- self.reads.contains(&collection.to_string()) || self.reads.iter().any(|r| r == "*")
234
- }
235
-
236
- /// Check if capability can write to collection
237
- pub fn can_write(&self, collection: &str) -> bool {
238
- self.writes.contains(&collection.to_string()) || self.writes.iter().any(|w| w == "*")
239
- }
240
-
241
- /// Check if capability can execute external system
242
- pub fn can_execute(&self, system: &str) -> bool {
243
- self.executes.contains(&system.to_string()) || self.executes.iter().any(|e| e == "*")
244
- }
245
- }
246
-
247
- /// Capability metadata and configuration
248
- #[derive(Debug, Clone, Serialize, Deserialize)]
249
- pub struct CapabilityMetadata {
250
- pub id: CapabilityId,
251
- pub name: String,
252
- pub description: String,
253
- pub role: CapabilityRole,
254
- pub access_model: CapabilityAccessModel,
255
- pub version: u32,
256
- pub created_ms: u128,
257
- }
258
-
259
- impl CapabilityMetadata {
260
- pub fn new(
261
- id: CapabilityId,
262
- name: String,
263
- description: String,
264
- role: CapabilityRole,
265
- access_model: CapabilityAccessModel,
266
- ) -> Self {
267
- Self {
268
- id,
269
- name,
270
- description,
271
- role,
272
- access_model,
273
- version: 1,
274
- created_ms: crate::now_ms(),
275
- }
276
- }
277
- }
278
-
279
- /// Capability registry - tracks all capabilities
280
- #[derive(Debug, Clone, Serialize, Deserialize)]
281
- pub struct CapabilityRegistry {
282
- /// All capabilities by ID
283
- #[serde(default)]
284
- capabilities: HashMap<CapabilityId, CapabilityMetadata>,
285
- /// Checkpoints by capability ID
286
- #[serde(default)]
287
- checkpoints: HashMap<CapabilityId, CapabilityCheckpoint>,
288
- }
289
-
290
- impl CapabilityRegistry {
291
- pub fn new() -> Self {
292
- Self {
293
- capabilities: HashMap::new(),
294
- checkpoints: HashMap::new(),
295
- }
296
- }
297
-
298
- /// Register a new capability
299
- pub fn register(&mut self, metadata: CapabilityMetadata) -> crate::Result<()> {
300
- let id = metadata.id.clone();
301
- if self.capabilities.contains_key(&id) {
302
- return Err(crate::FlowError::CapabilityError(
303
- "Capability already registered".to_string(),
304
- ));
305
- }
306
- let checkpoint = CapabilityCheckpoint::new(id.clone(), String::new());
307
- self.capabilities.insert(id.clone(), metadata);
308
- self.checkpoints.insert(id, checkpoint);
309
- Ok(())
310
- }
311
-
312
- /// Get capability metadata
313
- pub fn get(&self, id: &CapabilityId) -> Option<&CapabilityMetadata> {
314
- self.capabilities.get(id)
315
- }
316
-
317
- /// Get capability checkpoint
318
- pub fn get_checkpoint(&self, id: &CapabilityId) -> Option<&CapabilityCheckpoint> {
319
- self.checkpoints.get(id)
320
- }
321
-
322
- /// Update capability checkpoint
323
- pub fn update_checkpoint(&mut self, checkpoint: CapabilityCheckpoint) {
324
- self.checkpoints
325
- .insert(checkpoint.capability_id.clone(), checkpoint);
326
- }
327
-
328
- /// List all capabilities
329
- pub fn list(&self) -> Vec<&CapabilityMetadata> {
330
- self.capabilities.values().collect()
331
- }
332
-
333
- /// Remove a capability
334
- pub fn remove(&mut self, id: &CapabilityId) -> Option<CapabilityMetadata> {
335
- self.checkpoints.remove(id);
336
- self.capabilities.remove(id)
337
- }
338
- }
339
-
340
- impl Default for CapabilityRegistry {
341
- fn default() -> Self {
342
- Self::new()
343
- }
344
- }
345
-
346
- /// Trait for implementing capabilities
347
- /// This is the core contract for extending FeltDB with specialized behavior
348
- pub trait FlowCapability: Send + Sync {
349
- /// Get the capability ID
350
- fn id(&self) -> CapabilityId;
351
-
352
- /// Get the capability metadata
353
- fn metadata(&self) -> CapabilityMetadata;
354
-
355
- /// Initialize the capability (called on registration)
356
- fn initialize(&mut self, context: &CapabilityContext) -> crate::Result<()>;
357
-
358
- /// Process an operation - maintain derived state
359
- fn on_operation(
360
- &mut self,
361
- operation: &Operation,
362
- context: &CapabilityContext,
363
- ) -> crate::Result<CapabilityOperationResult>;
364
-
365
- /// Query the capability's derived state
366
- fn query(
367
- &self,
368
- query: &CapabilityQuery,
369
- context: &CapabilityContext,
370
- ) -> crate::Result<CapabilityQueryResult>;
371
-
372
- /// Rebuild the capability's derived state from scratch
373
- fn rebuild(
374
- &mut self,
375
- operations: &[Operation],
376
- context: &CapabilityContext,
377
- ) -> crate::Result<()>;
378
-
379
- /// Pause the capability
380
- fn pause(&mut self) -> crate::Result<()> {
381
- Ok(())
382
- }
383
-
384
- /// Resume the capability
385
- fn resume(&mut self) -> crate::Result<()> {
386
- Ok(())
387
- }
388
-
389
- /// Check if the capability is ready (fully caught up)
390
- fn is_ready(&self) -> bool {
391
- true
392
- }
393
- }
394
-
395
- /// Reference to a capability with namespace and version
396
- /// Canonical form: flow://capability/namespace:name@version
397
- #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
398
- pub struct CapabilityRef {
399
- /// Namespace (e.g., "docs", "images")
400
- pub namespace: String,
401
- /// Capability name (e.g., "vector-search", "image-analysis")
402
- pub capability: String,
403
- /// Capability version
404
- pub version: u32,
405
- }
406
-
407
- impl CapabilityRef {
408
- /// Create a new capability reference
409
- pub fn new(namespace: String, capability: String, version: u32) -> Self {
410
- Self {
411
- namespace,
412
- capability,
413
- version,
414
- }
415
- }
416
-
417
- /// Get canonical form for serialization
418
- pub fn canonical(&self) -> String {
419
- format!(
420
- "flow://capability/{}/{}@{}",
421
- self.namespace, self.capability, self.version
422
- )
423
- }
424
-
425
- /// Parse from canonical form
426
- pub fn from_canonical(canonical: &str) -> crate::Result<Self> {
427
- if !canonical.starts_with("flow://capability/") {
428
- return Err(crate::FlowError::CapabilityError(
429
- "Invalid capability reference format".to_string(),
430
- ));
431
- }
432
-
433
- let rest = &canonical[18..]; // Skip "flow://capability/"
434
- let parts: Vec<&str> = rest.split('/').collect();
435
- if parts.len() != 2 {
436
- return Err(crate::FlowError::CapabilityError(
437
- "Invalid capability reference format".to_string(),
438
- ));
439
- }
440
-
441
- let namespace = parts[0].to_string();
442
- let cap_parts: Vec<&str> = parts[1].split('@').collect();
443
- if cap_parts.len() != 2 {
444
- return Err(crate::FlowError::CapabilityError(
445
- "Invalid capability reference format".to_string(),
446
- ));
447
- }
448
-
449
- let capability = cap_parts[0].to_string();
450
- let version = cap_parts[1]
451
- .parse::<u32>()
452
- .map_err(|_| crate::FlowError::CapabilityError("Invalid version number".to_string()))?;
453
-
454
- Ok(Self::new(namespace, capability, version))
455
- }
456
- }
457
-
458
- impl fmt::Display for CapabilityRef {
459
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
460
- write!(f, "{}", self.canonical())
461
- }
462
- }
463
-
464
- /// Represents a required state for a capability to execute
465
- #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
466
- pub struct StateRequirement {
467
- /// Namespace containing the required state
468
- pub namespace: String,
469
- /// Minimum version required (0 means any)
470
- pub min_version: u64,
471
- }
472
-
473
- impl StateRequirement {
474
- pub fn new(namespace: String, min_version: u64) -> Self {
475
- Self {
476
- namespace,
477
- min_version,
478
- }
479
- }
480
- }
481
-
482
- /// Requirements for a capability to execute
483
- #[derive(Debug, Clone, Serialize, Deserialize)]
484
- pub struct CapabilityRequirements {
485
- /// Required namespaces and minimum versions
486
- pub required_state: Vec<StateRequirement>,
487
- /// Maximum acceptable latency for state (ms)
488
- pub max_state_latency_ms: Option<u64>,
489
- /// Whether execution requires single-owner semantics
490
- pub requires_ownership: bool,
491
- }
492
-
493
- impl CapabilityRequirements {
494
- pub fn new() -> Self {
495
- Self {
496
- required_state: Vec::new(),
497
- max_state_latency_ms: None,
498
- requires_ownership: false,
499
- }
500
- }
501
-
502
- pub fn with_required_state(mut self, requirement: StateRequirement) -> Self {
503
- self.required_state.push(requirement);
504
- self
505
- }
506
-
507
- pub fn with_max_latency(mut self, latency_ms: u64) -> Self {
508
- self.max_state_latency_ms = Some(latency_ms);
509
- self
510
- }
511
-
512
- pub fn with_ownership_requirement(mut self, requires: bool) -> Self {
513
- self.requires_ownership = requires;
514
- self
515
- }
516
- }
517
-
518
- impl Default for CapabilityRequirements {
519
- fn default() -> Self {
520
- Self::new()
521
- }
522
- }
523
-
524
- /// Advertises a capability at a specific peer with its requirements
525
- #[derive(Debug, Clone, Serialize, Deserialize)]
526
- pub struct DistributedCapabilityAdvertisement {
527
- /// The capability reference
528
- pub capability_ref: CapabilityRef,
529
- /// Peer ID providing this capability
530
- pub peer_id: String,
531
- /// Requirements for this capability
532
- pub requirements: CapabilityRequirements,
533
- /// Timestamp of advertisement
534
- pub advertised_ms: u128,
535
- }
536
-
537
- impl DistributedCapabilityAdvertisement {
538
- pub fn new(capability_ref: CapabilityRef, peer_id: String) -> Self {
539
- Self {
540
- capability_ref,
541
- peer_id,
542
- requirements: CapabilityRequirements::new(),
543
- advertised_ms: crate::now_ms(),
544
- }
545
- }
546
-
547
- pub fn with_requirements(mut self, requirements: CapabilityRequirements) -> Self {
548
- self.requirements = requirements;
549
- self
550
- }
551
- }
552
-
553
- /// Context for executing a capability (local or remote)
554
- #[derive(Debug, Clone, Serialize, Deserialize)]
555
- pub struct CapabilityExecutionContext {
556
- /// Unique execution ID
557
- pub execution_id: String,
558
- /// The capability being executed
559
- pub capability_ref: CapabilityRef,
560
- /// References to input data (instead of serialized payloads)
561
- pub input_refs: Vec<String>,
562
- /// Required state version for execution
563
- pub required_state_version: u64,
564
- /// Requester instance/peer ID
565
- pub requester: String,
566
- /// Timestamp when execution was requested
567
- pub requested_ms: u128,
568
- }
569
-
570
- impl CapabilityExecutionContext {
571
- pub fn new(execution_id: String, capability_ref: CapabilityRef, requester: String) -> Self {
572
- Self {
573
- execution_id,
574
- capability_ref,
575
- input_refs: Vec::new(),
576
- required_state_version: 0,
577
- requester,
578
- requested_ms: crate::now_ms(),
579
- }
580
- }
581
-
582
- pub fn with_input_ref(mut self, input_ref: String) -> Self {
583
- self.input_refs.push(input_ref);
584
- self
585
- }
586
-
587
- pub fn with_required_state_version(mut self, version: u64) -> Self {
588
- self.required_state_version = version;
589
- self
590
- }
591
- }
592
-
593
- /// Reference to an execution result with provenance
594
- #[derive(Debug, Clone, Serialize, Deserialize)]
595
- pub struct ExecutionRef {
596
- /// Unique execution ID
597
- pub execution_id: String,
598
- /// The capability that was executed
599
- pub capability_ref: CapabilityRef,
600
- /// Peer that executed the capability
601
- pub provider_peer: String,
602
- /// Input references used
603
- pub input_refs: Vec<String>,
604
- /// State version at time of execution
605
- pub input_state_version: u64,
606
- /// Content identity of the result
607
- pub result_content_identity: String,
608
- /// Operation that recorded this result
609
- pub created_operation: Option<String>,
610
- }
611
-
612
- impl ExecutionRef {
613
- pub fn new(execution_id: String, capability_ref: CapabilityRef, provider_peer: String) -> Self {
614
- Self {
615
- execution_id,
616
- capability_ref,
617
- provider_peer,
618
- input_refs: Vec::new(),
619
- input_state_version: 0,
620
- result_content_identity: String::new(),
621
- created_operation: None,
622
- }
623
- }
624
- }
625
-
626
- /// Result of a capability execution with full provenance
627
- #[derive(Debug, Clone, Serialize, Deserialize)]
628
- pub struct CapabilityExecutionResult {
629
- /// Reference to the execution
630
- pub execution_ref: ExecutionRef,
631
- /// The actual result data
632
- pub result: Value,
633
- /// Timestamp when execution completed
634
- pub completed_ms: u128,
635
- /// Any error that occurred
636
- pub error: Option<String>,
637
- }
638
-
639
- impl CapabilityExecutionResult {
640
- pub fn success(execution_ref: ExecutionRef, result: Value) -> Self {
641
- Self {
642
- execution_ref,
643
- result,
644
- completed_ms: crate::now_ms(),
645
- error: None,
646
- }
647
- }
648
-
649
- pub fn error(execution_ref: ExecutionRef, error: String) -> Self {
650
- Self {
651
- execution_ref,
652
- result: Value::Null,
653
- completed_ms: crate::now_ms(),
654
- error: Some(error),
655
- }
656
- }
657
- }
658
-
659
- /// Resolver for capabilities - routes to appropriate provider
660
- pub struct CapabilityResolver {
661
- /// Registered capabilities by ref
662
- capabilities: HashMap<String, DistributedCapabilityAdvertisement>,
663
- }
664
-
665
- impl CapabilityResolver {
666
- pub fn new() -> Self {
667
- Self {
668
- capabilities: HashMap::new(),
669
- }
670
- }
671
-
672
- /// Register a capability advertisement
673
- pub fn register(&mut self, ad: DistributedCapabilityAdvertisement) {
674
- self.capabilities.insert(ad.capability_ref.canonical(), ad);
675
- }
676
-
677
- /// Find a provider for a capability
678
- pub fn resolve(&self, cap_ref: &CapabilityRef) -> Option<&DistributedCapabilityAdvertisement> {
679
- self.capabilities.get(&cap_ref.canonical())
680
- }
681
-
682
- /// Find all providers for a capability (by name only)
683
- pub fn resolve_all(
684
- &self,
685
- namespace: &str,
686
- capability: &str,
687
- ) -> Vec<&DistributedCapabilityAdvertisement> {
688
- self.capabilities
689
- .values()
690
- .filter(|ad| {
691
- ad.capability_ref.namespace == namespace
692
- && ad.capability_ref.capability == capability
693
- })
694
- .collect()
695
- }
696
- }
697
-
698
- impl Default for CapabilityResolver {
699
- fn default() -> Self {
700
- Self::new()
701
- }
702
- }
703
-
704
- #[cfg(test)]
705
- mod tests {
706
- use super::*;
707
-
708
- #[test]
709
- fn test_capability_id_creation() {
710
- let id = CapabilityId::new("search".to_string());
711
- assert_eq!(id.0, "search");
712
- }
713
-
714
- #[test]
715
- fn test_capability_checkpoint() {
716
- let mut checkpoint = CapabilityCheckpoint::new(
717
- CapabilityId::new("search".to_string()),
718
- "instance-1".to_string(),
719
- );
720
- assert_eq!(checkpoint.last_processed_sequence, 0);
721
-
722
- checkpoint.update_position("instance-1".to_string(), 100);
723
- assert_eq!(checkpoint.last_processed_sequence, 100);
724
- }
725
-
726
- #[test]
727
- fn test_capability_access_model() {
728
- let access = CapabilityAccessModel::new(
729
- vec!["docs".to_string()],
730
- vec!["docs.search".to_string()],
731
- vec!["embedding-api".to_string()],
732
- );
733
-
734
- assert!(access.can_read("docs"));
735
- assert!(!access.can_read("users"));
736
- assert!(access.can_write("docs.search"));
737
- assert!(access.can_execute("embedding-api"));
738
- }
739
-
740
- #[test]
741
- fn test_capability_access_wildcard() {
742
- let access =
743
- CapabilityAccessModel::new(vec!["*".to_string()], vec!["*".to_string()], vec![]);
744
-
745
- assert!(access.can_read("anything"));
746
- assert!(access.can_write("anything"));
747
- }
748
-
749
- #[test]
750
- fn test_capability_registry() {
751
- let mut registry = CapabilityRegistry::new();
752
- let metadata = CapabilityMetadata::new(
753
- CapabilityId::new("search".to_string()),
754
- "Search Capability".to_string(),
755
- "Full-text search".to_string(),
756
- CapabilityRole::Projection,
757
- CapabilityAccessModel::new(
758
- vec!["docs".to_string()],
759
- vec!["docs.search".to_string()],
760
- vec![],
761
- ),
762
- );
763
-
764
- registry.register(metadata).unwrap();
765
- let cap_id = CapabilityId::new("search".to_string());
766
- assert!(registry.get(&cap_id).is_some());
767
- assert!(registry.get_checkpoint(&cap_id).is_some());
768
- }
769
-
770
- #[test]
771
- fn test_capability_ref_creation_and_canonical() {
772
- let cap_ref = CapabilityRef::new("docs".to_string(), "vector-search".to_string(), 1);
773
- assert_eq!(cap_ref.namespace, "docs");
774
- assert_eq!(cap_ref.capability, "vector-search");
775
- assert_eq!(cap_ref.version, 1);
776
- assert_eq!(
777
- cap_ref.canonical(),
778
- "flow://capability/docs/vector-search@1"
779
- );
780
- }
781
-
782
- #[test]
783
- fn test_capability_ref_parse_canonical() {
784
- let canonical = "flow://capability/docs/vector-search@1";
785
- let cap_ref = CapabilityRef::from_canonical(canonical).unwrap();
786
- assert_eq!(cap_ref.namespace, "docs");
787
- assert_eq!(cap_ref.capability, "vector-search");
788
- assert_eq!(cap_ref.version, 1);
789
- }
790
-
791
- #[test]
792
- fn test_capability_ref_display() {
793
- let cap_ref = CapabilityRef::new("images".to_string(), "image-analysis".to_string(), 2);
794
- assert_eq!(
795
- cap_ref.to_string(),
796
- "flow://capability/images/image-analysis@2"
797
- );
798
- }
799
-
800
- #[test]
801
- fn test_state_requirement_creation() {
802
- let req = StateRequirement::new("docs".to_string(), 847);
803
- assert_eq!(req.namespace, "docs");
804
- assert_eq!(req.min_version, 847);
805
- }
806
-
807
- #[test]
808
- fn test_capability_requirements_builder() {
809
- let reqs = CapabilityRequirements::new()
810
- .with_required_state(StateRequirement::new("docs".to_string(), 847))
811
- .with_max_latency(5000)
812
- .with_ownership_requirement(true);
813
-
814
- assert_eq!(reqs.required_state.len(), 1);
815
- assert_eq!(reqs.max_state_latency_ms, Some(5000));
816
- assert!(reqs.requires_ownership);
817
- }
818
-
819
- #[test]
820
- fn test_distributed_capability_advertisement() {
821
- let cap_ref = CapabilityRef::new("docs".to_string(), "vector-search".to_string(), 1);
822
- let ad = DistributedCapabilityAdvertisement::new(cap_ref.clone(), "peer-b".to_string())
823
- .with_requirements(
824
- CapabilityRequirements::new()
825
- .with_required_state(StateRequirement::new("docs".to_string(), 847)),
826
- );
827
-
828
- assert_eq!(ad.capability_ref, cap_ref);
829
- assert_eq!(ad.peer_id, "peer-b");
830
- assert_eq!(ad.requirements.required_state.len(), 1);
831
- }
832
-
833
- #[test]
834
- fn test_capability_execution_context() {
835
- let cap_ref = CapabilityRef::new("docs".to_string(), "vector-search".to_string(), 1);
836
- let ctx = CapabilityExecutionContext::new(
837
- "exec-123".to_string(),
838
- cap_ref.clone(),
839
- "requester".to_string(),
840
- )
841
- .with_input_ref("flow://docs#123".to_string())
842
- .with_required_state_version(851);
843
-
844
- assert_eq!(ctx.execution_id, "exec-123");
845
- assert_eq!(ctx.capability_ref, cap_ref);
846
- assert_eq!(ctx.input_refs.len(), 1);
847
- assert_eq!(ctx.required_state_version, 851);
848
- }
849
-
850
- #[test]
851
- fn test_execution_ref_creation() {
852
- let cap_ref = CapabilityRef::new("docs".to_string(), "vector-search".to_string(), 1);
853
- let exec_ref = ExecutionRef::new(
854
- "exec-123".to_string(),
855
- cap_ref.clone(),
856
- "peer-b".to_string(),
857
- );
858
-
859
- assert_eq!(exec_ref.execution_id, "exec-123");
860
- assert_eq!(exec_ref.capability_ref, cap_ref);
861
- assert_eq!(exec_ref.provider_peer, "peer-b");
862
- }
863
-
864
- #[test]
865
- fn test_capability_execution_result_success() {
866
- let cap_ref = CapabilityRef::new("docs".to_string(), "vector-search".to_string(), 1);
867
- let exec_ref = ExecutionRef::new("exec-123".to_string(), cap_ref, "peer-b".to_string());
868
- let result = serde_json::json!({"results": [1, 2, 3]});
869
-
870
- let exec_result = CapabilityExecutionResult::success(exec_ref.clone(), result.clone());
871
- assert!(exec_result.error.is_none());
872
- assert_eq!(exec_result.result, result);
873
- }
874
-
875
- #[test]
876
- fn test_capability_resolver_registration() {
877
- let mut resolver = CapabilityResolver::new();
878
- let cap_ref = CapabilityRef::new("docs".to_string(), "vector-search".to_string(), 1);
879
- let ad = DistributedCapabilityAdvertisement::new(cap_ref.clone(), "peer-b".to_string());
880
-
881
- resolver.register(ad);
882
-
883
- let resolved = resolver.resolve(&cap_ref);
884
- assert!(resolved.is_some());
885
- assert_eq!(resolved.unwrap().peer_id, "peer-b");
886
- }
887
-
888
- #[test]
889
- fn test_capability_resolver_resolve_all() {
890
- let mut resolver = CapabilityResolver::new();
891
-
892
- let cap_ref_v1 = CapabilityRef::new("docs".to_string(), "vector-search".to_string(), 1);
893
- let ad1 = DistributedCapabilityAdvertisement::new(cap_ref_v1, "peer-a".to_string());
894
- resolver.register(ad1);
895
-
896
- let cap_ref_v2 = CapabilityRef::new("docs".to_string(), "vector-search".to_string(), 2);
897
- let ad2 = DistributedCapabilityAdvertisement::new(cap_ref_v2, "peer-b".to_string());
898
- resolver.register(ad2);
899
-
900
- let all = resolver.resolve_all("docs", "vector-search");
901
- assert_eq!(all.len(), 2);
902
- }
903
- }