npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

dataverse-type-gen

v1.3.6

Published

TypeScript type generator for Dataverse entities and metadata

Downloads

108

Readme

Dataverse Type Generator

Generate TypeScript types from Microsoft Dataverse metadata.

⚠️ CAUTION: AI-Generated Code

This project was developed using AI assistance (Claude Code). Users should evaluate the code thoroughly before production use.

Features

  • CLI for automated type generation
  • Generate types by entities, publisher, or solution
  • TypeScript interfaces and choice value enums
  • Azure Identity integration for authentication
  • Optional React Query hooks and query builders

Quick Start

Basic Usage

# Initialize configuration
npx dataverse-type-gen init

# Generate types for specific entities
npx dataverse-type-gen generate --entities account,contact,opportunity

# Generate types for all entities from a publisher  
npx dataverse-type-gen generate --publisher your_prefix

# Generate types from a solution
npx dataverse-type-gen generate --solution "My Solution"

# Preview without creating files
npx dataverse-type-gen generate --entities account --dry-run

Installation

npm install dataverse-type-gen

Environment Setup

Set your Dataverse instance URL:

export DATAVERSE_INSTANCE="https://yourorg.crm.dynamics.com"

Or specify via CLI:

npx dataverse-type-gen generate --dataverse-url https://yourorg.crm.dynamics.com --entities account

Generated Types

Entity Interfaces

// Generated from account entity
export interface Account {
  accountid?: string
  name?: string
  telephone1?: string
  accountcategorycode?: AccountCategoryCode
  // ... all attributes with proper TypeScript types
}

Choice/Option Set Enums

export const AccountCategoryCode = {
  PreferredCustomer: { Value: 1, Label: "Preferred Customer" },
  Standard: { Value: 2, Label: "Standard" },
  // ... all choice values with labels
} as const

export type AccountCategoryCode = (typeof AccountCategoryCode)[keyof typeof AccountCategoryCode]["Value"]

Lookup Properties & Bindings

Generates lookup properties (_xx_value) and type-safe @odata.bind helpers:

export interface Account {
  primarycontactid?: string
  _primarycontactid_value?: string; // Lookup property - GUID value
}

export type AccountBindings = {
  '[email protected]'?: string; // Bind to: contact
};

export const AccountBindings = {
  primarycontactid: (id: string) => ({ '[email protected]': `/contacts(${id})` })
};

React Query Hooks

When generateHooks: true is enabled, the generator creates type-safe React Query hooks:

import { useAccountList, useAccount } from './generated'

// List accounts with type-safe filtering
const { data: accounts } = useAccountList({
  $select: ['name', 'telephone1'], // ✅ IntelliSense support
  $filter: { name: { $contains: 'contoso' } },
  $top: 10
})

// Get single account
const { data: account } = useAccount(accountId, {
  $select: ['name', 'primarycontactid']
})

Query Builders with Type-Safe Filtering

Query Building: The generator creates query builders with type-safe OData filtering for URL construction:

import { AccountQueries } from './generated/queries/account.queries'

// Build URLs with full transparency - you can see exactly what's generated
const listUrl = AccountQueries.buildListUrl({
  $filter: { name: { $contains: 'contoso' } },
  $select: ['name', 'telephone1'],
  $orderby: { name: 'asc' },
  $top: 10
})
// Result: /api/data/v9.2/accounts?$filter=contains(name,'contoso')&$select=name,telephone1&$orderby=name asc&$top=10

const singleUrl = AccountQueries.buildEntityUrl(accountId, {
  $select: ['name', 'primarycontactid']
})

const countUrl = AccountQueries.buildCountUrl({
  $filter: { statecode: 0 }
})

Query Builder Benefits:

  • Generated code is visible and modifiable
  • No abstraction layer to troubleshoot
  • Edit generated functions for specific needs
  • TypeScript support with entity-specific types
  • Each entity has its own query logic

Additional Features

Type-Safe Expand Support

Query builders support type-safe expand operations with IntelliSense and compile-time validation for related entities.

Configuration

Configuration File (dataverse.config.json)

{
  "dataverseUrl": "https://yourorg.crm.dynamics.com",
  "outputDir": "./generated",
  "fileExtension": ".ts",
  "entities": ["account", "contact", "opportunity"],
  "publisher": "your_prefix",
  "solution": "Your Solution Name",
  "fullMetadata": false,
  "typeGeneration": {
    "includeComments": true,
    "useExactTypes": true,
    "generateHooks": false
  }
}

Environment Variables

| Variable | Description | Example | |----------|-------------|---------| | DATAVERSE_INSTANCE | Dataverse instance URL | https://yourorg.crm.dynamics.com |

Authentication

This package uses Azure Identity for secure authentication with multiple credential providers:

Supported Authentication Methods

  1. Azure CLI - az login (recommended for development)
  2. Managed Identity - Automatic in Azure environments
  3. Environment Variables - AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_TENANT_ID
  4. Visual Studio/VS Code - Integrated Azure extensions

Required Permissions

  • Dataverse User: App user with read permissions on metadata

License

MIT License - see LICENSE file for details.