Skip to content

refactor: extract shared types and utility functions to mdl/types#234

Closed
retran wants to merge 2 commits intomendixlabs:mainfrom
retran:feature/shared-types-1-extract-types
Closed

refactor: extract shared types and utility functions to mdl/types#234
retran wants to merge 2 commits intomendixlabs:mainfrom
retran:feature/shared-types-1-extract-types

Conversation

@retran
Copy link
Copy Markdown
Contributor

@retran retran commented Apr 19, 2026

Summary

  • Extract shared types (EdmxDocument, AsyncAPIDocument, JsonStructure, ImageCollection, navigation types, Java types, mapping types) from sdk/mpr into new mdl/types package
  • Extract IDToBsonBinary/BsonBinaryToID into new mdl/bsonutil package
  • Migrate mdl/catalog to use mdl/types instead of sdk/mpr
  • Add type aliases in sdk/mpr for backward compatibility

Why

The executor layer (mdl/) currently imports sdk/mpr for type definitions, creating a circular dependency that prevents alternative backend implementations. Extracting shared types into mdl/types breaks this coupling.

Stack

This is PR 1/5 in the shared-types stack:

  1. → This PR: Extract shared types to mdl/types
  2. Define mutation backend interfaces
  3. Implement mutation backends and migrate handlers
  4. Decouple executor from storage layer
  5. Code quality polish

Depends on PR #232 (mock handler tests).

retran added 2 commits April 19, 2026 15:06
Phase 1-8: 85 read/write handler tests with mock backend infrastructure
Error paths: 49 tests covering backend error propagation for all handler groups
Not-connected: 29 tests verifying Connected/ConnectedForWrite guards
JSON format: 26 tests validating JSON output for show/list handlers

Production code changes:
- Added Func fields to MockBackend for 8 agent-editor write methods
- Fixed ContainerID parameter semantics in withContainer and all call sites
Create mdl/types/ package with WASM-safe shared types extracted from
sdk/mpr: domain model types, ID utilities, EDMX/AsyncAPI parsing,
JSON formatting helpers. Migrate all executor handlers to use
mdl/types directly, removing type aliases from sdk/mpr/reader_types.go.

- Extract 16+ domain types to mdl/types/ (infrastructure, java,
  navigation, mapping)
- Extract GenerateID, BlobToUUID, ValidateID to mdl/types/id.go
- Extract ParseEdmx, ParseAsyncAPI to mdl/types/edmx.go, asyncapi.go
- Extract PrettyPrintJSON, BuildJsonElementsFromSnippet to json_utils.go
- Migrate 30+ executor handler files off sdk/mpr type references
- sdk/mpr retains thin delegation wrappers for backward compatibility
Copilot AI review requested due to automatic review settings April 19, 2026 17:35
@retran
Copy link
Copy Markdown
Contributor Author

retran commented Apr 19, 2026

Closing — renaming branches and recreating stacked PRs with descriptive names.

@retran retran closed this Apr 19, 2026
@retran retran deleted the feature/shared-types-1-extract-types branch April 19, 2026 17:36
@github-actions
Copy link
Copy Markdown

AI Code Review

What Looks Good

This PR successfully extracts shared types from sdk/mpr into mdl/types to break a circular dependency, which is a well-scoped architectural improvement. The changes are:

  • Consistently applied: All backend interfaces, mock implementations, and related code are uniformly updated to use mdl/types instead of sdk/mpr
  • Properly scoped: Focused solely on extracting types and utilities without mixing in unrelated changes
  • Backward compatible: Mentions adding type aliases in sdk/mpr for compatibility (though not visible in the truncated diff)
  • Well-structured: Conversion functions in mdl/backend/mpr/convert.go provide clean translation between type systems
  • Test-aware: Depends on PR feat: add comprehensive mock-based handler tests (189 tests) #232 for mock handler tests, suggesting test coverage is being handled appropriately
  • Follows patterns: Uses established conversion patterns seen elsewhere in the codebase

The refactor touches many files but maintains a single clear purpose: breaking the mdl/sdk/mpr circular dependency by moving shared types to a neutral location (mdl/types).

Recommendation

