Generate typings for multi-select picklist, file and image columns via AttributeTypeName#333
Open
Cordedmink2 wants to merge 5 commits into
Open
Conversation
… test output hygiene
… and boolean control types
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Dataverse typings generator to key off AttributeTypeName.Value (instead of legacy AttributeType) so newer column types like multi-select picklists, file, and image columns are correctly included in generated getAttribute/getControl signatures. It also makes form-eligibility filtering use IsValidForForm, fixes an async enum-resolution race, and introduces a VS Code–independent builder with unit tests.
Changes:
- Reworked typings generation via a new
typingsBuilderhelper that mapsAttributeTypeName.Valueto@types/xrmattribute/control types (including multi-select) and filters output usingIsValidForForm. - Fixed enum generation ordering/race by awaiting enum-resolution work and aligned enum emission with the same filtered attribute set as signature generation.
- Added a Node-friendly unit-test harness (
tsconfig.tests.json,test:unit, mocha tests) and bumped template@types/xrmto^9.0.68to ensure scaffolded projects compile with the new signatures.
Reviewed changes
Copilot reviewed 9 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tsconfig.tests.json | Adds a dedicated TS config for compiling mocha unit tests to out-tests. |
| src/utils/Interfaces.ts | Extends attribute metadata typing with IsValidForForm used by the generator filter. |
| src/test/unit/typingsBuilder.test.ts | Adds unit coverage for filtering, mapping, enum resolution awaiting, and emitted output. |
| src/helpers/typingsHelper.ts | Switches VS Code command path to call the new builder and write emitted typings output. |
| src/helpers/typingsBuilder.ts | New core builder: filtering, type mapping keyed by AttributeTypeName.Value, enum generation, and emission. |
| resources/templates/Webpack/package.json | Bumps @types/xrm to a version that includes multi-select and BooleanControl typings. |
| resources/templates/TypeScript/package.json | Bumps @types/xrm to ^9.0.68. |
| resources/templates/JavaScript/package.json | Bumps @types/xrm to ^9.0.68. |
| package.json | Adds test:unit script to compile/run mocha unit tests. |
| .gitignore | Ignores the unit-test build output directory out-tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Author
|
@Power-Maverick This ok? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Generating typings for an entity with multi-select picklist (Choices) columns produces their option-value enums but no
getAttribute/getControlsignatures — addresses #313 (closed by the stale bot; I'm the original reporter and this delivers the PR discussed there). Root cause: generation filters on the legacyAttributeTypeproperty, where multi-select, file and image columns all reportVirtual, so they were dropped before the type maps were ever consulted. Microsoft's guidance is to useAttributeTypeNamefor anything newer than the original 2011 type set.Changes
AttributeTypeName.Valuewith a whitelist map: multi-selects map toAttributes.MultiSelectOptionSetAttribute/Controls.MultiSelectOptionSetControl, booleans now getControls.BooleanControl(previously genericStandardControl), and file/image columns are included with conservative fallback types (Attributes.Attribute/Controls.StandardControl) since@types/xrmhas no dedicated interfaces for them. The docs listfile/imageas validgetAttributeType()values but don't document theirgetControlType(); these fallbacks are deliberately conservative, and I'll follow up with observed runtime values from a live form.IsValidForFormmetadata property instead of being inferred from type names.formContext.getAttribute()are no longer emitted. Dropped categories: primary ids / uniqueidentifier, entityname, managedproperty, calendarrules, plain virtual companion columns (e.g.*nameshadows), and bigint (absent from the documentedgetAttributeType()values, and JS numbers can't safely hold all 64-bit values). Previously these were emitted with misleading types — e.g.accountidtyped asStringAttributewhengetAttribute("accountid")returns null at runtime. Projects referencing those signatures will see compile errors after regenerating; that's the output telling the truth now.AttributeOfcompanion columns..forEach(async ...)and never awaited before the file was emitted — they only landed in the output because the directory QuickPick stalls long enough. Resolution is now awaited (Promise.all) with a regression test.src/helpers/typingsBuilder.tswith mocha unit tests (npm run test:unit, 11 tests). The new script exists because the currentpretest/testchain can't run:pretestcalls a nonexistentcompile-testsscript,tsconfig.jsonexcludessrc/test/**, andrunTest.tsimports the legacyvscode-testpackage. That harness is left untouched here;test:unitis additive and reuses the existing mocha devDependency.@types/xrm^9.0.68— the minimum version containingMultiSelectOptionSetAttribute/MultiSelectOptionSetControl(9.0.68) andBooleanControl(9.0.63). Without this, freshly generated typings don't compile in scaffolded projects. Note on the lockfile diff: the TypeScript template'spackage-lock.jsonshows ~4,800 changed lines because npm ≥7 can't writelockfileVersion: 1— the regeneration upgrades it to v2 (readable by npm 6+). The real change is just the@types/xrmbump.Known limitation
IsValidForFormmeans a column can be placed on a form —getAttribute/getControlstill returnnullat runtime when the column isn't on the loaded form. Generated signatures stay non-null, matching@types/xrm@9.0.68's own base signatures and the tool's existing behavior.Testing
npm run compile,npm run lint(no new warnings), andnpm run test:unit(11 tests: type-map coverage, filter exclusions, sort determinism, input non-mutation, resolver scoping, race regression, emitted-signature assertions) all pass.tsc --strictagainst exactly@types/xrm@9.0.68, and fails against9.0.41with the expected missing-member errors — confirming the template bump is required.AttributeType = "Virtual";statecode/statuscodereportStateType/StatusTypewithIsValidForForm = true; primary ids reportIsValidForForm = false.