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,43 @@
|
|
|
1
|
+
use crate::graph::Graph;
|
|
2
|
+
use crate::parser::ast::TargetFormat;
|
|
3
|
+
use crate::primitives::{MappingContract, ProjectionContract};
|
|
4
|
+
|
|
5
|
+
pub struct ProjectionRegistry<'a> {
|
|
6
|
+
graph: &'a Graph,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
impl<'a> ProjectionRegistry<'a> {
|
|
10
|
+
pub fn new(graph: &'a Graph) -> Self {
|
|
11
|
+
Self { graph }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
pub fn find_mappings_for_target(&self, target: &TargetFormat) -> Vec<&MappingContract> {
|
|
15
|
+
self.graph
|
|
16
|
+
.all_mappings()
|
|
17
|
+
.into_iter()
|
|
18
|
+
.filter(|m| m.target_format() == target)
|
|
19
|
+
.collect()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
pub fn find_projections_for_target(&self, target: &TargetFormat) -> Vec<&ProjectionContract> {
|
|
23
|
+
self.graph
|
|
24
|
+
.all_projections()
|
|
25
|
+
.into_iter()
|
|
26
|
+
.filter(|p| p.target_format() == target)
|
|
27
|
+
.collect()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
pub fn get_mapping_by_name(&self, name: &str) -> Option<&MappingContract> {
|
|
31
|
+
self.graph
|
|
32
|
+
.all_mappings()
|
|
33
|
+
.into_iter()
|
|
34
|
+
.find(|m| m.name() == name)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
pub fn get_projection_by_name(&self, name: &str) -> Option<&ProjectionContract> {
|
|
38
|
+
self.graph
|
|
39
|
+
.all_projections()
|
|
40
|
+
.into_iter()
|
|
41
|
+
.find(|p| p.name() == name)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
use crate::authority::{
|
|
2
|
+
AuthorityEnvironment as RustAuthorityEnvironment,
|
|
3
|
+
AuthorityEnvironmentConfig as RustAuthorityEnvironmentConfig, ClaimLevel as RustClaimLevel,
|
|
4
|
+
FactEnvelope as RustFactEnvelope, FinalDecision as RustFinalDecision,
|
|
5
|
+
PolicyModality as RustPolicyModality, SourceClass as RustSourceClass,
|
|
6
|
+
};
|
|
7
|
+
use pyo3::exceptions::PyValueError;
|
|
8
|
+
use pyo3::prelude::*;
|
|
9
|
+
|
|
10
|
+
// =============================================================================
|
|
11
|
+
// Enums
|
|
12
|
+
// =============================================================================
|
|
13
|
+
|
|
14
|
+
#[pyclass(eq, eq_int, from_py_object)]
|
|
15
|
+
#[derive(Clone, PartialEq)]
|
|
16
|
+
pub enum FinalDecision {
|
|
17
|
+
Allow,
|
|
18
|
+
Deny,
|
|
19
|
+
Escalate,
|
|
20
|
+
NotApplicable,
|
|
21
|
+
Reject,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
impl From<FinalDecision> for RustFinalDecision {
|
|
25
|
+
fn from(v: FinalDecision) -> Self {
|
|
26
|
+
match v {
|
|
27
|
+
FinalDecision::Allow => RustFinalDecision::Allow,
|
|
28
|
+
FinalDecision::Deny => RustFinalDecision::Deny,
|
|
29
|
+
FinalDecision::Escalate => RustFinalDecision::Escalate,
|
|
30
|
+
FinalDecision::NotApplicable => RustFinalDecision::NotApplicable,
|
|
31
|
+
FinalDecision::Reject => RustFinalDecision::Reject,
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
impl From<RustFinalDecision> for FinalDecision {
|
|
37
|
+
fn from(v: RustFinalDecision) -> Self {
|
|
38
|
+
match v {
|
|
39
|
+
RustFinalDecision::Allow => FinalDecision::Allow,
|
|
40
|
+
RustFinalDecision::Deny => FinalDecision::Deny,
|
|
41
|
+
RustFinalDecision::Escalate => FinalDecision::Escalate,
|
|
42
|
+
RustFinalDecision::NotApplicable => FinalDecision::NotApplicable,
|
|
43
|
+
RustFinalDecision::Reject => FinalDecision::Reject,
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
#[pyclass(eq, eq_int, from_py_object)]
|
|
49
|
+
#[derive(Clone, PartialEq)]
|
|
50
|
+
pub enum PolicyModality {
|
|
51
|
+
Permission,
|
|
52
|
+
Prohibition,
|
|
53
|
+
Obligation,
|
|
54
|
+
Override,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
impl From<PolicyModality> for RustPolicyModality {
|
|
58
|
+
fn from(v: PolicyModality) -> Self {
|
|
59
|
+
match v {
|
|
60
|
+
PolicyModality::Permission => RustPolicyModality::Permission,
|
|
61
|
+
PolicyModality::Prohibition => RustPolicyModality::Prohibition,
|
|
62
|
+
PolicyModality::Obligation => RustPolicyModality::Obligation,
|
|
63
|
+
PolicyModality::Override => RustPolicyModality::Override,
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
impl From<RustPolicyModality> for PolicyModality {
|
|
69
|
+
fn from(v: RustPolicyModality) -> Self {
|
|
70
|
+
match v {
|
|
71
|
+
RustPolicyModality::Permission => PolicyModality::Permission,
|
|
72
|
+
RustPolicyModality::Prohibition => PolicyModality::Prohibition,
|
|
73
|
+
RustPolicyModality::Obligation => PolicyModality::Obligation,
|
|
74
|
+
RustPolicyModality::Override => PolicyModality::Override,
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
#[pyclass(eq, eq_int, from_py_object)]
|
|
80
|
+
#[derive(Clone, PartialEq)]
|
|
81
|
+
pub enum SourceClass {
|
|
82
|
+
CallerSupplied,
|
|
83
|
+
RuntimeObserved,
|
|
84
|
+
SystemOfRecord,
|
|
85
|
+
Attested,
|
|
86
|
+
ManualApproval,
|
|
87
|
+
Derived,
|
|
88
|
+
UnknownSource,
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
impl From<SourceClass> for RustSourceClass {
|
|
92
|
+
fn from(v: SourceClass) -> Self {
|
|
93
|
+
match v {
|
|
94
|
+
SourceClass::CallerSupplied => RustSourceClass::CallerSupplied,
|
|
95
|
+
SourceClass::RuntimeObserved => RustSourceClass::RuntimeObserved,
|
|
96
|
+
SourceClass::SystemOfRecord => RustSourceClass::SystemOfRecord,
|
|
97
|
+
SourceClass::Attested => RustSourceClass::Attested,
|
|
98
|
+
SourceClass::ManualApproval => RustSourceClass::ManualApproval,
|
|
99
|
+
SourceClass::Derived => RustSourceClass::Derived,
|
|
100
|
+
SourceClass::UnknownSource => RustSourceClass::UnknownSource,
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
impl From<RustSourceClass> for SourceClass {
|
|
106
|
+
fn from(v: RustSourceClass) -> Self {
|
|
107
|
+
match v {
|
|
108
|
+
RustSourceClass::CallerSupplied => SourceClass::CallerSupplied,
|
|
109
|
+
RustSourceClass::RuntimeObserved => SourceClass::RuntimeObserved,
|
|
110
|
+
RustSourceClass::SystemOfRecord => SourceClass::SystemOfRecord,
|
|
111
|
+
RustSourceClass::Attested => SourceClass::Attested,
|
|
112
|
+
RustSourceClass::ManualApproval => SourceClass::ManualApproval,
|
|
113
|
+
RustSourceClass::Derived => SourceClass::Derived,
|
|
114
|
+
RustSourceClass::UnknownSource => SourceClass::UnknownSource,
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
#[pyclass(eq, eq_int, from_py_object)]
|
|
120
|
+
#[derive(Clone, PartialEq)]
|
|
121
|
+
pub enum ClaimLevel {
|
|
122
|
+
AuditBacked,
|
|
123
|
+
Validated,
|
|
124
|
+
FormallyProven,
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
impl From<ClaimLevel> for RustClaimLevel {
|
|
128
|
+
fn from(v: ClaimLevel) -> Self {
|
|
129
|
+
match v {
|
|
130
|
+
ClaimLevel::AuditBacked => RustClaimLevel::AuditBacked,
|
|
131
|
+
ClaimLevel::Validated => RustClaimLevel::Validated,
|
|
132
|
+
ClaimLevel::FormallyProven => RustClaimLevel::FormallyProven,
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
impl From<RustClaimLevel> for ClaimLevel {
|
|
138
|
+
fn from(v: RustClaimLevel) -> Self {
|
|
139
|
+
match v {
|
|
140
|
+
RustClaimLevel::AuditBacked => ClaimLevel::AuditBacked,
|
|
141
|
+
RustClaimLevel::Validated => ClaimLevel::Validated,
|
|
142
|
+
RustClaimLevel::FormallyProven => ClaimLevel::FormallyProven,
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// =============================================================================
|
|
148
|
+
// Structs
|
|
149
|
+
// =============================================================================
|
|
150
|
+
|
|
151
|
+
#[pyclass(skip_from_py_object)]
|
|
152
|
+
pub struct AuthorityEnvironment {
|
|
153
|
+
inner: RustAuthorityEnvironment,
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
#[pymethods]
|
|
157
|
+
impl AuthorityEnvironment {
|
|
158
|
+
#[new]
|
|
159
|
+
fn new(config_json: &str) -> PyResult<Self> {
|
|
160
|
+
let config: RustAuthorityEnvironmentConfig = serde_json::from_str(config_json)
|
|
161
|
+
.map_err(|e| PyValueError::new_err(format!("Invalid config JSON: {}", e)))?;
|
|
162
|
+
let env = RustAuthorityEnvironment::new(config)
|
|
163
|
+
.map_err(|e| PyValueError::new_err(format!("Authority error: {}", e)))?;
|
|
164
|
+
Ok(Self { inner: env })
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
fn validate(&mut self) -> PyResult<()> {
|
|
168
|
+
self.inner
|
|
169
|
+
.validate()
|
|
170
|
+
.map_err(|e| PyValueError::new_err(format!("Validation error: {}", e)))
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
#[pyo3(signature = (request_json, facts_json = "[]"))]
|
|
174
|
+
fn evaluate(&self, request_json: &str, facts_json: &str) -> PyResult<(String, String)> {
|
|
175
|
+
let request: crate::authority::AuthorityRequest = serde_json::from_str(request_json)
|
|
176
|
+
.map_err(|e| PyValueError::new_err(format!("Invalid request JSON: {}", e)))?;
|
|
177
|
+
let facts: Vec<RustFactEnvelope> = serde_json::from_str(facts_json)
|
|
178
|
+
.map_err(|e| PyValueError::new_err(format!("Invalid facts JSON: {}", e)))?;
|
|
179
|
+
let (trace, decision) = self
|
|
180
|
+
.inner
|
|
181
|
+
.evaluate(&request, &facts)
|
|
182
|
+
.map_err(|e| PyValueError::new_err(format!("Evaluation error: {}", e)))?;
|
|
183
|
+
let trace_json = serde_json::to_string(&trace)
|
|
184
|
+
.map_err(|e| PyValueError::new_err(format!("Trace serialization error: {}", e)))?;
|
|
185
|
+
let decision_json = serde_json::to_string(&decision)
|
|
186
|
+
.map_err(|e| PyValueError::new_err(format!("Decision serialization error: {}", e)))?;
|
|
187
|
+
Ok((trace_json, decision_json))
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
fn __repr__(&self) -> String {
|
|
191
|
+
"<Py AuthorityEnvironment>".to_string()
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
#[pyclass(from_py_object)]
|
|
196
|
+
#[derive(Clone)]
|
|
197
|
+
pub struct AuthorityErrorCode {
|
|
198
|
+
#[pyo3(get)]
|
|
199
|
+
pub code: String,
|
|
200
|
+
#[pyo3(get)]
|
|
201
|
+
pub message: String,
|
|
202
|
+
#[pyo3(get)]
|
|
203
|
+
pub recoverable: bool,
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
#[pymethods]
|
|
207
|
+
impl AuthorityErrorCode {
|
|
208
|
+
fn __repr__(&self) -> String {
|
|
209
|
+
format!(
|
|
210
|
+
"AuthorityError(code='{}', message='{}')",
|
|
211
|
+
self.code, self.message
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/// Evaluate an authority request against a policy environment configuration.
|
|
217
|
+
///
|
|
218
|
+
/// Args:
|
|
219
|
+
/// config_json: JSON string of AuthorityEnvironmentConfig
|
|
220
|
+
/// request_json: JSON string of AuthorityRequest
|
|
221
|
+
/// facts_json: JSON array of FactEnvelope objects (optional)
|
|
222
|
+
///
|
|
223
|
+
/// Returns:
|
|
224
|
+
/// Tuple of (trace_json, decision_json)
|
|
225
|
+
#[pyfunction]
|
|
226
|
+
#[pyo3(signature = (config_json, request_json, facts_json = "[]"))]
|
|
227
|
+
pub fn evaluate_authority(
|
|
228
|
+
config_json: &str,
|
|
229
|
+
request_json: &str,
|
|
230
|
+
facts_json: &str,
|
|
231
|
+
) -> PyResult<(String, String)> {
|
|
232
|
+
let config: RustAuthorityEnvironmentConfig = serde_json::from_str(config_json)
|
|
233
|
+
.map_err(|e| PyValueError::new_err(format!("Invalid config: {}", e)))?;
|
|
234
|
+
let mut env = RustAuthorityEnvironment::new(config)
|
|
235
|
+
.map_err(|e| PyValueError::new_err(format!("Environment error: {}", e)))?;
|
|
236
|
+
env.validate()
|
|
237
|
+
.map_err(|e| PyValueError::new_err(format!("Validation error: {}", e)))?;
|
|
238
|
+
|
|
239
|
+
let request: crate::authority::AuthorityRequest = serde_json::from_str(request_json)
|
|
240
|
+
.map_err(|e| PyValueError::new_err(format!("Invalid request: {}", e)))?;
|
|
241
|
+
let facts: Vec<RustFactEnvelope> = serde_json::from_str(facts_json)
|
|
242
|
+
.map_err(|e| PyValueError::new_err(format!("Invalid facts: {}", e)))?;
|
|
243
|
+
|
|
244
|
+
let (trace, decision) = env
|
|
245
|
+
.evaluate(&request, &facts)
|
|
246
|
+
.map_err(|e| PyValueError::new_err(format!("Evaluation error: {}", e)))?;
|
|
247
|
+
|
|
248
|
+
let trace_json = serde_json::to_string(&trace)
|
|
249
|
+
.map_err(|e| PyValueError::new_err(format!("Trace serialization error: {}", e)))?;
|
|
250
|
+
let decision_json = serde_json::to_string(&decision)
|
|
251
|
+
.map_err(|e| PyValueError::new_err(format!("Decision serialization error: {}", e)))?;
|
|
252
|
+
Ok((trace_json, decision_json))
|
|
253
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/// Python-native error types for domainforge
|
|
2
|
+
///
|
|
3
|
+
/// This module provides Python exception conversion that feels native to Python users.
|
|
4
|
+
/// Users should never see Rust error types when using the Python bindings.
|
|
5
|
+
use crate::validation_error::ValidationError;
|
|
6
|
+
use pyo3::exceptions::PyException;
|
|
7
|
+
use pyo3::prelude::*;
|
|
8
|
+
|
|
9
|
+
/// Convert ValidationError to appropriate Python exception with custom attributes
|
|
10
|
+
pub fn to_python_exception(py: Python, err: ValidationError) -> PyErr {
|
|
11
|
+
let code = err.error_code().as_str().to_string();
|
|
12
|
+
|
|
13
|
+
match err {
|
|
14
|
+
ValidationError::SyntaxError {
|
|
15
|
+
message,
|
|
16
|
+
line,
|
|
17
|
+
column,
|
|
18
|
+
..
|
|
19
|
+
} => {
|
|
20
|
+
let exc = PyException::new_err(message);
|
|
21
|
+
let exc_obj = exc.value(py);
|
|
22
|
+
|
|
23
|
+
if let Err(e) = exc_obj.setattr("code", code) {
|
|
24
|
+
return e;
|
|
25
|
+
}
|
|
26
|
+
if let Err(e) = exc_obj.setattr("line", line) {
|
|
27
|
+
return e;
|
|
28
|
+
}
|
|
29
|
+
if let Err(e) = exc_obj.setattr("column", column) {
|
|
30
|
+
return e;
|
|
31
|
+
}
|
|
32
|
+
if let Err(e) = exc_obj.setattr("error_type", "SyntaxError") {
|
|
33
|
+
return e;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
exc
|
|
37
|
+
}
|
|
38
|
+
ValidationError::TypeError {
|
|
39
|
+
message,
|
|
40
|
+
expected_type,
|
|
41
|
+
found_type,
|
|
42
|
+
suggestion,
|
|
43
|
+
..
|
|
44
|
+
} => {
|
|
45
|
+
let exc = PyException::new_err(message);
|
|
46
|
+
let exc_obj = exc.value(py);
|
|
47
|
+
|
|
48
|
+
if let Err(e) = exc_obj.setattr("code", code) {
|
|
49
|
+
return e;
|
|
50
|
+
}
|
|
51
|
+
if let Err(e) = exc_obj.setattr("error_type", "TypeError") {
|
|
52
|
+
return e;
|
|
53
|
+
}
|
|
54
|
+
if let Some(exp) = expected_type {
|
|
55
|
+
if let Err(e) = exc_obj.setattr("expected", exp) {
|
|
56
|
+
return e;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if let Some(fnd) = found_type {
|
|
60
|
+
if let Err(e) = exc_obj.setattr("found", fnd) {
|
|
61
|
+
return e;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if let Some(sug) = suggestion {
|
|
65
|
+
if let Err(e) = exc_obj.setattr("suggestion", sug) {
|
|
66
|
+
return e;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
exc
|
|
71
|
+
}
|
|
72
|
+
ValidationError::UnitError {
|
|
73
|
+
expected,
|
|
74
|
+
found,
|
|
75
|
+
suggestion,
|
|
76
|
+
..
|
|
77
|
+
} => {
|
|
78
|
+
let message = format!("Unit mismatch: expected {:?}, found {:?}", expected, found);
|
|
79
|
+
let exc = PyException::new_err(message);
|
|
80
|
+
let exc_obj = exc.value(py);
|
|
81
|
+
|
|
82
|
+
if let Err(e) = exc_obj.setattr("code", code) {
|
|
83
|
+
return e;
|
|
84
|
+
}
|
|
85
|
+
if let Err(e) = exc_obj.setattr("error_type", "UnitError") {
|
|
86
|
+
return e;
|
|
87
|
+
}
|
|
88
|
+
if let Err(e) = exc_obj.setattr("expected_dimension", format!("{:?}", expected)) {
|
|
89
|
+
return e;
|
|
90
|
+
}
|
|
91
|
+
if let Err(e) = exc_obj.setattr("found_dimension", format!("{:?}", found)) {
|
|
92
|
+
return e;
|
|
93
|
+
}
|
|
94
|
+
if let Some(sug) = suggestion {
|
|
95
|
+
if let Err(e) = exc_obj.setattr("suggestion", sug) {
|
|
96
|
+
return e;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
exc
|
|
101
|
+
}
|
|
102
|
+
ValidationError::UndefinedReference {
|
|
103
|
+
reference_type,
|
|
104
|
+
name,
|
|
105
|
+
suggestion,
|
|
106
|
+
..
|
|
107
|
+
} => {
|
|
108
|
+
let message = format!("Undefined {}: '{}'", reference_type, name);
|
|
109
|
+
let exc = PyException::new_err(message);
|
|
110
|
+
let exc_obj = exc.value(py);
|
|
111
|
+
|
|
112
|
+
if let Err(e) = exc_obj.setattr("code", code) {
|
|
113
|
+
return e;
|
|
114
|
+
}
|
|
115
|
+
if let Err(e) = exc_obj.setattr("error_type", "ReferenceError") {
|
|
116
|
+
return e;
|
|
117
|
+
}
|
|
118
|
+
if let Err(e) = exc_obj.setattr("reference_type", reference_type.to_string()) {
|
|
119
|
+
return e;
|
|
120
|
+
}
|
|
121
|
+
if let Err(e) = exc_obj.setattr("name", name) {
|
|
122
|
+
return e;
|
|
123
|
+
}
|
|
124
|
+
if let Some(sug) = suggestion {
|
|
125
|
+
if let Err(e) = exc_obj.setattr("suggestion", sug) {
|
|
126
|
+
return e;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
exc
|
|
131
|
+
}
|
|
132
|
+
ValidationError::ScopeError {
|
|
133
|
+
variable,
|
|
134
|
+
suggestion,
|
|
135
|
+
..
|
|
136
|
+
} => {
|
|
137
|
+
let message = format!("Variable '{}' not in scope", variable);
|
|
138
|
+
let exc = PyException::new_err(message);
|
|
139
|
+
let exc_obj = exc.value(py);
|
|
140
|
+
|
|
141
|
+
if let Err(e) = exc_obj.setattr("code", code) {
|
|
142
|
+
return e;
|
|
143
|
+
}
|
|
144
|
+
if let Err(e) = exc_obj.setattr("error_type", "ScopeError") {
|
|
145
|
+
return e;
|
|
146
|
+
}
|
|
147
|
+
if let Err(e) = exc_obj.setattr("variable", variable) {
|
|
148
|
+
return e;
|
|
149
|
+
}
|
|
150
|
+
if let Some(sug) = suggestion {
|
|
151
|
+
if let Err(e) = exc_obj.setattr("suggestion", sug) {
|
|
152
|
+
return e;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
exc
|
|
157
|
+
}
|
|
158
|
+
ValidationError::DuplicateDeclaration {
|
|
159
|
+
name,
|
|
160
|
+
first_location,
|
|
161
|
+
second_location,
|
|
162
|
+
} => {
|
|
163
|
+
let message = format!(
|
|
164
|
+
"Duplicate declaration of '{}': first at {}, duplicate at {}",
|
|
165
|
+
name, first_location, second_location
|
|
166
|
+
);
|
|
167
|
+
let exc = PyException::new_err(message);
|
|
168
|
+
let exc_obj = exc.value(py);
|
|
169
|
+
|
|
170
|
+
if let Err(e) = exc_obj.setattr("code", code) {
|
|
171
|
+
return e;
|
|
172
|
+
}
|
|
173
|
+
if let Err(e) = exc_obj.setattr("error_type", "DuplicateDeclaration") {
|
|
174
|
+
return e;
|
|
175
|
+
}
|
|
176
|
+
if let Err(e) = exc_obj.setattr("name", name) {
|
|
177
|
+
return e;
|
|
178
|
+
}
|
|
179
|
+
if let Err(e) = exc_obj.setattr("first_location", first_location) {
|
|
180
|
+
return e;
|
|
181
|
+
}
|
|
182
|
+
if let Err(e) = exc_obj.setattr("second_location", second_location) {
|
|
183
|
+
return e;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
exc
|
|
187
|
+
}
|
|
188
|
+
ValidationError::DeterminismError { message, hint } => {
|
|
189
|
+
let exc = PyException::new_err(message);
|
|
190
|
+
let exc_obj = exc.value(py);
|
|
191
|
+
|
|
192
|
+
if let Err(e) = exc_obj.setattr("code", code) {
|
|
193
|
+
return e;
|
|
194
|
+
}
|
|
195
|
+
if let Err(e) = exc_obj.setattr("error_type", "DeterminismError") {
|
|
196
|
+
return e;
|
|
197
|
+
}
|
|
198
|
+
if let Err(e) = exc_obj.setattr("hint", hint) {
|
|
199
|
+
return e;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
exc
|
|
203
|
+
}
|
|
204
|
+
ValidationError::InvalidExpression {
|
|
205
|
+
message,
|
|
206
|
+
suggestion,
|
|
207
|
+
..
|
|
208
|
+
} => {
|
|
209
|
+
let exc = PyException::new_err(message);
|
|
210
|
+
let exc_obj = exc.value(py);
|
|
211
|
+
|
|
212
|
+
if let Err(e) = exc_obj.setattr("code", code) {
|
|
213
|
+
return e;
|
|
214
|
+
}
|
|
215
|
+
if let Err(e) = exc_obj.setattr("error_type", "InvalidExpression") {
|
|
216
|
+
return e;
|
|
217
|
+
}
|
|
218
|
+
if let Some(sug) = suggestion {
|
|
219
|
+
if let Err(e) = exc_obj.setattr("suggestion", sug) {
|
|
220
|
+
return e;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
exc
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
//! Python bindings for the SEA formatter.
|
|
2
|
+
|
|
3
|
+
use crate::formatter::{format, FormatConfig, IndentStyle};
|
|
4
|
+
use pyo3::exceptions::PyValueError;
|
|
5
|
+
use pyo3::prelude::*;
|
|
6
|
+
|
|
7
|
+
/// Format SEA-DSL source code.
|
|
8
|
+
///
|
|
9
|
+
/// Args:
|
|
10
|
+
/// source: The SEA-DSL source code to format
|
|
11
|
+
/// indent_width: Number of spaces per indent level (default: 4)
|
|
12
|
+
/// use_tabs: Use tabs instead of spaces for indentation (default: false)
|
|
13
|
+
/// preserve_comments: Preserve comments in output (default: true)
|
|
14
|
+
/// sort_imports: Sort imports alphabetically (default: true)
|
|
15
|
+
///
|
|
16
|
+
/// Returns:
|
|
17
|
+
/// The formatted source code
|
|
18
|
+
///
|
|
19
|
+
/// Raises:
|
|
20
|
+
/// ValueError: If the source code cannot be parsed
|
|
21
|
+
///
|
|
22
|
+
/// Example:
|
|
23
|
+
/// >>> from domainforge import format_source
|
|
24
|
+
/// >>> formatted = format_source('Entity "Foo" in bar')
|
|
25
|
+
/// >>> print(formatted)
|
|
26
|
+
/// Entity "Foo" in bar
|
|
27
|
+
#[pyfunction]
|
|
28
|
+
#[pyo3(signature = (source, indent_width=4, use_tabs=false, preserve_comments=true, sort_imports=true))]
|
|
29
|
+
pub fn format_source(
|
|
30
|
+
source: &str,
|
|
31
|
+
indent_width: usize,
|
|
32
|
+
use_tabs: bool,
|
|
33
|
+
preserve_comments: bool,
|
|
34
|
+
sort_imports: bool,
|
|
35
|
+
) -> PyResult<String> {
|
|
36
|
+
let config = FormatConfig {
|
|
37
|
+
indent_width,
|
|
38
|
+
indent_style: if use_tabs {
|
|
39
|
+
IndentStyle::Tabs
|
|
40
|
+
} else {
|
|
41
|
+
IndentStyle::Spaces
|
|
42
|
+
},
|
|
43
|
+
preserve_comments,
|
|
44
|
+
sort_imports,
|
|
45
|
+
..Default::default()
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
format(source, config).map_err(|e| PyValueError::new_err(e.to_string()))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/// Check if SEA-DSL source code is already formatted.
|
|
52
|
+
///
|
|
53
|
+
/// Args:
|
|
54
|
+
/// source: The SEA-DSL source code to check
|
|
55
|
+
/// indent_width: Number of spaces per indent level (default: 4)
|
|
56
|
+
/// use_tabs: Use tabs instead of spaces for indentation (default: false)
|
|
57
|
+
///
|
|
58
|
+
/// Returns:
|
|
59
|
+
/// True if the source is already formatted, False otherwise
|
|
60
|
+
///
|
|
61
|
+
/// Raises:
|
|
62
|
+
/// ValueError: If the source code cannot be parsed
|
|
63
|
+
///
|
|
64
|
+
/// Example:
|
|
65
|
+
/// >>> from domainforge import check_format
|
|
66
|
+
/// >>> check_format('Entity "Foo" in bar\\n')
|
|
67
|
+
/// True
|
|
68
|
+
/// >>> check_format('Entity "Foo" in bar')
|
|
69
|
+
/// False
|
|
70
|
+
#[pyfunction]
|
|
71
|
+
#[pyo3(signature = (source, indent_width=4, use_tabs=false))]
|
|
72
|
+
pub fn check_format(source: &str, indent_width: usize, use_tabs: bool) -> PyResult<bool> {
|
|
73
|
+
let config = FormatConfig {
|
|
74
|
+
indent_width,
|
|
75
|
+
indent_style: if use_tabs {
|
|
76
|
+
IndentStyle::Tabs
|
|
77
|
+
} else {
|
|
78
|
+
IndentStyle::Spaces
|
|
79
|
+
},
|
|
80
|
+
..Default::default()
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
let formatted = format(source, config).map_err(|e| PyValueError::new_err(e.to_string()))?;
|
|
84
|
+
|
|
85
|
+
Ok(source == formatted)
|
|
86
|
+
}
|