domainforge 0.13.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.
- package/.cargo/config.toml +6 -0
- package/.claude/settings.local.json +18 -0
- package/.coderabbit.yml +43 -0
- package/.codex/skills/release-management/SKILL.md +151 -0
- package/.codex/skills/release-management/agents/openai.yaml +4 -0
- package/.github/actions/decrypt-secrets/action.yml +121 -0
- package/.github/agents/Coder.agent.md +97 -0
- package/.github/agents/DeepResearch.agent.md +61 -0
- package/.github/chatmodes/tdd.vibepro.chatmode.md +1183 -0
- package/.github/copilot-instructions.md +13 -0
- package/.github/dependabot.yml +68 -0
- package/.github/workflows/README.md +165 -0
- package/.github/workflows/ci.yml +335 -0
- package/.github/workflows/dependabot-automerge.yml +114 -0
- package/.github/workflows/dependency-review.yml +27 -0
- package/.github/workflows/deploy.yml +87 -0
- package/.github/workflows/prepare-release.yml +168 -0
- package/.github/workflows/release-crates.yml +42 -0
- package/.github/workflows/release-npm.yml +137 -0
- package/.github/workflows/release-please.yml +29 -0
- package/.github/workflows/release-pypi.yml +96 -0
- package/.gitkeep +1 -0
- package/.release-please-manifest.json +5 -0
- package/.sea-registry.toml +10 -0
- package/.serena/project.yml +133 -0
- package/.sops.yaml +10 -0
- package/AGENTS.md +216 -0
- package/CHANGELOG.md +400 -0
- package/CLAUDE.md +62 -0
- package/CONTRIBUTING.md +323 -0
- package/Cargo.lock +3612 -0
- package/Cargo.toml +12 -0
- package/LICENSE +201 -0
- package/README.md +660 -0
- package/README_PYTHON.md +256 -0
- package/README_TYPESCRIPT.md +305 -0
- package/README_WASM.md +329 -0
- package/RELEASE_NOTES.md +41 -0
- package/bun.lock +378 -0
- package/bunfig.toml +11 -0
- package/check_output.txt +83 -0
- package/clippy_output.txt +80 -0
- package/commitlint.config.cjs +8 -0
- package/deny.toml +42 -0
- package/devbox.json +14 -0
- package/devbox.lock +76 -0
- package/docs/RELEASE_PROCESS.md +360 -0
- package/docs/diagnostics.md +161 -0
- package/docs/doc_guidelines.md +53 -0
- package/docs/explanations/README.md +21 -0
- package/docs/explanations/architecture-overview.md +109 -0
- package/docs/explanations/cross-language-binding-strategy.md +68 -0
- package/docs/explanations/graph-store-design.md +47 -0
- package/docs/explanations/performance-benchmarks.md +63 -0
- package/docs/explanations/policy-evaluation-logic.md +106 -0
- package/docs/explanations/semantic-modeling-concepts.md +109 -0
- package/docs/explanations/three-valued-logic.md +66 -0
- package/docs/explanations/versioning-strategy.md +45 -0
- package/docs/governance.md +168 -0
- package/docs/how-tos/README.md +46 -0
- package/docs/how-tos/ci-cd-validation.md +93 -0
- package/docs/how-tos/create-custom-units.md +125 -0
- package/docs/how-tos/define-policies.md +119 -0
- package/docs/how-tos/export-to-calm.md +110 -0
- package/docs/how-tos/export-to-protobuf.md +312 -0
- package/docs/how-tos/extend-grammar.md +133 -0
- package/docs/how-tos/generate-rdf-turtle.md +106 -0
- package/docs/how-tos/import-from-calm.md +114 -0
- package/docs/how-tos/import-from-sbvr.md +249 -0
- package/docs/how-tos/install-cli.md +126 -0
- package/docs/how-tos/parse-sea-files.md +132 -0
- package/docs/how-tos/policy-evaluation-modes.md +30 -0
- package/docs/how-tos/run-cross-language-tests.md +115 -0
- package/docs/how-tos/troubleshoot-napi-builds.md +55 -0
- package/docs/how-tos/use-modules-imports.md +285 -0
- package/docs/index.md +13 -0
- package/docs/plans/canonical-normalizer.md +121 -0
- package/docs/plans/cd_improvement.md +112 -0
- package/docs/plans/cli-ast.md +29 -0
- package/docs/plans/expression-bindings-and-normalizer-integration.md +174 -0
- package/docs/plans/protobuf_advanced_features_plan.md +597 -0
- package/docs/plans/protobuf_plan.yml +525 -0
- package/docs/plans/refactor_dsl_architecture.md +131 -0
- package/docs/plans/release-plan.md +163 -0
- package/docs/plans/sea_fmt_implementation_plan.md +516 -0
- package/docs/playbooks/README.md +18 -0
- package/docs/playbooks/adding-new-primitive.md +68 -0
- package/docs/playbooks/debugging-parser-failures.md +42 -0
- package/docs/playbooks/local-release-preparation.md +139 -0
- package/docs/playbooks/migrating-schema-versions.md +43 -0
- package/docs/playbooks/onboarding-contributors.md +64 -0
- package/docs/playbooks/releasing-beta.md +86 -0
- package/docs/playbooks/secret-management.md +64 -0
- package/docs/reference/README.md +199 -0
- package/docs/reference/ast-json-api.md +427 -0
- package/docs/reference/calm-mapping.md +519 -0
- package/docs/reference/cli-commands.md +588 -0
- package/docs/reference/configuration.md +202 -0
- package/docs/reference/error-codes.md +664 -0
- package/docs/reference/generated-artifacts-policy.md +53 -0
- package/docs/reference/grammar-spec.md +255 -0
- package/docs/reference/primitives-api.md +317 -0
- package/docs/reference/protobuf-api.md +426 -0
- package/docs/reference/python-api.md +485 -0
- package/docs/reference/registry.md +50 -0
- package/docs/reference/sea-dsl-ai-cheatsheet.yaml +913 -0
- package/docs/reference/security-model.md +74 -0
- package/docs/reference/typescript-api.md +508 -0
- package/docs/reference/wasm-api.md +420 -0
- package/docs/semantic-pack-review.md +144 -0
- package/docs/semantic-pack-signing.md +234 -0
- package/docs/semantic-packs.md +284 -0
- package/docs/specs/ADR-001-sea-dsl-semantic-source-of-truth.md +33 -0
- package/docs/specs/ADR-002-projection-first-class-construct.md +50 -0
- package/docs/specs/ADR-003-protobuf-projection-target.md +51 -0
- package/docs/specs/ADR-004-projection-compatibility-semantics.md +57 -0
- package/docs/specs/ADR-005-multi-language-support-strategy.md +112 -0
- package/docs/specs/ADR-006-error-handling-strategy.md +115 -0
- package/docs/specs/ADR-007-policy-evaluation-engine.md +95 -0
- package/docs/specs/ADR-008-knowledge-graph-integration.md +90 -0
- package/docs/specs/ADR-009-module-resolution-strategy.md +115 -0
- package/docs/specs/ADR-010-unit-system.md +106 -0
- package/docs/specs/PRD-001-sea-projection-framework.md +155 -0
- package/docs/specs/PRD-002-sea-cli-tooling.md +169 -0
- package/docs/specs/PRD-003-dsl-core-capabilities.md +275 -0
- package/docs/specs/README.md +62 -0
- package/docs/specs/SDS-001-protobuf-projection-engine.md +451 -0
- package/docs/specs/SDS-002-sea-core-architecture.md +268 -0
- package/docs/specs/SDS-003-parser-semantic-graph.md +377 -0
- package/docs/specs/SDS-004-policy-engine-design.md +362 -0
- package/docs/specs/SDS-005-knowledge-graph-module.md +364 -0
- package/docs/specs/SDS-006-calm-integration.md +367 -0
- package/docs/specs/SDS-007-sbvr-import.md +347 -0
- package/docs/templates/template_explanation.md +14 -0
- package/docs/templates/template_howto.md +21 -0
- package/docs/templates/template_playbook.md +21 -0
- package/docs/templates/template_reference.md +17 -0
- package/docs/templates/template_tutorial.md +24 -0
- package/docs/tutorials/README.md +12 -0
- package/docs/tutorials/first-sea-model.md +85 -0
- package/docs/tutorials/getting-started.md +98 -0
- package/docs/tutorials/python-binding-quickstart.md +107 -0
- package/docs/tutorials/typescript-binding-quickstart.md +91 -0
- package/docs/tutorials/wasm-in-browser.md +75 -0
- package/domainforge-core/CHANGELOG.md +138 -0
- package/domainforge-core/Cargo.toml +101 -0
- package/domainforge-core/MIGRATING.md +32 -0
- package/domainforge-core/README.md +197 -0
- package/domainforge-core/benchmark_results.txt +51 -0
- package/domainforge-core/build.rs +6 -0
- package/domainforge-core/deny.toml +31 -0
- package/domainforge-core/docs/specs/projections/sbvr_kg_mapping.md +43 -0
- package/domainforge-core/examples/basic.sea +7 -0
- package/domainforge-core/examples/cli/import_export_workflow.sh +38 -0
- package/domainforge-core/examples/cli/validate_example.sh +30 -0
- package/domainforge-core/examples/evolution_semantics.sea +31 -0
- package/domainforge-core/examples/parser_demo.rs +203 -0
- package/domainforge-core/grammar/sea.pest +408 -0
- package/domainforge-core/schemas/calm-v1.schema.json +170 -0
- package/domainforge-core/schemas/shacl/sea_shapes.ttl +19 -0
- package/domainforge-core/src/authority/compiler.rs +309 -0
- package/domainforge-core/src/authority/environment.rs +203 -0
- package/domainforge-core/src/authority/error.rs +164 -0
- package/domainforge-core/src/authority/fact_resolver.rs +224 -0
- package/domainforge-core/src/authority/mod.rs +25 -0
- package/domainforge-core/src/authority/pack.rs +133 -0
- package/domainforge-core/src/authority/policy.rs +224 -0
- package/domainforge-core/src/authority/resolver.rs +446 -0
- package/domainforge-core/src/authority/trace.rs +217 -0
- package/domainforge-core/src/authority/transform.rs +168 -0
- package/domainforge-core/src/authority/types.rs +617 -0
- package/domainforge-core/src/bin/domainforge.rs +25 -0
- package/domainforge-core/src/calm/export.rs +538 -0
- package/domainforge-core/src/calm/import.rs +1220 -0
- package/domainforge-core/src/calm/mod.rs +9 -0
- package/domainforge-core/src/calm/models.rs +108 -0
- package/domainforge-core/src/calm/sbvr_import.rs +9 -0
- package/domainforge-core/src/cli/authority.rs +149 -0
- package/domainforge-core/src/cli/format.rs +85 -0
- package/domainforge-core/src/cli/import.rs +133 -0
- package/domainforge-core/src/cli/mod.rs +64 -0
- package/domainforge-core/src/cli/normalize.rs +180 -0
- package/domainforge-core/src/cli/pack.rs +904 -0
- package/domainforge-core/src/cli/parse.rs +112 -0
- package/domainforge-core/src/cli/project.rs +294 -0
- package/domainforge-core/src/cli/registry.rs +41 -0
- package/domainforge-core/src/cli/test.rs +12 -0
- package/domainforge-core/src/cli/validate.rs +195 -0
- package/domainforge-core/src/cli/validate_kg.rs +80 -0
- package/domainforge-core/src/concept_id.rs +89 -0
- package/domainforge-core/src/error/diagnostics.rs +426 -0
- package/domainforge-core/src/error/fuzzy.rs +253 -0
- package/domainforge-core/src/error/mod.rs +13 -0
- package/domainforge-core/src/formatter/comments.rs +223 -0
- package/domainforge-core/src/formatter/config.rs +114 -0
- package/domainforge-core/src/formatter/mod.rs +22 -0
- package/domainforge-core/src/formatter/printer.rs +906 -0
- package/domainforge-core/src/graph/mod.rs +858 -0
- package/domainforge-core/src/graph/to_ast.rs +66 -0
- package/domainforge-core/src/kg.rs +1476 -0
- package/domainforge-core/src/kg_import.rs +251 -0
- package/domainforge-core/src/lib.rs +203 -0
- package/domainforge-core/src/module/mod.rs +1 -0
- package/domainforge-core/src/module/resolver.rs +260 -0
- package/domainforge-core/src/parser/ast.rs +2919 -0
- package/domainforge-core/src/parser/ast_convert.rs +494 -0
- package/domainforge-core/src/parser/ast_schema.rs +491 -0
- package/domainforge-core/src/parser/error.rs +291 -0
- package/domainforge-core/src/parser/lint.rs +39 -0
- package/domainforge-core/src/parser/mod.rs +193 -0
- package/domainforge-core/src/parser/printer.rs +702 -0
- package/domainforge-core/src/parser/profiles.rs +71 -0
- package/domainforge-core/src/parser/string_utils.rs +138 -0
- package/domainforge-core/src/patterns.rs +68 -0
- package/domainforge-core/src/policy/core.rs +1148 -0
- package/domainforge-core/src/policy/expression.rs +399 -0
- package/domainforge-core/src/policy/mod.rs +18 -0
- package/domainforge-core/src/policy/normalize.rs +1028 -0
- package/domainforge-core/src/policy/quantifier.rs +940 -0
- package/domainforge-core/src/policy/three_valued.rs +140 -0
- package/domainforge-core/src/policy/three_valued_microbench.rs +104 -0
- package/domainforge-core/src/policy/type_inference.rs +67 -0
- package/domainforge-core/src/policy/violation.rs +36 -0
- package/domainforge-core/src/primitives/concept_change.rs +61 -0
- package/domainforge-core/src/primitives/entity.rs +224 -0
- package/domainforge-core/src/primitives/flow.rs +111 -0
- package/domainforge-core/src/primitives/instance.rs +93 -0
- package/domainforge-core/src/primitives/mapping_contract.rs +50 -0
- package/domainforge-core/src/primitives/metric.rs +79 -0
- package/domainforge-core/src/primitives/mod.rs +25 -0
- package/domainforge-core/src/primitives/projection_contract.rs +50 -0
- package/domainforge-core/src/primitives/quantity.rs +56 -0
- package/domainforge-core/src/primitives/relation.rs +68 -0
- package/domainforge-core/src/primitives/resource.rs +237 -0
- package/domainforge-core/src/primitives/resource_instance.rs +88 -0
- package/domainforge-core/src/primitives/role.rs +49 -0
- package/domainforge-core/src/projection/buf.rs +404 -0
- package/domainforge-core/src/projection/contracts.rs +22 -0
- package/domainforge-core/src/projection/engine.rs +19 -0
- package/domainforge-core/src/projection/mod.rs +16 -0
- package/domainforge-core/src/projection/protobuf.rs +3331 -0
- package/domainforge-core/src/projection/registry.rs +43 -0
- package/domainforge-core/src/python/authority.rs +253 -0
- package/domainforge-core/src/python/error.rs +227 -0
- package/domainforge-core/src/python/formatter.rs +86 -0
- package/domainforge-core/src/python/graph.rs +366 -0
- package/domainforge-core/src/python/mod.rs +9 -0
- package/domainforge-core/src/python/policy.rs +651 -0
- package/domainforge-core/src/python/primitives.rs +796 -0
- package/domainforge-core/src/python/registry.rs +98 -0
- package/domainforge-core/src/python/semantic_pack.rs +619 -0
- package/domainforge-core/src/python/units.rs +96 -0
- package/domainforge-core/src/registry/mod.rs +432 -0
- package/domainforge-core/src/registry/tests.rs +210 -0
- package/domainforge-core/src/sbvr.rs +744 -0
- package/domainforge-core/src/semantic_pack/builder.rs +470 -0
- package/domainforge-core/src/semantic_pack/canonical_json.rs +184 -0
- package/domainforge-core/src/semantic_pack/diagnostics.rs +214 -0
- package/domainforge-core/src/semantic_pack/diff.rs +216 -0
- package/domainforge-core/src/semantic_pack/mod.rs +31 -0
- package/domainforge-core/src/semantic_pack/pack_set.rs +240 -0
- package/domainforge-core/src/semantic_pack/resolver.rs +437 -0
- package/domainforge-core/src/semantic_pack/review.rs +125 -0
- package/domainforge-core/src/semantic_pack/schema.rs +342 -0
- package/domainforge-core/src/semantic_pack/signing.rs +105 -0
- package/domainforge-core/src/semantic_pack/validator.rs +368 -0
- package/domainforge-core/src/semantic_version.rs +140 -0
- package/domainforge-core/src/test_utils.rs +12 -0
- package/domainforge-core/src/typescript/authority.rs +184 -0
- package/domainforge-core/src/typescript/error.rs +146 -0
- package/domainforge-core/src/typescript/formatter.rs +76 -0
- package/domainforge-core/src/typescript/graph.rs +391 -0
- package/domainforge-core/src/typescript/mod.rs +9 -0
- package/domainforge-core/src/typescript/policy.rs +564 -0
- package/domainforge-core/src/typescript/primitives.rs +784 -0
- package/domainforge-core/src/typescript/registry.rs +88 -0
- package/domainforge-core/src/typescript/semantic_pack.rs +470 -0
- package/domainforge-core/src/typescript/units.rs +76 -0
- package/domainforge-core/src/units/mod.rs +462 -0
- package/domainforge-core/src/uuid_module.rs +42 -0
- package/domainforge-core/src/validation_error.rs +818 -0
- package/domainforge-core/src/validation_result.rs +30 -0
- package/domainforge-core/src/wasm/authority.rs +192 -0
- package/domainforge-core/src/wasm/error.rs +145 -0
- package/domainforge-core/src/wasm/formatter.rs +69 -0
- package/domainforge-core/src/wasm/graph.rs +471 -0
- package/domainforge-core/src/wasm/mod.rs +16 -0
- package/domainforge-core/src/wasm/policy.rs +607 -0
- package/domainforge-core/src/wasm/primitives.rs +295 -0
- package/domainforge-core/src/wasm/semantic_pack.rs +471 -0
- package/domainforge-core/src/wasm/units.rs +62 -0
- package/domainforge-core/std/aws.sea +6 -0
- package/domainforge-core/std/core.sea +6 -0
- package/domainforge-core/std/http.sea +27 -0
- package/domainforge-core/tests/aggregation_enhanced_tests.rs +162 -0
- package/domainforge-core/tests/aggregation_eval_tests.rs +248 -0
- package/domainforge-core/tests/aggregation_integration_tests.rs +379 -0
- package/domainforge-core/tests/aggregation_parser_tests.rs +92 -0
- package/domainforge-core/tests/aggregation_tests.rs +102 -0
- package/domainforge-core/tests/authority_conformance_tests.rs +1173 -0
- package/domainforge-core/tests/calm_round_trip_tests.rs +283 -0
- package/domainforge-core/tests/calm_schema_validation_tests.rs +137 -0
- package/domainforge-core/tests/cast_operator_tests.rs +85 -0
- package/domainforge-core/tests/cli_binary_check.rs +37 -0
- package/domainforge-core/tests/cli_import_tests.rs +291 -0
- package/domainforge-core/tests/cli_path_traversal_tests.rs +124 -0
- package/domainforge-core/tests/cli_tests.rs +63 -0
- package/domainforge-core/tests/diagnostics_tests.rs +203 -0
- package/domainforge-core/tests/dimension_unit_tests.rs +80 -0
- package/domainforge-core/tests/entity_tests.rs +69 -0
- package/domainforge-core/tests/evolution_semantics_tests.rs +157 -0
- package/domainforge-core/tests/flow_tests.rs +78 -0
- package/domainforge-core/tests/flow_unit_validation_tests.rs +31 -0
- package/domainforge-core/tests/graph_integration_tests.rs +218 -0
- package/domainforge-core/tests/graph_tests.rs +626 -0
- package/domainforge-core/tests/import_parsing_tests.rs +23 -0
- package/domainforge-core/tests/instance_integration_tests.rs +98 -0
- package/domainforge-core/tests/instance_parsing_tests.rs +58 -0
- package/domainforge-core/tests/instance_tests.rs +61 -0
- package/domainforge-core/tests/kg_uri_encoding_tests.rs +53 -0
- package/domainforge-core/tests/lint_tests.rs +19 -0
- package/domainforge-core/tests/metric_tests.rs +143 -0
- package/domainforge-core/tests/module_resolution_tests.rs +100 -0
- package/domainforge-core/tests/namespace_registry_tests.rs +247 -0
- package/domainforge-core/tests/null_handling_tests.rs +26 -0
- package/domainforge-core/tests/parser_ast_v3.rs +53 -0
- package/domainforge-core/tests/parser_dimension_registry_tests.rs +20 -0
- package/domainforge-core/tests/parser_integration_tests.rs +294 -0
- package/domainforge-core/tests/parser_metadata_tests.rs +97 -0
- package/domainforge-core/tests/parser_resource_domain_only_graph_test.rs +21 -0
- package/domainforge-core/tests/parser_resource_limits_tests.rs +122 -0
- package/domainforge-core/tests/parser_tests.rs +512 -0
- package/domainforge-core/tests/pattern_semantics_tests.rs +87 -0
- package/domainforge-core/tests/phase_14_determinism_tests.rs +166 -0
- package/domainforge-core/tests/phase_15_validation_error_tests.rs +136 -0
- package/domainforge-core/tests/phase_16_unicode_tests.rs +248 -0
- package/domainforge-core/tests/phase_17_export_tests.rs +285 -0
- package/domainforge-core/tests/phase_17_round_trip_tests.rs +264 -0
- package/domainforge-core/tests/policy_tests.rs +635 -0
- package/domainforge-core/tests/primitives_integration_tests.rs +151 -0
- package/domainforge-core/tests/print_rdf_xml.rs +14 -0
- package/domainforge-core/tests/printer_tests.rs +204 -0
- package/domainforge-core/tests/profile_tests.rs +35 -0
- package/domainforge-core/tests/projection_contracts_tests.rs +154 -0
- package/domainforge-core/tests/protobuf_projection_tests.rs +199 -0
- package/domainforge-core/tests/quantity_tests.rs +41 -0
- package/domainforge-core/tests/rdf_xml_typed_literal_tests.rs +105 -0
- package/domainforge-core/tests/registry_schema_tests.rs +33 -0
- package/domainforge-core/tests/resource_tests.rs +50 -0
- package/domainforge-core/tests/resource_unit_tests.rs +24 -0
- package/domainforge-core/tests/roles_relations_tests.rs +61 -0
- package/domainforge-core/tests/round_trip_tests.rs +34 -0
- package/domainforge-core/tests/runtime_toggle_tests.rs +70 -0
- package/domainforge-core/tests/sbvr_fact_schema_tests.rs +60 -0
- package/domainforge-core/tests/sbvr_flow_facts_tests.rs +55 -0
- package/domainforge-core/tests/sbvr_parsing_tests.rs +53 -0
- package/domainforge-core/tests/semantic_pack_alias_resolution.rs +197 -0
- package/domainforge-core/tests/semantic_pack_build.rs +302 -0
- package/domainforge-core/tests/semantic_pack_consumer_smoke.rs +150 -0
- package/domainforge-core/tests/semantic_pack_pack_set.rs +160 -0
- package/domainforge-core/tests/semantic_pack_signing.rs +157 -0
- package/domainforge-core/tests/semantic_pack_three_valued.rs +250 -0
- package/domainforge-core/tests/semantic_pack_validate.rs +196 -0
- package/domainforge-core/tests/std_lib_tests.rs +37 -0
- package/domainforge-core/tests/temporal_evaluation_tests.rs +159 -0
- package/domainforge-core/tests/temporal_semantics_tests.rs +214 -0
- package/domainforge-core/tests/three_valued_quantifiers_tests.rs +164 -0
- package/domainforge-core/tests/turtle_entity_export_tests.rs +38 -0
- package/domainforge-core/tests/turtle_escaping_tests.rs +53 -0
- package/domainforge-core/tests/turtle_resource_export_tests.rs +34 -0
- package/domainforge-core/tests/type_inference_tests.rs +40 -0
- package/domainforge-core/tests/unicode_validation_tests.rs +169 -0
- package/domainforge-core/tests/unit_tests.rs +81 -0
- package/domainforge-core/tests/validate_tests.rs +38 -0
- package/domainforge-core/tests/validation_unit_mismatch_tests.rs +83 -0
- package/domainforge-core/tests/wasm_tests.rs +229 -0
- package/domainforge-python/CHANGELOG-python.md +12 -0
- package/domainforge-python/MIGRATING.md +24 -0
- package/domainforge-python/README.md +256 -0
- package/domainforge-python/domainforge/__init__.py +95 -0
- package/domainforge-python/domainforge/domainforge.pyi +519 -0
- package/domainforge-python/pyproject.toml +36 -0
- package/domainforge-typescript/CHANGELOG-typescript.md +12 -0
- package/domainforge-typescript/LICENSE +201 -0
- package/domainforge-typescript/MIGRATING.md +24 -0
- package/domainforge-typescript/README.md +305 -0
- package/domainforge-typescript/index.d.ts +452 -0
- package/domainforge-typescript/index.js +361 -0
- package/domainforge-typescript/package.json +60 -0
- package/example.js +61 -0
- package/examples/browser.html +366 -0
- package/examples/namespaces/finance/cashflow.sea +5 -0
- package/examples/namespaces/logistics/core.sea +7 -0
- package/examples/observability_metrics.sea +38 -0
- package/fixtures/semantic_packs/acme_procurement/domain/entities.sea +39 -0
- package/fixtures/semantic_packs/acme_procurement/domain/metrics.sea +11 -0
- package/fixtures/semantic_packs/acme_procurement/domain/relations.sea +7 -0
- package/fixtures/semantic_packs/acme_procurement/domain/resources.sea +9 -0
- package/fixtures/semantic_packs/acme_procurement/review/acme.procurement.semantic-review.jsonl +7 -0
- package/fixtures/semantic_packs/acme_procurement/tests/ambiguous_vendor_alias.sea +8 -0
- package/fixtures/semantic_packs/acme_procurement/tests/deprecated_vendor_alias.sea +8 -0
- package/fixtures/semantic_packs/acme_procurement/tests/invalid_relation.sea +3 -0
- package/fixtures/semantic_packs/acme_procurement/tests/proposed_concept.sea +8 -0
- package/fixtures/semantic_packs/acme_procurement/tests/rejected_concept.sea +8 -0
- package/fixtures/semantic_packs/acme_procurement/tests/unit_mismatch.sea +7 -0
- package/fixtures/semantic_packs/acme_procurement/tests/unknown_vendor_policy.sea +8 -0
- package/fixtures/semantic_packs/acme_procurement/tests/valid_purchase_policy.sea +8 -0
- package/index.d.ts +2 -0
- package/index.js +8 -0
- package/justfile +200 -0
- package/lefthook.yml +13 -0
- package/lib/validate_native_exports.d.ts +4 -0
- package/lib/validate_native_exports.js +12 -0
- package/package.json +22 -0
- package/pytest.ini +5 -0
- package/python/tests/test_registry.py +75 -0
- package/python/tests/test_units.py +18 -0
- package/release-please-config.json +49 -0
- package/requirements-dev.txt +3 -0
- package/requirements.txt +3 -0
- package/rust-toolchain.toml +3 -0
- package/schemas/ast-v1.schema.json +72 -0
- package/schemas/ast-v2.schema.json +1200 -0
- package/schemas/ast-v3.schema.json +1200 -0
- package/schemas/sea-registry.schema.json +45 -0
- package/scripts/build-python.sh +37 -0
- package/scripts/build-release.sh +279 -0
- package/scripts/build-typescript.sh +13 -0
- package/scripts/build-wasm.sh +113 -0
- package/scripts/bump-version.sh +245 -0
- package/scripts/check_unused_test_imports.py +85 -0
- package/scripts/ci_tasks.py +379 -0
- package/scripts/clear_debug_test.sh +10 -0
- package/scripts/create-github-release.sh +262 -0
- package/scripts/create-tag.sh +203 -0
- package/scripts/find_and_link_test_binary.sh +70 -0
- package/scripts/generate-changelog.sh +271 -0
- package/scripts/generate-release-notes.sh +205 -0
- package/scripts/lint_release_security.py +96 -0
- package/scripts/lint_release_workflows.py +82 -0
- package/scripts/lint_workflow_gates.py +113 -0
- package/scripts/optimized-wasm-build.sh +61 -0
- package/scripts/patch_napi_types.py +62 -0
- package/scripts/pre-release-check.sh +289 -0
- package/scripts/prepare_rust_debug.sh +52 -0
- package/scripts/release.sh +373 -0
- package/scripts/resolve_rust_binary.py +230 -0
- package/scripts/run_commitlint.sh +29 -0
- package/scripts/test-all.sh +77 -0
- package/scripts/update_launch_program.py +93 -0
- package/secrets/README.md +27 -0
- package/secrets/secrets.yaml +21 -0
- package/test_integration.py +67 -0
- package/tests/test_authority.py +328 -0
- package/tests/test_ci_tasks.py +143 -0
- package/tests/test_expression.py +256 -0
- package/tests/test_golden_payment_flow.py +42 -0
- package/tests/test_graph.py +127 -0
- package/tests/test_instance.py +136 -0
- package/tests/test_parser.py +82 -0
- package/tests/test_primitives.py +68 -0
- package/tests/test_role_relation_parity.py +56 -0
- package/tests/test_runtime_toggle.py +156 -0
- package/tests/test_semantic_pack.py +639 -0
- package/tests/test_three_valued_eval.py +159 -0
- package/tsconfig.json +30 -0
- package/typescript-tests/advanced.test.ts +165 -0
- package/typescript-tests/authority.test.ts +216 -0
- package/typescript-tests/expression.test.ts +228 -0
- package/typescript-tests/golden-payment-flow.test.ts +51 -0
- package/typescript-tests/graph.test.ts +142 -0
- package/typescript-tests/native-binding.test.ts +20 -0
- package/typescript-tests/primitives.test.ts +88 -0
- package/typescript-tests/registry.test.ts +122 -0
- package/typescript-tests/role_relation.test.ts +63 -0
- package/typescript-tests/runtime_toggle.test.ts +141 -0
- package/typescript-tests/semantic-pack.test.ts +556 -0
- package/typescript-tests/three_valued_eval.test.ts +135 -0
- package/typescript-tests/units.test.ts +36 -0
- package/vitest.config.ts +13 -0
- package/wasm_demo.html +225 -0
|
@@ -0,0 +1,651 @@
|
|
|
1
|
+
use crate::policy::{
|
|
2
|
+
AggregateFunction as RustAggregateFunction, BinaryOp as RustBinaryOp,
|
|
3
|
+
Expression as RustExpression, NormalizedExpression as RustNormalizedExpression,
|
|
4
|
+
Quantifier as RustQuantifier, UnaryOp as RustUnaryOp, WindowSpec as RustWindowSpec,
|
|
5
|
+
};
|
|
6
|
+
use chrono::DateTime;
|
|
7
|
+
use pyo3::exceptions::PyValueError;
|
|
8
|
+
use pyo3::prelude::*;
|
|
9
|
+
use rust_decimal::Decimal;
|
|
10
|
+
use std::str::FromStr;
|
|
11
|
+
|
|
12
|
+
// =============================================================================
|
|
13
|
+
// Enums
|
|
14
|
+
// =============================================================================
|
|
15
|
+
|
|
16
|
+
#[pyclass(eq, eq_int, from_py_object)]
|
|
17
|
+
#[derive(Clone, PartialEq)]
|
|
18
|
+
pub enum AggregateFunction {
|
|
19
|
+
Count,
|
|
20
|
+
Sum,
|
|
21
|
+
Min,
|
|
22
|
+
Max,
|
|
23
|
+
Avg,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
impl From<AggregateFunction> for RustAggregateFunction {
|
|
27
|
+
fn from(py_agg: AggregateFunction) -> Self {
|
|
28
|
+
match py_agg {
|
|
29
|
+
AggregateFunction::Count => RustAggregateFunction::Count,
|
|
30
|
+
AggregateFunction::Sum => RustAggregateFunction::Sum,
|
|
31
|
+
AggregateFunction::Min => RustAggregateFunction::Min,
|
|
32
|
+
AggregateFunction::Max => RustAggregateFunction::Max,
|
|
33
|
+
AggregateFunction::Avg => RustAggregateFunction::Avg,
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
impl From<RustAggregateFunction> for AggregateFunction {
|
|
39
|
+
fn from(rust_agg: RustAggregateFunction) -> Self {
|
|
40
|
+
match rust_agg {
|
|
41
|
+
RustAggregateFunction::Count => AggregateFunction::Count,
|
|
42
|
+
RustAggregateFunction::Sum => AggregateFunction::Sum,
|
|
43
|
+
RustAggregateFunction::Min => AggregateFunction::Min,
|
|
44
|
+
RustAggregateFunction::Max => AggregateFunction::Max,
|
|
45
|
+
RustAggregateFunction::Avg => AggregateFunction::Avg,
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
#[pyclass(eq, eq_int, from_py_object)]
|
|
51
|
+
#[derive(Clone, PartialEq)]
|
|
52
|
+
pub enum BinaryOp {
|
|
53
|
+
And,
|
|
54
|
+
Or,
|
|
55
|
+
Equal,
|
|
56
|
+
NotEqual,
|
|
57
|
+
GreaterThan,
|
|
58
|
+
LessThan,
|
|
59
|
+
GreaterThanOrEqual,
|
|
60
|
+
LessThanOrEqual,
|
|
61
|
+
Plus,
|
|
62
|
+
Minus,
|
|
63
|
+
Multiply,
|
|
64
|
+
Divide,
|
|
65
|
+
Contains,
|
|
66
|
+
StartsWith,
|
|
67
|
+
EndsWith,
|
|
68
|
+
Matches,
|
|
69
|
+
HasRole,
|
|
70
|
+
Before,
|
|
71
|
+
After,
|
|
72
|
+
During,
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
impl From<BinaryOp> for RustBinaryOp {
|
|
76
|
+
fn from(py_op: BinaryOp) -> Self {
|
|
77
|
+
match py_op {
|
|
78
|
+
BinaryOp::And => RustBinaryOp::And,
|
|
79
|
+
BinaryOp::Or => RustBinaryOp::Or,
|
|
80
|
+
BinaryOp::Equal => RustBinaryOp::Equal,
|
|
81
|
+
BinaryOp::NotEqual => RustBinaryOp::NotEqual,
|
|
82
|
+
BinaryOp::GreaterThan => RustBinaryOp::GreaterThan,
|
|
83
|
+
BinaryOp::LessThan => RustBinaryOp::LessThan,
|
|
84
|
+
BinaryOp::GreaterThanOrEqual => RustBinaryOp::GreaterThanOrEqual,
|
|
85
|
+
BinaryOp::LessThanOrEqual => RustBinaryOp::LessThanOrEqual,
|
|
86
|
+
BinaryOp::Plus => RustBinaryOp::Plus,
|
|
87
|
+
BinaryOp::Minus => RustBinaryOp::Minus,
|
|
88
|
+
BinaryOp::Multiply => RustBinaryOp::Multiply,
|
|
89
|
+
BinaryOp::Divide => RustBinaryOp::Divide,
|
|
90
|
+
BinaryOp::Contains => RustBinaryOp::Contains,
|
|
91
|
+
BinaryOp::StartsWith => RustBinaryOp::StartsWith,
|
|
92
|
+
BinaryOp::EndsWith => RustBinaryOp::EndsWith,
|
|
93
|
+
BinaryOp::Matches => RustBinaryOp::Matches,
|
|
94
|
+
BinaryOp::HasRole => RustBinaryOp::HasRole,
|
|
95
|
+
BinaryOp::Before => RustBinaryOp::Before,
|
|
96
|
+
BinaryOp::After => RustBinaryOp::After,
|
|
97
|
+
BinaryOp::During => RustBinaryOp::During,
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
impl From<RustBinaryOp> for BinaryOp {
|
|
103
|
+
fn from(rust_op: RustBinaryOp) -> Self {
|
|
104
|
+
match rust_op {
|
|
105
|
+
RustBinaryOp::And => BinaryOp::And,
|
|
106
|
+
RustBinaryOp::Or => BinaryOp::Or,
|
|
107
|
+
RustBinaryOp::Equal => BinaryOp::Equal,
|
|
108
|
+
RustBinaryOp::NotEqual => BinaryOp::NotEqual,
|
|
109
|
+
RustBinaryOp::GreaterThan => BinaryOp::GreaterThan,
|
|
110
|
+
RustBinaryOp::LessThan => BinaryOp::LessThan,
|
|
111
|
+
RustBinaryOp::GreaterThanOrEqual => BinaryOp::GreaterThanOrEqual,
|
|
112
|
+
RustBinaryOp::LessThanOrEqual => BinaryOp::LessThanOrEqual,
|
|
113
|
+
RustBinaryOp::Plus => BinaryOp::Plus,
|
|
114
|
+
RustBinaryOp::Minus => BinaryOp::Minus,
|
|
115
|
+
RustBinaryOp::Multiply => BinaryOp::Multiply,
|
|
116
|
+
RustBinaryOp::Divide => BinaryOp::Divide,
|
|
117
|
+
RustBinaryOp::Contains => BinaryOp::Contains,
|
|
118
|
+
RustBinaryOp::StartsWith => BinaryOp::StartsWith,
|
|
119
|
+
RustBinaryOp::EndsWith => BinaryOp::EndsWith,
|
|
120
|
+
RustBinaryOp::Matches => BinaryOp::Matches,
|
|
121
|
+
RustBinaryOp::HasRole => BinaryOp::HasRole,
|
|
122
|
+
RustBinaryOp::Before => BinaryOp::Before,
|
|
123
|
+
RustBinaryOp::After => BinaryOp::After,
|
|
124
|
+
RustBinaryOp::During => BinaryOp::During,
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
#[pyclass(eq, eq_int, from_py_object)]
|
|
130
|
+
#[derive(Clone, PartialEq)]
|
|
131
|
+
pub enum UnaryOp {
|
|
132
|
+
Not,
|
|
133
|
+
Negate,
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
impl From<UnaryOp> for RustUnaryOp {
|
|
137
|
+
fn from(py_op: UnaryOp) -> Self {
|
|
138
|
+
match py_op {
|
|
139
|
+
UnaryOp::Not => RustUnaryOp::Not,
|
|
140
|
+
UnaryOp::Negate => RustUnaryOp::Negate,
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
impl From<RustUnaryOp> for UnaryOp {
|
|
146
|
+
fn from(rust_op: RustUnaryOp) -> Self {
|
|
147
|
+
match rust_op {
|
|
148
|
+
RustUnaryOp::Not => UnaryOp::Not,
|
|
149
|
+
RustUnaryOp::Negate => UnaryOp::Negate,
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
#[pyclass(eq, eq_int, from_py_object)]
|
|
155
|
+
#[derive(Clone, PartialEq)]
|
|
156
|
+
pub enum Quantifier {
|
|
157
|
+
ForAll,
|
|
158
|
+
Exists,
|
|
159
|
+
ExistsUnique,
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
impl From<Quantifier> for RustQuantifier {
|
|
163
|
+
fn from(py_q: Quantifier) -> Self {
|
|
164
|
+
match py_q {
|
|
165
|
+
Quantifier::ForAll => RustQuantifier::ForAll,
|
|
166
|
+
Quantifier::Exists => RustQuantifier::Exists,
|
|
167
|
+
Quantifier::ExistsUnique => RustQuantifier::ExistsUnique,
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
impl From<RustQuantifier> for Quantifier {
|
|
173
|
+
fn from(rust_q: RustQuantifier) -> Self {
|
|
174
|
+
match rust_q {
|
|
175
|
+
RustQuantifier::ForAll => Quantifier::ForAll,
|
|
176
|
+
RustQuantifier::Exists => Quantifier::Exists,
|
|
177
|
+
RustQuantifier::ExistsUnique => Quantifier::ExistsUnique,
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/// Severity level for policy violations
|
|
183
|
+
#[pyclass(eq, eq_int, from_py_object)]
|
|
184
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
185
|
+
pub enum Severity {
|
|
186
|
+
Error,
|
|
187
|
+
Warning,
|
|
188
|
+
Info,
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
impl From<crate::policy::Severity> for Severity {
|
|
192
|
+
fn from(severity: crate::policy::Severity) -> Self {
|
|
193
|
+
match severity {
|
|
194
|
+
crate::policy::Severity::Error => Severity::Error,
|
|
195
|
+
crate::policy::Severity::Warning => Severity::Warning,
|
|
196
|
+
crate::policy::Severity::Info => Severity::Info,
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// =============================================================================
|
|
202
|
+
// WindowSpec
|
|
203
|
+
// =============================================================================
|
|
204
|
+
|
|
205
|
+
#[pyclass(from_py_object)]
|
|
206
|
+
#[derive(Clone)]
|
|
207
|
+
pub struct WindowSpec {
|
|
208
|
+
#[pyo3(get)]
|
|
209
|
+
pub duration: u64,
|
|
210
|
+
#[pyo3(get)]
|
|
211
|
+
pub unit: String,
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
#[pymethods]
|
|
215
|
+
impl WindowSpec {
|
|
216
|
+
#[new]
|
|
217
|
+
fn new(duration: u64, unit: String) -> Self {
|
|
218
|
+
Self { duration, unit }
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
fn __repr__(&self) -> String {
|
|
222
|
+
format!(
|
|
223
|
+
"WindowSpec(duration={}, unit='{}')",
|
|
224
|
+
self.duration, self.unit
|
|
225
|
+
)
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
impl From<WindowSpec> for RustWindowSpec {
|
|
230
|
+
fn from(py_ws: WindowSpec) -> Self {
|
|
231
|
+
RustWindowSpec {
|
|
232
|
+
duration: py_ws.duration,
|
|
233
|
+
unit: py_ws.unit,
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
impl From<RustWindowSpec> for WindowSpec {
|
|
239
|
+
fn from(rust_ws: RustWindowSpec) -> Self {
|
|
240
|
+
WindowSpec {
|
|
241
|
+
duration: rust_ws.duration,
|
|
242
|
+
unit: rust_ws.unit,
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// =============================================================================
|
|
248
|
+
// Expression
|
|
249
|
+
// =============================================================================
|
|
250
|
+
|
|
251
|
+
/// A policy expression that can be normalized and compared for equivalence.
|
|
252
|
+
#[pyclass(from_py_object)]
|
|
253
|
+
#[derive(Clone)]
|
|
254
|
+
pub struct Expression {
|
|
255
|
+
inner: RustExpression,
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
#[pymethods]
|
|
259
|
+
impl Expression {
|
|
260
|
+
// -------------------------------------------------------------------------
|
|
261
|
+
// Factory methods for all Expression variants
|
|
262
|
+
// -------------------------------------------------------------------------
|
|
263
|
+
|
|
264
|
+
/// Create a literal expression from a JSON-compatible value.
|
|
265
|
+
#[staticmethod]
|
|
266
|
+
fn literal(value: &Bound<'_, pyo3::types::PyAny>) -> PyResult<Self> {
|
|
267
|
+
let json_val = python_to_json(value)?;
|
|
268
|
+
Ok(Self {
|
|
269
|
+
inner: RustExpression::Literal(json_val),
|
|
270
|
+
})
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/// Create a variable expression.
|
|
274
|
+
#[staticmethod]
|
|
275
|
+
fn variable(name: &str) -> Self {
|
|
276
|
+
Self {
|
|
277
|
+
inner: RustExpression::Variable(name.to_string()),
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/// Create a quantity literal expression (e.g., "100 USD").
|
|
282
|
+
#[staticmethod]
|
|
283
|
+
fn quantity(value: &str, unit: &str) -> PyResult<Self> {
|
|
284
|
+
let decimal = Decimal::from_str(value)
|
|
285
|
+
.map_err(|e| PyValueError::new_err(format!("Invalid decimal value: {}", e)))?;
|
|
286
|
+
Ok(Self {
|
|
287
|
+
inner: RustExpression::QuantityLiteral {
|
|
288
|
+
value: decimal,
|
|
289
|
+
unit: unit.to_string(),
|
|
290
|
+
},
|
|
291
|
+
})
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/// Create a time literal expression (ISO 8601 timestamp).
|
|
295
|
+
#[staticmethod]
|
|
296
|
+
fn time(timestamp: &str) -> PyResult<Self> {
|
|
297
|
+
DateTime::parse_from_rfc3339(timestamp)
|
|
298
|
+
.map_err(|e| PyValueError::new_err(format!("Invalid timestamp: {}", e)))?;
|
|
299
|
+
Ok(Self {
|
|
300
|
+
inner: RustExpression::TimeLiteral(timestamp.to_string()),
|
|
301
|
+
})
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/// Create an interval literal expression.
|
|
305
|
+
#[staticmethod]
|
|
306
|
+
fn interval(start: &str, end: &str) -> PyResult<Self> {
|
|
307
|
+
let start_dt = DateTime::parse_from_rfc3339(start)
|
|
308
|
+
.map_err(|e| PyValueError::new_err(format!("Invalid start timestamp: {}", e)))?;
|
|
309
|
+
let end_dt = DateTime::parse_from_rfc3339(end)
|
|
310
|
+
.map_err(|e| PyValueError::new_err(format!("Invalid end timestamp: {}", e)))?;
|
|
311
|
+
|
|
312
|
+
if start_dt > end_dt {
|
|
313
|
+
return Err(PyValueError::new_err(
|
|
314
|
+
"Start time must be before or equal to end time",
|
|
315
|
+
));
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
Ok(Self {
|
|
319
|
+
inner: RustExpression::IntervalLiteral {
|
|
320
|
+
start: start.to_string(),
|
|
321
|
+
end: end.to_string(),
|
|
322
|
+
},
|
|
323
|
+
})
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/// Create a binary expression (e.g., left AND right).
|
|
327
|
+
#[staticmethod]
|
|
328
|
+
fn binary(op: BinaryOp, left: &Expression, right: &Expression) -> Self {
|
|
329
|
+
Self {
|
|
330
|
+
inner: RustExpression::Binary {
|
|
331
|
+
op: op.into(),
|
|
332
|
+
left: Box::new(left.inner.clone()),
|
|
333
|
+
right: Box::new(right.inner.clone()),
|
|
334
|
+
},
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/// Create a unary expression (e.g., NOT x).
|
|
339
|
+
#[staticmethod]
|
|
340
|
+
fn unary(op: UnaryOp, operand: &Expression) -> Self {
|
|
341
|
+
Self {
|
|
342
|
+
inner: RustExpression::Unary {
|
|
343
|
+
op: op.into(),
|
|
344
|
+
operand: Box::new(operand.inner.clone()),
|
|
345
|
+
},
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/// Create a cast expression (e.g., x as "Money").
|
|
350
|
+
#[staticmethod]
|
|
351
|
+
fn cast(operand: &Expression, target_type: &str) -> Self {
|
|
352
|
+
Self {
|
|
353
|
+
inner: RustExpression::Cast {
|
|
354
|
+
operand: Box::new(operand.inner.clone()),
|
|
355
|
+
target_type: target_type.to_string(),
|
|
356
|
+
},
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/// Create a quantifier expression (ForAll, Exists, ExistsUnique).
|
|
361
|
+
#[staticmethod]
|
|
362
|
+
fn quantifier(
|
|
363
|
+
q: Quantifier,
|
|
364
|
+
variable: &str,
|
|
365
|
+
collection: &Expression,
|
|
366
|
+
condition: &Expression,
|
|
367
|
+
) -> Self {
|
|
368
|
+
Self {
|
|
369
|
+
inner: RustExpression::Quantifier {
|
|
370
|
+
quantifier: q.into(),
|
|
371
|
+
variable: variable.to_string(),
|
|
372
|
+
collection: Box::new(collection.inner.clone()),
|
|
373
|
+
condition: Box::new(condition.inner.clone()),
|
|
374
|
+
},
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/// Create a member access expression (e.g., user.name).
|
|
379
|
+
#[staticmethod]
|
|
380
|
+
fn member_access(object: &str, member: &str) -> Self {
|
|
381
|
+
Self {
|
|
382
|
+
inner: RustExpression::MemberAccess {
|
|
383
|
+
object: object.to_string(),
|
|
384
|
+
member: member.to_string(),
|
|
385
|
+
},
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/// Create an aggregation expression (e.g., COUNT(items)).
|
|
390
|
+
#[staticmethod]
|
|
391
|
+
#[pyo3(signature = (function, collection, field=None, filter=None))]
|
|
392
|
+
fn aggregation(
|
|
393
|
+
function: AggregateFunction,
|
|
394
|
+
collection: &Expression,
|
|
395
|
+
field: Option<&str>,
|
|
396
|
+
filter: Option<&Expression>,
|
|
397
|
+
) -> Self {
|
|
398
|
+
Self {
|
|
399
|
+
inner: RustExpression::Aggregation {
|
|
400
|
+
function: function.into(),
|
|
401
|
+
collection: Box::new(collection.inner.clone()),
|
|
402
|
+
field: field.map(|s| s.to_string()),
|
|
403
|
+
filter: filter.map(|e| Box::new(e.inner.clone())),
|
|
404
|
+
},
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/// Create an aggregation comprehension expression.
|
|
409
|
+
#[staticmethod]
|
|
410
|
+
#[pyo3(signature = (function, variable, collection, predicate, projection, window=None, target_unit=None))]
|
|
411
|
+
fn aggregation_comprehension(
|
|
412
|
+
function: AggregateFunction,
|
|
413
|
+
variable: &str,
|
|
414
|
+
collection: &Expression,
|
|
415
|
+
predicate: &Expression,
|
|
416
|
+
projection: &Expression,
|
|
417
|
+
window: Option<&WindowSpec>,
|
|
418
|
+
target_unit: Option<&str>,
|
|
419
|
+
) -> Self {
|
|
420
|
+
Self {
|
|
421
|
+
inner: RustExpression::AggregationComprehension {
|
|
422
|
+
function: function.into(),
|
|
423
|
+
variable: variable.to_string(),
|
|
424
|
+
collection: Box::new(collection.inner.clone()),
|
|
425
|
+
window: window.map(|w| w.clone().into()),
|
|
426
|
+
predicate: Box::new(predicate.inner.clone()),
|
|
427
|
+
projection: Box::new(projection.inner.clone()),
|
|
428
|
+
target_unit: target_unit.map(|s| s.to_string()),
|
|
429
|
+
},
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/// Create a group-by expression.
|
|
434
|
+
#[staticmethod]
|
|
435
|
+
#[pyo3(signature = (variable, collection, key, condition, filter=None))]
|
|
436
|
+
fn group_by(
|
|
437
|
+
variable: &str,
|
|
438
|
+
collection: &Expression,
|
|
439
|
+
key: &Expression,
|
|
440
|
+
condition: &Expression,
|
|
441
|
+
filter: Option<&Expression>,
|
|
442
|
+
) -> Self {
|
|
443
|
+
Self {
|
|
444
|
+
inner: RustExpression::GroupBy {
|
|
445
|
+
variable: variable.to_string(),
|
|
446
|
+
collection: Box::new(collection.inner.clone()),
|
|
447
|
+
filter: filter.map(|e| Box::new(e.inner.clone())),
|
|
448
|
+
key: Box::new(key.inner.clone()),
|
|
449
|
+
condition: Box::new(condition.inner.clone()),
|
|
450
|
+
},
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// -------------------------------------------------------------------------
|
|
455
|
+
// Normalization methods
|
|
456
|
+
// -------------------------------------------------------------------------
|
|
457
|
+
|
|
458
|
+
/// Normalize this expression to canonical form.
|
|
459
|
+
fn normalize(&self) -> NormalizedExpression {
|
|
460
|
+
NormalizedExpression {
|
|
461
|
+
inner: self.inner.normalize(),
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/// Check if this expression is semantically equivalent to another.
|
|
466
|
+
fn is_equivalent(&self, other: &Expression) -> bool {
|
|
467
|
+
self.inner.is_equivalent(&other.inner)
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
fn __str__(&self) -> String {
|
|
471
|
+
self.inner.to_string()
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
fn __repr__(&self) -> String {
|
|
475
|
+
format!("Expression({})", self.inner)
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
fn __eq__(&self, other: &Expression) -> bool {
|
|
479
|
+
self.inner == other.inner
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
impl From<RustExpression> for Expression {
|
|
484
|
+
fn from(expr: RustExpression) -> Self {
|
|
485
|
+
Self { inner: expr }
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
impl Expression {
|
|
490
|
+
pub fn into_inner(self) -> RustExpression {
|
|
491
|
+
self.inner
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// =============================================================================
|
|
496
|
+
// NormalizedExpression
|
|
497
|
+
// =============================================================================
|
|
498
|
+
|
|
499
|
+
/// A normalized expression with a stable hash for caching and equivalence checks.
|
|
500
|
+
#[pyclass(from_py_object)]
|
|
501
|
+
#[derive(Clone)]
|
|
502
|
+
pub struct NormalizedExpression {
|
|
503
|
+
inner: RustNormalizedExpression,
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
#[pymethods]
|
|
507
|
+
impl NormalizedExpression {
|
|
508
|
+
/// Get the stable hash value for this normalized expression.
|
|
509
|
+
fn stable_hash(&self) -> u64 {
|
|
510
|
+
self.inner.stable_hash()
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/// Get the inner expression.
|
|
514
|
+
fn inner_expression(&self) -> Expression {
|
|
515
|
+
Expression {
|
|
516
|
+
inner: self.inner.inner().clone(),
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
fn __str__(&self) -> String {
|
|
521
|
+
self.inner.to_string()
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
fn __repr__(&self) -> String {
|
|
525
|
+
format!(
|
|
526
|
+
"NormalizedExpression({}, hash={:#018x})",
|
|
527
|
+
self.inner,
|
|
528
|
+
self.inner.stable_hash()
|
|
529
|
+
)
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
fn __eq__(&self, other: &NormalizedExpression) -> bool {
|
|
533
|
+
self.inner == other.inner
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
fn __hash__(&self) -> u64 {
|
|
537
|
+
self.inner.stable_hash()
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// =============================================================================
|
|
542
|
+
// Violation and EvaluationResult
|
|
543
|
+
// =============================================================================
|
|
544
|
+
|
|
545
|
+
/// A policy violation
|
|
546
|
+
#[pyclass(from_py_object)]
|
|
547
|
+
#[derive(Debug, Clone)]
|
|
548
|
+
pub struct Violation {
|
|
549
|
+
#[pyo3(get)]
|
|
550
|
+
pub name: String,
|
|
551
|
+
#[pyo3(get)]
|
|
552
|
+
pub message: String,
|
|
553
|
+
#[pyo3(get)]
|
|
554
|
+
pub severity: Severity,
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
#[pymethods]
|
|
558
|
+
impl Violation {
|
|
559
|
+
fn __repr__(&self) -> String {
|
|
560
|
+
format!(
|
|
561
|
+
"Violation(name='{}', message='{}', severity='{:?}')",
|
|
562
|
+
self.name, self.message, self.severity
|
|
563
|
+
)
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
impl From<crate::policy::Violation> for Violation {
|
|
568
|
+
fn from(v: crate::policy::Violation) -> Self {
|
|
569
|
+
Self {
|
|
570
|
+
name: v.policy_name,
|
|
571
|
+
message: v.message,
|
|
572
|
+
severity: v.severity.into(),
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/// Result of evaluating a policy against a graph
|
|
578
|
+
#[pyclass(from_py_object)]
|
|
579
|
+
#[derive(Clone, Debug)]
|
|
580
|
+
pub struct EvaluationResult {
|
|
581
|
+
/// Backwards compatible boolean: false if evaluation is unknown (NULL)
|
|
582
|
+
#[pyo3(get)]
|
|
583
|
+
pub is_satisfied: bool,
|
|
584
|
+
/// Tri-state evaluation result: True, False, or None (NULL)
|
|
585
|
+
#[pyo3(get)]
|
|
586
|
+
pub is_satisfied_tristate: Option<bool>,
|
|
587
|
+
/// List of violations
|
|
588
|
+
#[pyo3(get)]
|
|
589
|
+
pub violations: Vec<Violation>,
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
#[pymethods]
|
|
593
|
+
impl EvaluationResult {
|
|
594
|
+
fn __repr__(&self) -> String {
|
|
595
|
+
format!(
|
|
596
|
+
"EvaluationResult(is_satisfied={}, is_satisfied_tristate={:?}, violations={})",
|
|
597
|
+
self.is_satisfied,
|
|
598
|
+
self.is_satisfied_tristate,
|
|
599
|
+
self.violations.len()
|
|
600
|
+
)
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
impl From<crate::policy::EvaluationResult> for EvaluationResult {
|
|
605
|
+
fn from(result: crate::policy::EvaluationResult) -> Self {
|
|
606
|
+
Self {
|
|
607
|
+
is_satisfied: result.is_satisfied,
|
|
608
|
+
is_satisfied_tristate: result.is_satisfied_tristate,
|
|
609
|
+
violations: result.violations.into_iter().map(|v| v.into()).collect(),
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
// =============================================================================
|
|
615
|
+
// Helper functions
|
|
616
|
+
// =============================================================================
|
|
617
|
+
|
|
618
|
+
/// Convert a Python value to a serde_json::Value.
|
|
619
|
+
fn python_to_json(value: &Bound<'_, pyo3::types::PyAny>) -> PyResult<serde_json::Value> {
|
|
620
|
+
if value.is_none() {
|
|
621
|
+
Ok(serde_json::Value::Null)
|
|
622
|
+
} else if let Ok(b) = value.extract::<bool>() {
|
|
623
|
+
Ok(serde_json::Value::Bool(b))
|
|
624
|
+
} else if let Ok(i) = value.extract::<i64>() {
|
|
625
|
+
Ok(serde_json::Value::Number(i.into()))
|
|
626
|
+
} else if let Ok(f) = value.extract::<f64>() {
|
|
627
|
+
serde_json::Number::from_f64(f)
|
|
628
|
+
.map(serde_json::Value::Number)
|
|
629
|
+
.ok_or_else(|| PyValueError::new_err("Invalid float value (NaN or Infinity)"))
|
|
630
|
+
} else if let Ok(s) = value.extract::<String>() {
|
|
631
|
+
Ok(serde_json::Value::String(s))
|
|
632
|
+
} else if let Ok(list) = value.cast::<pyo3::types::PyList>() {
|
|
633
|
+
let arr: Result<Vec<_>, _> = list.iter().map(|v| python_to_json(&v)).collect();
|
|
634
|
+
Ok(serde_json::Value::Array(arr?))
|
|
635
|
+
} else if let Ok(tuple) = value.cast::<pyo3::types::PyTuple>() {
|
|
636
|
+
let arr: Result<Vec<_>, _> = tuple.iter().map(|v| python_to_json(&v)).collect();
|
|
637
|
+
Ok(serde_json::Value::Array(arr?))
|
|
638
|
+
} else if let Ok(dict) = value.cast::<pyo3::types::PyDict>() {
|
|
639
|
+
let mut map = serde_json::Map::new();
|
|
640
|
+
for (k, v) in dict.iter() {
|
|
641
|
+
let key: String = k.extract()?;
|
|
642
|
+
map.insert(key, python_to_json(&v)?);
|
|
643
|
+
}
|
|
644
|
+
Ok(serde_json::Value::Object(map))
|
|
645
|
+
} else {
|
|
646
|
+
Err(PyValueError::new_err(format!(
|
|
647
|
+
"Cannot convert Python value to JSON: {:?}",
|
|
648
|
+
value
|
|
649
|
+
)))
|
|
650
|
+
}
|
|
651
|
+
}
|