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 🙏

© 2024 – Pkg Stats / Ryan Hefner

breeze-entity-generator

v1.4.0

Published

Generate TypeScript modules for entities from Breeze metadata

Downloads

523

Readme

Breeze Entity Generator

This tool generates TypeScript classes from Breeze metadata. The generated classes match the server-side classes and the query responses, so you can develop your application with typed entities.

Breeze metadata can be generated from EntityFramework, NHibernate, POCO classes, or handwritten.

Usage: Write your JavaScript file, generate-entities.js:

const  tsGen = require('node_modules/breeze-entity-generator/tsgen-core');

tsGen.generate({
  inputFileName: 'MyProject.metadata.json',
  outputFolder: './src/app/model/entities/',
  camelCase: true,
  kebabCaseFileNames: true,
  baseClassName: 'BaseEntity',
  baseComplexName: 'BaseComplex',
  codePrefix: 'MyProject',
  useEnumTypes: true,
  propertyComments: true
});

Then run node[.exe] generate-entities.js

Input(s): A file containing CSDL or Breeze native metadata

Output(s):

  • One TypeScript module file per entity and complex type, with the corresponding class export.
  • A helper class (RegistrationHelper.ts) to register all constructors with Breeze.
  • A TypeScript barrel (EntityModel.ts) exporting all of the entity classes, for easy import when several classes are required.
  • A helper class (Metadata.ts) that exports the Breeze metadata as a static value, so it can be used by Breeze at runtime.

Config Parameters

inputFileName: Specifies the file containing the metadata

outputFolder: Optionally specifies the location for the generated TypeScript files. If not specified, the current directory is used as the location

sourceFilesFolder: Optionally specifies the location to find existing TypeScript files. The <code> blocks from these files will be preserved in the corresponding output files. If not specified, the outputFolder will be used.

baseClassName: Optionally specifies a TypeScript base class for all the generated entity classes. The generated entity classes will directly or indirectly inherit from this class. The file must contain a single module and exported class.

baseComplexName: Optionally specifies a TypeScript base class for all the generated complex type (value type) classes. The generated classes will directly or indirectly inherit from this class. The file must contain a single module and exported class.

camelCase: Optionally generates the property names using camel case. This parameter has no effect if the input file contains Breeze native metadata. (See NamingConvention)

codePrefix: Name to put in front of the generated Metadata class and the RegistrationHelper class

kebabCaseFileNames: Optionally generate kebab-case-file-names instead of PascalCaseFileNames.

useEnumTypes: Optionally generate an Enums.ts file containing enums defined in the metadata. Only effective if input metadata contains an "enumTypes" section.

propertyComments: Optionally include metadata comments on data properties, indicating original datatype and key relationships, e.g.:

  /** String(50) */
  productName!: string;
  /** Int32 FK supplier */
  supplierId!: number;

Description

At the core of the typescript generator sits handlebars which is responsible for generating the actual TypeScript source code. The output that handlebars generate can be customized by modifying the templates.

Note: node.js must be installed and node must be part of the PATH.

Custom code and imports

The typescript generator preserves three special sections for each class when regenerating the code. Those sections are <code-import>, <code> and <module-code>. The <code-import> section is for custom imports, the <code> section is for custom methods, etc and <module-code> section is for module level code eg functions. Following is an example of a class after it got generated showing the three sections. Everything between the opening and closing tags is preserved.

import { EntityBase } from './EntityBase';
import { Order } from './Order';

/// <code-import> Place custom imports between <code-import> tags

/// </code-import>

/// <module-code> Place module level code between <module-code> tags

/// </module-code>

export class InternationalOrder extends EntityBase {

   /// <code> Place custom code between <code> tags
   
   /// </code>

   // Generated code. Do not place code below this line.
   orderID: number;
   customsDescription: string;
   exciseTax: number;
   rowVersion: number;
   order: Order;
}

Files

node_modules (Directory containing the third-party node libraries including Breeze)

entity.template.txt (Handlebars template for an entity class)

entityModel.template.txt (Handlebars template for the barrel exporting all entities)

register.template.txt (Handlebars template for the ctor registration helper class)

enum.template.txt (Handlebars template for the file containing the enum classes)

metadata.template.txt (Handlebars template for the static metadata)

tsgen-core.js (The typescript generator node script)

Release Notes

1.0.0 - Initial release as an npm package 1.1.0 - Work with breeze-client .mjs modules (as well as older CJS bundles) 1.2.0 - Add support for Complex Type base class and not-null (!) assertions. Breaking change: entity.template.txt now imports baseClassName from the parent directory. 1.2.1 - Fix enum type references 1.3.0 - Use TypeScript enum types instead of string unions for enums. 1.3.1 - Use ordinal values instead of strings for enum definitions, e.g. Green = 2. Template change only. 1.3.2 - Include './enums' in entity-model.ts. Template change only. 1.3.3 - Proper handling of abstract base classes: write 'abstract' modifier, correct include path, exclude from RegistrationHelper 1.3.4 - Fix class name of RegistrationHelper; Fix include path to base complex type 1.4.0 - Add property comments indicating type, maxlength, key, and fk