Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in registration-helper.ts #9

Open
bancroftway opened this issue Jun 26, 2017 · 5 comments
Open

Error in registration-helper.ts #9

bancroftway opened this issue Jun 26, 2017 · 5 comments

Comments

@bancroftway
Copy link

bancroftway commented Jun 26, 2017

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;
}

@marcelgood
Copy link
Collaborator

Run generate again. There's a bug in the logic, which doesn't create the initializer the first time around.

@bancroftway
Copy link
Author

bancroftway commented Jun 27, 2017

I can confirm that running "gulp generate" multiple times did not fix this issue.

Here is the output...BTW, the output has the wording "Initializer function "initializer" discovered for entity type: Location" but the generated class for 'Location' does not contain 'initializer'.

Also, should the 'initializer' property have been generated as part of the generated model classes (e.g. Location in this case or do you think it needs to be on EntityBase? If latter, could you please provide an updated definition of what EntityBase should look like. I am noting my EntityBase class below.

[19:06:47] Using gulpfile R:\Projects\Bancroftway\Fruitmap\Tools\gulpfile.js
[19:06:47] Starting 'generate'...
[19:06:47] running: ./bin/metadatagenerator -i ../Data/bin/Debug/Data.dll -o ./db.metadata.json
[19:06:47] Finished 'generate' after 15 ms
[19:06:47] MetadataGenerator -i ../Data/bin/Debug/Data.dll -o ./db.metadata.json

[19:06:47] completed: ./bin/metadatagenerator -i ../Data/bin/Debug/Data.dll -o ./db.metadata.json
{ inputFileName: './db.metadata.json',
  outputFolder: '../Webapp/src/model',
  camelCase: true,
  kebabCaseFileNames: true,
  baseClassFileName: 'EntityBase' }
Generating typescript classes...
Input: R:\Projects\Bancroftway\Fruitmap\Tools\db.metadata.json
Source: R:\Projects\Bancroftway\Fruitmap\Webapp\src\model
Output: R:\Projects\Bancroftway\Fruitmap\Webapp\src\model
BaseClass: EntityBase
camelCase: true
kebabCaseFileNames: true
useEnumTypes: false
Injected base class: EntityBase
Initializer function "initializer" discovered for entity type: Location
R:\Projects\Bancroftway\Fruitmap\Webapp\src\model\location.ts hasn't changed. Skipping...
R:\Projects\Bancroftway\Fruitmap\Webapp\src\model\registration-helper.ts hasn't changed. Skipping...
R:\Projects\Bancroftway\Fruitmap\Webapp\src\model\entity-model.ts hasn't changed. Skipping...
R:\Projects\Bancroftway\Fruitmap\Webapp\src\model\metadata.ts hasn't changed. Skipping...

My EntityBase class is:

import { Entity, EntityAspect, EntityType } from "breeze-client";

export class EntityBase implements Entity {
    entityAspect: EntityAspect;
    entityType: EntityType;

    get $typeName(): string {
        if (!this.entityAspect) return "";
        return this.entityAspect.getKey().entityType.shortName;
    }
}

@marcelgood
Copy link
Collaborator

The initializer is something that you would put into the generated entity and then if it's discovered, it's called by the registration helper. I'm not sure why the generator says it discovered it, but it's not actually there. Here's an example of a generated entity with an initializer. The generator is supposed to add an empty stub the second time around, but it shouldn't generate an invalid registration helper.

import { EntityBase } from './entity-base';

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

/// </code-import>

export class State extends EntityBase {

    /// <code> Place custom code between <code> tags
    /// [Initializer]
    static initializer(entity: State) { }
    /// </code>

    // Generated code. Do not place code below this line.
    id: string;
    shortName: string;
    name: string;
    rowVersion: number;
}

I've updated the repo with the tools code from TempHire. It looks like the version here was behind. Try if the updated code works better. It works in the TempHire example.

@sskasim
Copy link

sskasim commented Feb 9, 2018

@marcelgood
I cannot get the tool to update [entity].ts files because it does not like the existence of an initializer() in the file. Can you help?

I have been using the generator for a while and I had no problems when re-generating after adding column to my table. But ever since I added a code in the block for initializer I am not able to update .ts files with the new columns I added to my table. The generator successfully creates the [App}.metdata.json file but fails to update the .ts files with new columns I may add to my entity in Database. It says for eg. "Initializer function "initializer" discovered for entity type: Country"

I have this code in the Country.ts
/// <code> Place custom code between <code> tags /// [Initializer] static initializer(entity: Country) { EntityBase.initializeEntity(entity, entity.entityType.keyProperties[0].name); } /// </code>

@marcelgood
Copy link
Collaborator

Not sure what would cause that. Can you do the same thing in TempHire and then add a new column/property and see if the same thing happens. Basically if you can give me a repro example, then I can take a look at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants