Skip to content

ProxyGenerator: derived types, flags enums, and assembly-to-package mappings#2187

Merged
einari merged 16 commits into
mainfrom
feature/proxy-generator-derived-types-support
May 3, 2026
Merged

ProxyGenerator: derived types, flags enums, and assembly-to-package mappings#2187
einari merged 16 commits into
mainfrom
feature/proxy-generator-derived-types-support

Conversation

@einari
Copy link
Copy Markdown
Contributor

@einari einari commented May 2, 2026

Added

  • Support for derived types (polymorphic shapes) in proxy generation — commands and queries that use a base type with derived subtypes now generate correct TypeScript union types
  • [Flags] enum support — enums decorated with [Flags] are generated using a dedicated template that emits an allXxx constant combining all non-zero members with bitwise OR, e.g. export const allAnchorEdges = AnchorEdges.top | AnchorEdges.right | AnchorEdges.bottom | AnchorEdges.left

einari and others added 4 commits May 2, 2026 18:48
Detect types decorated with [DerivedType] and their concrete subtypes.
Generated TypeScript now emits @derivedType(id) on derived classes and
@field(Base, false, [Derived1, Derived2]) on properties whose base type
has registered derivatives, enabling the @cratis/fundamentals
JsonSerializer to resolve the correct class from _derivedTypeId on
deserialization.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sort type loading so [DerivedType]-decorated classes load before types
that reference them, ensuring @field derivatives arrays are fully
populated. Rewrite deserialize-query-result.js to instantiate the
correct derived class when _derivedTypeId matches, while preserving raw
values for special types (TimeSpan, Guid) so C# re-deserialization
remains correct.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Verify the full data flow from C# (IShape/CircleShape/RectangleShape with
[DerivedType] attributes) through the TypeScript proxy to correctly
instantiated JavaScript objects. Specs assert both the concrete type
(constructor.name) and the type-specific property values.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@einari einari added the minor label May 2, 2026
Comment thread Source/DotNET/Tools/ProxyGenerator/TypeExtensions.cs Fixed
einari and others added 11 commits May 2, 2026 19:09
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Verifies that a model-bound command with two IShape properties correctly
round-trips through the JavaScript proxy: the C# serializer adds
_derivedTypeId discriminators, the proxy POSTs them to the server, and
DerivedTypeJsonConverterFactory resolves CircleShape and RectangleShape
on the receiving end.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ping to AssemblyToPackageMapping

Agent-Logs-Url: https://github.com/Cratis/Arc/sessions/ae058189-02e3-477c-a131-5c0cd4a543da

Co-authored-by: einari <134365+einari@users.noreply.github.com>
…le multi-project example

Agent-Logs-Url: https://github.com/Cratis/Arc/sessions/fd53fd75-bc6a-4d3e-ab26-8c3680af0e37

Co-authored-by: einari <134365+einari@users.noreply.github.com>
…ect'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
…in configuration.md

Agent-Logs-Url: https://github.com/Cratis/Arc/sessions/560ada5c-342f-4fbc-acc8-1f0bed712c4b

Co-authored-by: einari <134365+einari@users.noreply.github.com>
Enums decorated with [Flags] are now generated using a dedicated FlagsEnum.hbs
Handlebars template that emits an allXxx constant combining all non-zero members
with the bitwise OR operator, e.g. allAnchorEdges = AnchorEdges.top | AnchorEdges.right | ...

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Combines flags enum template support with assembly-to-package mappings.
Both regular and flags enum descriptors now respect IsFromMappedAssembly()
so types from mapped assemblies are imported from their package rather than
generated locally.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@einari einari changed the title Support DerivedTypes in ProxyGenerator ProxyGenerator: derived types, flags enums, and assembly-to-package mappings May 3, 2026
Comment on lines +76 to +79
catch
{
_typeScriptIsValid = false;
}
Comment on lines +43 to +46
catch
{
_typeScriptIsValid = false;
}
@einari
Copy link
Copy Markdown
Contributor Author

einari commented May 3, 2026

…ution with assembly mapping tests

Agent-Logs-Url: https://github.com/Cratis/Arc/sessions/4e4616c6-ce78-4fbe-9134-28dec756ed85

Co-authored-by: einari <134365+einari@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented May 3, 2026

@copilot Fix the broken build; https://github.com/Cratis/Arc/actions/runs/25275672739/job/74105139264?pr=2187

Fixed in 0748739.

The test should_generate_identity_details_user_role_import was failing due to a test isolation race condition introduced by the new assembly mapping tests. Those tests temporarily map the specs assembly to an npm package in static state (TypeExtensions._assemblyPackageMappings). When when_generating_types_for_identity_details_with_nested_complex_types ran in parallel, UserRole.IsFromMappedAssembly() returned true, which prevented the UserRole type from being collected in typesInvolved, so no import statement was generated for it.

The fix adds [Collection(AssemblyPackageMappingCollectionDefinition.Name)] to the test class, ensuring it runs sequentially with the assembly mapping tests rather than concurrently.

Copilot finished work on behalf of einari May 3, 2026 10:19
@einari
Copy link
Copy Markdown
Contributor Author

einari commented May 3, 2026

@copilot Merge main into this and rebase - fix any conflicts.

Copy link
Copy Markdown
Contributor

Copilot AI commented May 3, 2026

@copilot Merge main into this and rebase - fix any conflicts.

The branch is already fully up to date with main. origin/main is at eef5197e, which is the exact commit this feature branch diverged from — main has not advanced since then, so there are no new commits to merge in and no conflicts to resolve.

Copilot finished work on behalf of einari May 3, 2026 10:24
@einari einari merged commit eb4ecfc into main May 3, 2026
16 checks passed
@einari einari deleted the feature/proxy-generator-derived-types-support branch May 3, 2026 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants