breeze / breeze.tooling Goto Github PK
View Code? Open in Web Editor NEWUtilities and tooling for Breeze
Utilities and tooling for Breeze
From MetadataGenerator/Program.cs:
/// When using a DbFirst approach EF thwros two kind of exceptions:
/// 1. InvalidOperationException is there is no connection string for the DbContext we are working on.
/// 2. UnintentionalCodeFirstException if it finds the connection string for the DbContext.
/// UnintentionalCodeFirstException inherits from InvalidOperationException
The only way I can get a DbFirst EF 6.0 model to produce Metadata is to uncomment:
catch (InvalidOperationException iex) // This is might be because we have a DbFirst DbContext, so let's try it out.
{
try
{
return EFContextProvider<object>.GetMetadataFromDbFirstAssembly(type.Assembly, Options.ResourcePrefix);
}
catch (Exception ex)
{
Console.WriteLine("An exception was thrown while processing the dbfirst assembly {0}. {1}", type.Assembly.FullName, ex);
}
}
The InvalidOperationException thrown does have the message:
"No connection string named 'TIPS_Corn_DevEntities' could be found in the application config file."
as is indicated in the /// 1 comment above, however the connection string does exist and is properly named within the specified .dll.config. Properly catching and executing
GetMetadataFromDbFirstAssembly()
will properly generate the metadata.
Why is this code commented out?
Thanks,
Mike
Hi guys,
Would you consider publishing breeze.tooling to npm putting it as OS specific?
Is MetaDataGenerator available for EF Core DLL?
Thanks & regards,
Fayeeg
Would be nice to add an example of best use case.
I found i was getting error with MyNameSpace no defined.
I found i had to include the generated _ReferenceHelper.js in my index.html which seems a bit dirty.
Is there a better typescript`y way to bootstrap the namespace?
After running "gulp generate", I did RegistrationHelper.register in my repository class like so:
constructor() {
this.db = new EntityManager("http://localhost:62749/breeze/data");
RegistrationHelper.register(this.db.metadataStore);
}
but I am getting an error:
Property 'initializer' does not exist on type 'typeof Location'.
The generated registration-helper.ts is below. When watching Brian Noyes' course, I did not see the ".initializer" code....so is it safe to remove this?
import { MetadataStore } from 'breeze-client';
import { Location } from './location';
export class RegistrationHelper {
static register(metadataStore: MetadataStore) {
metadataStore.registerEntityTypeCtor('Location', Location, Location.initializer);
}
}
The generated Location class does not have initializer property. Here is the generated Location class:
import { EntityBase } from './entity-base';
/// <code-import> Place custom imports between <code-import> tags
/// </code-import>
export class Location extends EntityBase {
/// <code> Place custom code between <code> tags
/// </code>
// Generated code. Do not place code below this line.
id: number;
description: string;
lat: number;
lng: number;
dateCreated: Date;
dateModified: Date;
createdByUserId: string;
}
When I attempt to re-generate my entities using the tsgen tool with breeze-clilent@mjs, I receive the following error:
Error [ERR_REQUIRE_ESM]: require() of ES Module C:\GitHub\gitlab.disney.com\ghro.disney.com\ghro.disney.com.web\ClientApp\node_modules\breeze-client\fesm2015\breeze-client.mjs not supported. Instead change the require of C:\GitHub\gitlab.disney.com\ghro.disney.com\ghro.disney.com.web\ClientApp\node_modules\breeze-client\fesm2015\breeze-client.mjs to a dynamic import() which is available in all CommonJS modules.
I had to revert back to [email protected] to generate my entity set.
Could tsgen be updated with an MJS version? Thanks! :)
Hey,
I'm not very familiar with the templating tool used by the breeze generator, but how would you remove the trailing comma ?
{{#each values}} {{this}} = {{lookup ../ordinals @index}},
generates
export enum ProductColor { Red = 0, Green = 1, Blue = 2, Yellow = 4, }
if the last enum value is followed by a comma, this gives a linting error so it's a bit annoying when generating metadata...
Hello,
I think you may have parameter name wrong in the breeze.tooling/TypeScriptModuleGen/gulpfile.js file. By default you have the parameter called baseClassName but I believe it is supposed to be baseClassFileName.
Prior to making this change it would generate the typescript files but would not include the reference to the EntityBase or my various navigation properties. The output when running gulp generate would also state BaseClass: undefined.
Once I made the change things worked properly.
Thank you.
Hey guys,
Just realised I need to rather use the module syntax, and found a few issues that needed to be rectified to get the script to run... sorry I don't currently have a PR for these, I'll do one as soon as I get a chance, but I thought it easier to let you know in case you have time before me.
var fs = require('fs');
at the top of tsgen.js file, or you get fs undefined error.var config = argvToConfig;
line should be var config = argvToConfig()
; to actually execute the function.argvToConfig
function, check at the end should be if (!config.inputFileName || !fs.existsSync(config.inputFileName)) {
instead of if (!inputFileName || !fs.existsSync(inputFileName)) {
processRawMetadata
function to config.baseClassName
, but the property is actually config.baseClassFileName
Otherwise it's a really great tool. One question though, would it not be better to make it one tool with an option for module or entity syntax output? Surely make it easier to maintain? I haven't had to check enough the differences, so that may well be a stupid idea for various reasons, just a thought.
Thanks!
I created a new class project .Net Framework 4.5.2
I have generated the POCO class using EntityFramework Reverse POCO Code First Generator.
And created a app.config file and specified connection as mentioned below : -
<connectionStrings>
<add name="DBConnection" connectionString="Server=.;Database=Zza;Trusted_Connection=true" ProviderName="System.Data.SqlClient"/>
</connectionStrings>
But MetaDataGenerator not accepting the above connection string and gives error.
"No connection string named DBConnection could be found in the application config file."
The DBContext.cs has following constructor
public DBContext() : base("Name=DBConnection") { }
Please can you guide ...
Hello,
The MetadataGenerator tool is specific to EF. Is there a tool for NH ?
I can generate the CSDL metadata easily enough (had to add my connection string to the metadatagenerator.exe.config file), but when I try and use the tsgen script I get the following error:
Unexpected error occurred: Unable to locate the default implementation of the 'modelLibrary' interface. Possible options are 'ko', 'backingStore' or 'backbone'. See the breeze.config.initializeAdapterInstances method.
Hello guys,
I am getting above error when I am running the TypescriptEntityGen\tsgen.js -i metadata.json command.
Any specific typescript or handlebar.js version is required. This was working fine before few months.
breeze.client: ^1.5.5
handlerbars: ^1.3.0 (as mentioned in package.json)
Hi,
Could you consider publishing breeze-entity-generator to npm, with a version number of 1.1.0?
following this post https://stackoverflow.com/questions/39781647/breeze-typescript-tooling
I updated my tsgen to use
var breeze = require('breeze-client/breeze.debug');
but I get error : Cannot find module 'breeze-client/breeze.debug' in package.json
I have "breeze-client": "2.0.0-alpha.18", how can I get this debug file?
I've written a tsgen-odata.js script which consumes a csdl xml directly from $metadata endpoint and then calls tsgen-core.ts for entity generation. It uses datajs library to parse metadata as you do in breeze.js
var argv = require('yargs').argv;
var tsGenCore = require('./tsgen-core');
var fs = require('fs');
var doRequest = require('request');
require('datajs');
var xmldom = require('xmldom');
global.DOMParser = xmldom.DOMParser;
var metaPath = './tools/metadata.json';
try {
//var metaUrl = 'http://localhost:51163/odata/$metadata';
var metaUrl = argv.i || argv.input;
OData.defaultHttpClient = {
request: function(request, success, error) {
doRequest({
url: request.requestUri,
headers: request.headers
}, (err, resp, body) => {
var response;
if (!err && resp.statusCode >= 200 && resp.statusCode <= 299) {
response = { requestUri: request.requestUri, statusCode: resp.statusCode, statusText: resp.statusText, headers: resp.headers, body: body };
success(response);
} else {
error({ message: "HTTP request failed", request: request, response: response });
}
});
}
};
OData.read({
requestUri: metaUrl,
// headers: { "Accept": "application/json"}
headers: { 'Accept': 'application/*; odata.metadata=full'}
},
function (data) {
// data.dataServices.schema is an array of schemas. with properties of
// entityContainer[], association[], entityType[], and namespace.
if (!data || !data.dataServices) {
var error = new Error("Metadata query failed for: " + url);
return deferred.reject(error);
}
var csdlMetadata = data.dataServices;
//
var jsonStr = JSON.stringify(csdlMetadata);
fs.writeFile(metaPath, jsonStr, (err) => {
if (err) throw err;
var config = argvToConfig();
tsGenCore.generate(config);
});
},
function (error) {
var message = "Metadata query failed; " + (error.message || "");
console.log('Unexpected error occurred: ' + message);
},
OData.metadataHandler
);
} catch (e) {
console.log('Unexpected error occurred: ' + e.stack);
}
function argvToConfig() {
var config = {
inputFileName: metaPath,//argv.i || argv.input,
outputFolder: argv.o || argv.outputFolder,
sourceFilesFolder: argv.s || argv.sourceFiles,
baseClassName: argv.b || argv.baseClass,
camelCase: !!(argv.c || argv.camelCase),
kebabCaseFileNames: !!(argv.k || argv.kebabCaseFileNames),
useEnumTypes: !!(argv.e || argv.useEnumTypes)
};
return config;
}
You may treat this as a feature request
Generated typescript classes are not extending the EntityBase class.
Here is the gulpfile section that specifies the generation task:
function generateEntities() {
tsGen.generate({
inputFileName: './db.metadata.json',
outputFolder: '../Webapp/src/model',
camelCase: true,
kebabCaseFileNames: true,
baseClassName: 'EntityBase'
});
}
The generated class is:
/// <code-import> Place custom imports between <code-import> tags
/// </code-import>
export class Location {
/// <code> Place custom code between <code> tags
/// </code>
// Generated code. Do not place code below this line.
id: number;
description: string;
lat: number;
lng: number;
dateCreated: Date;
dateModified: Date;
createdByUserId: string;
}
When running npm install
, the following errors show up in Node v9.4.0:
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: graceful-fs v3.0.0 and before will fail on node releases >= v7.0. Please update to graceful-fs@^4.0.0 as soon as possible. Use 'npm ls graceful-fs' to find it in the tree.
Hi guys,
I have a question about using these entities with breeze. The entities generated have a property with the correct array type for a navigation property. If I do a query where I include an expand clause, I can see in the query results that the associated objects are loaded, and I can also see that the root entity is loaded, and that the array property has been "attacked" by breeze (it's added a bunch of custom properties and functions to the array object).
However the contents of the array is empty. So although the correct entities have been loaded, they are not associated with the root entity correctly.
Any idea how to overcome this?
Thanks!
I'm submitting a ... (check one with "x")
[ X ] bug report
Current behavior
Trying to feed a metadata file in CSDL format (taken from ASP.Net OData service' $metadata endpoint) to both tsgen-core.js and convert-csdl.js leads to an JSON parsing error:
SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse ()
at MetadataStore.proto.importMetadata (node_modules\breeze-client\breeze.debug.js: 6651:64)
at Function.ctor.importMetadata (node_modules\breeze-client\breeze.debug.js:6712:8)
Expected behavior
Generated entity models in .js/.ts files without this error
**Minimal reproduction of the problem **
node .\tools\tsgen.js --input .\tools\metadata.csdl --outputFolder .\ClientApp\data
OR
node ./tools/convert-csdl.js ./tools/metadata.csdl ./tools/metadata.json
Please tell us about your environment:
OS: WIndows 10 Pro
Node.js: 10.15.3
tslint being deprecated and replaced with eslint, could you update the entity-template.txt .
you can replace
// tslint:disable:no-trailing-whitespace
// tslint:disable:member-ordering
with
/* eslint-disable no-trailing-spaces */ /* eslint-disable @typescript-eslint/member-ordering */
-> node .\tsgen.js -input metadata.xml
-> Unexpected error occurred: Unexpected token < in JSON at position 0
metadata.xml is like this http://services.odata.org/V4/TripPinServiceRW/$metadata
Hi,
Since .NET Core 2.2 will reach End of Life on December 23, 2019, any plans that you will offer your server side packages on .Net core 3.x ?
I tried upgrading the Metadatagenerator EF core project and I am getting the below error
System.MissingMethodException : Method not found: 'System.Type Microsoft.EntityFrameworkCore.Metadata.IProperty.get_ClrType
We wish to start our new project using .Net core 3.1 and would like to use breeze client/server libraries. Looking forward to your solution. Thanks in advance.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.