Approve the PR. The refactor is correctly implemented, follows the project's architectural goals, and maintains consistency across the codebase. The approach of extracting shared types with conversion functions is sound and properly scoped. Verification should confirm that:

  1. The mdl/types package contains the expected type definitions
  2. Backward compatibility aliases exist in sdk/mpr
  3. All tests pass (especially given the dependency on PR feat: add comprehensive mock-based handler tests (189 tests) #232 for mock tests)

Automated review via OpenRouter (Nemotron Super 120B) — workflow source

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR continues the MDL decoupling effort by moving shared value types and ID/UUID utilities out of sdk/mpr into a new mdl/types package, then updating executor/catalog/backend layers to depend on mdl/types rather than sdk/mpr (reducing coupling and enabling alternate backends).

Changes:

  • Introduce mdl/types with shared document/value types (navigation, mappings, Java descriptors, infra types, AsyncAPI, ID utilities).
  • Refactor mdl/backend/*, mdl/catalog/*, mdl/executor/*, and related code to use mdl/types in public interfaces and logic.
  • Update sdk/mpr implementations to use mdl/types (including delegations and some type-aliasing/delegation for selected parsers).

Reviewed changes

Copilot reviewed 108 out of 111 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
sdk/mpr/writer_imagecollection_test.go Update tests to use types.ImageCollection.
sdk/mpr/writer_imagecollection.go Writer image-collection APIs now consume types.ImageCollection.
sdk/mpr/writer_core.go Delegate UUID/blob helpers to mdl/types.
sdk/mpr/utils.go Delegate ID/hash/UUID helpers to mdl/types and re-implement BSON ID conversion.
sdk/mpr/reader.go Delegate blob→UUID formatting to mdl/types.
sdk/mpr/parser_misc.go Switch parsed document return types to mdl/types equivalents.
sdk/mpr/asyncapi.go Move AsyncAPI types to mdl/types via aliases + delegate parser.
mdl/visitor/visitor_agenteditor.go Minor whitespace cleanup.
mdl/types/navigation.go New navigation document/profile/menu value types.
mdl/types/mapping.go New JSON structure + image collection value types.
mdl/types/java.go New lightweight Java/JS action descriptor types.
mdl/types/infrastructure.go New shared infra/value types (versions, folder/unit info, raw-unit wrappers, rename hits, security structs).
mdl/types/id.go New shared ID/UUID/hash helpers.
mdl/types/doc.go Package documentation for shared value types.
mdl/types/asyncapi.go AsyncAPI parsing/types moved here from sdk/mpr.
mdl/linter/rules/page_navigation_security.go Linter updated to traverse types.NavMenuItem.
mdl/executor/widget_templates.go Use types.GenerateID for widget template IDs.
mdl/executor/widget_operations.go Use types.GenerateID when creating translation IDs.
mdl/executor/widget_engine.go Use types.GenerateID callback/IDs for widget build.
mdl/executor/mock_test_helpers_test.go New executor mock test helpers (ctx, hierarchy, factories, assertions).
mdl/executor/helpers.go Use types.FolderInfo and types.GenerateID for folder creation.
mdl/executor/executor.go Executor caches now store types.UnitInfo / types.FolderInfo.
mdl/executor/cmd_write_handlers_mock_test.go New mock tests for write handlers.
mdl/executor/cmd_workflows_write.go Use types.GenerateID for workflow element IDs.
mdl/executor/cmd_workflows_mock_test.go New workflow handler mock tests.
mdl/executor/cmd_settings_mock_test.go New settings handler mock tests.
mdl/executor/cmd_security_write.go Use types.EntityMemberAccess / types.EntityAccessRevocation.
mdl/executor/cmd_security_mock_test.go New security handler mock tests.
mdl/executor/cmd_rest_clients_mock_test.go New REST client handler mock tests.
mdl/executor/cmd_rename.go Switch rename report plumbing to types.RenameHit.
mdl/executor/cmd_published_rest_mock_test.go New published REST handler mock tests.
mdl/executor/cmd_pages_mock_test.go New pages/layouts handler mock tests.
mdl/executor/cmd_pages_builder_v3_layout.go Use types.GenerateID for V3 page builder nodes.
mdl/executor/cmd_pages_builder.go Folder cache now uses types.FolderInfo (plus related changes).
mdl/executor/cmd_odata_mock_test.go New OData handler mock tests.
mdl/executor/cmd_odata.go Use types.GenerateID + types.ParseEdmx.
mdl/executor/cmd_notconnected_mock_test.go New not-connected guard mock tests.
mdl/executor/cmd_navigation_mock_test.go New navigation handler mock tests using mdl/types.
mdl/executor/cmd_navigation.go Navigation writer spec/types switched to mdl/types.
mdl/executor/cmd_modules_mock_test.go New modules handler mock tests using types.UnitInfo.
mdl/executor/cmd_misc_mock_test.go New version handler mock tests using types.ProjectVersion.
mdl/executor/cmd_microflows_mock_test.go New microflows handler mock tests.
mdl/executor/cmd_microflows_create.go Use types.GenerateID for microflow IDs/params.
mdl/executor/cmd_microflows_builder_workflow.go Use types.GenerateID for workflow-related microflow objects.
mdl/executor/cmd_microflows_builder_graph.go Use types.GenerateID for microflow graph objects.
mdl/executor/cmd_microflows_builder_flows.go Use types.GenerateID for sequence flows/cases/events.
mdl/executor/cmd_microflows_builder_control.go Use types.GenerateID for control-flow microflow objects.
mdl/executor/cmd_microflows_builder_annotations.go Use types.GenerateID for annotations and flows.
mdl/executor/cmd_mermaid_mock_test.go New mermaid describe mock test.
mdl/executor/cmd_jsonstructures_mock_test.go New JSON structures handler mock test using mdl/types.
mdl/executor/cmd_jsonstructures.go Switch JSON helpers/types to mdl/types.
mdl/executor/cmd_javascript_actions_mock_test.go New JS action handler mock tests using mdl/types.
mdl/executor/cmd_javaactions_mock_test.go New Java action handler mock tests.
mdl/executor/cmd_javaactions.go Use types.GenerateID for Java action model construction.
mdl/executor/cmd_import_mappings_mock_test.go New import mappings handler mock test.
mdl/executor/cmd_import_mappings.go Switch JSON structure element map types to mdl/types.
mdl/executor/cmd_imagecollections_mock_test.go New image collections handler mock tests using mdl/types.
mdl/executor/cmd_imagecollections.go Switch image collection types to mdl/types.
mdl/executor/cmd_fragments_mock_test.go New fragments handler mock tests.
mdl/executor/cmd_folders.go Use types.FolderInfo in folder path resolution.
mdl/executor/cmd_export_mappings_mock_test.go New export mappings handler mock test.
mdl/executor/cmd_export_mappings.go Switch JSON structure element map types to mdl/types.
mdl/executor/cmd_enumerations_mock_test.go Refactor enumeration tests to new mock helpers + add describe/notfound coverage.
mdl/executor/cmd_entities_mock_test.go New entities handler mock tests.
mdl/executor/cmd_entities.go Use types.GenerateID for entity construction (attrs/vr/index IDs).
mdl/executor/cmd_dbconnection_mock_test.go New DB connection handler mock tests.
mdl/executor/cmd_datatransformer_mock_test.go New data transformer handler mock tests.
mdl/executor/cmd_constants_mock_test.go New constants handler mock tests.
mdl/executor/cmd_businessevents_mock_test.go New business events handler mock tests.
mdl/executor/cmd_businessevents.go Use types.GenerateID for channel name generation.
mdl/executor/cmd_associations_mock_test.go New associations handler mock tests.
mdl/executor/cmd_agenteditor_write.go Formatting-only alignment in agent creation struct literal.
mdl/executor/cmd_agenteditor_models.go Formatting-only alignment in model creation struct literal.
mdl/executor/cmd_agenteditor_mock_test.go New agent editor handlers mock tests.
mdl/catalog/builder_references.go Catalog navigation reference extraction now uses types.NavMenuItem.
mdl/catalog/builder_navigation.go Catalog navigation builder now uses mdl/types menu items.
mdl/catalog/builder_contract.go Catalog contract parsing uses types.ParseEdmx / types.ParseAsyncAPI.
mdl/catalog/builder.go CatalogReader interface updated to mdl/types for shared structs.
mdl/backend/workflow.go Backend interfaces updated to types.ImageCollection.
mdl/backend/security.go Backend interfaces updated to types.EntityMemberAccess/revocation.
mdl/backend/navigation.go Backend interfaces updated to types.NavigationDocument/spec.
mdl/backend/mpr/backend.go MPR backend converts between sdk/mpr and mdl/types across interfaces.
mdl/backend/mock/mock_workflow.go Mock backend updated for types.ImageCollection.
mdl/backend/mock/mock_security.go Mock backend updated for types.EntityAccessRevocation.
mdl/backend/mock/mock_navigation.go Mock backend updated for navigation mdl/types.
mdl/backend/mock/mock_module.go Mock backend updated for types.FolderInfo.
mdl/backend/mock/mock_mapping.go Mock backend updated for types.JsonStructure.
mdl/backend/mock/mock_java.go Mock backend updated for types.JavaAction/types.JavaScriptAction.
mdl/backend/mock/mock_infrastructure.go Mock backend updated for mdl/types infra + adds functional AgentEditor write hooks.
mdl/backend/mock/mock_connection.go Mock connection updated to return types.MPRVersion/types.ProjectVersion.
mdl/backend/mock/backend.go MockBackend struct fields migrated from sdk/mpr types to mdl/types.
mdl/backend/mapping.go MappingBackend interface migrated to mdl/types.
mdl/backend/java.go JavaBackend interface migrated to mdl/types.
mdl/backend/infrastructure.go Infra interfaces migrated to mdl/types (rename/raw-unit/widget metadata).
mdl/backend/doc.go Backend package docs updated to reflect mdl/types extraction.
mdl/backend/connection.go Connection/Folder backend interfaces migrated to mdl/types.
internal/marketplace/types.go Minor comment formatting adjustment.
cmd/mxcli/project_tree.go Project tree builder uses types.NavMenuItem for menu rendering.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 306 to 312
currentContainerID = newFolderID

// Add to cache
pb.foldersCache = append(pb.foldersCache, &mpr.FolderInfo{
pb.foldersCache = append(pb.foldersCache, &types.FolderInfo{
ID: newFolderID,
ContainerID: currentContainerID,
Name: part,
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When creating a missing folder, the newly appended FolderInfo sets ContainerID to currentContainerID after it has been updated to newFolderID. This makes the cached folder appear to be its own parent, which will break subsequent lookups/resolution of nested folder paths. Capture the parent container ID before updating currentContainerID, and store that as ContainerID in the cached FolderInfo.

Copilot uses AI. Check for mistakes.
Comment on lines 12 to 15
// CreateImageCollection creates a new empty image collection unit in the MPR.
func (w *Writer) CreateImageCollection(ic *ImageCollection) error {
func (w *Writer) CreateImageCollection(ic *types.ImageCollection) error {
if ic.ID == "" {
ic.ID = model.ID(generateUUID())
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the exported Writer.CreateImageCollection API to accept *types.ImageCollection instead of the previously public *mpr.ImageCollection. Unless sdk/mpr defines type ImageCollection = types.ImageCollection (and callers can keep using mpr.ImageCollection), this is a breaking change for downstream users. Consider adding the missing type alias in sdk/mpr (and optionally switching the signature back to *mpr.ImageCollection via the alias) to preserve backward compatibility as stated in the PR description.

Copilot uses AI. Check for mistakes.
Comment thread sdk/mpr/utils.go
Comment on lines 25 to 40
// IDToBsonBinary converts a UUID string to a BSON binary value.
func IDToBsonBinary(id string) primitive.Binary {
return idToBsonBinary(id)
blob := types.UUIDToBlob(id)
if blob == nil || len(blob) != 16 {
blob = types.UUIDToBlob(types.GenerateID())
}
return primitive.Binary{
Subtype: 0x00,
Data: blob,
}
}

// BsonBinaryToID converts a BSON binary value to a UUID string.
func BsonBinaryToID(bin primitive.Binary) string {
return BlobToUUID(bin.Data)
return types.BlobToUUID(bin.Data)
}
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description says IDToBsonBinary/BsonBinaryToID were extracted into a new mdl/bsonutil package, but this diff keeps these functions in sdk/mpr/utils.go (re-implemented here) and there is no corresponding extraction in the changes shown. Either update the PR description to match the implemented scope, or complete the extraction and have sdk/mpr delegate to mdl/bsonutil for consistency with the stated refactor plan.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants