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

feat(codegen): code generator to bootstrap vocab file (#21) #22

Conversation

sanketshevkar
Copy link
Member

Closes #21

Changes

  • new code generator added to generate vocab YAML file

Flags

  • Tests cases for field types like enumValues, relationships and fields is remaining.

Screenshots or Video

Related Issues

  • Issue #
  • Pull Request #

Author Checklist

  • Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit.
  • Vital features and changes captured in unit and/or integration tests
  • Commits messages follow AP format
  • Extend the documentation, if necessary
  • Merging to main from fork:branchname

Signed-off-by: sanketshevkar <shevkar.sanket@gmail.com>
Signed-off-by: sanketshevkar <shevkar.sanket@gmail.com>
Signed-off-by: sanketshevkar <shevkar.sanket@gmail.com>
lib/codegen/codegen.js Outdated Show resolved Hide resolved
Signed-off-by: sanketshevkar <shevkar.sanket@gmail.com>
Signed-off-by: sanketshevkar <shevkar.sanket@gmail.com>
@dselman dselman self-requested a review May 26, 2023 17:39
Signed-off-by: sanketshevkar <shevkar.sanket@gmail.com>
 into sanketshevkar/i21/create-bootstrap-eng-vocab-file

chore(*): rebase with main
Copy link
Sponsor Contributor

@dselman dselman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Thanks! 🙏

@sanketshevkar sanketshevkar marked this pull request as ready for review May 31, 2023 11:22
@sanketshevkar sanketshevkar changed the title DRAFT: feat(codegen): code generator to bootstrap vocab file (#21) feat(codegen): code generator to bootstrap vocab file (#21) May 31, 2023
Copy link
Sponsor Member

@mttrbrts mttrbrts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The npm run build:types command is failing in the build. Can you look into it, please?

@sanketshevkar
Copy link
Member Author

The npm run build:types command is failing in the build. Can you look into it, please?

@mttrbrts I investigated the error. Looks like the error is from concerto-vocabulary package. The following types shown in the error were not imported.
I tried to hard code a fix, some thing like this

export = Vocabulary;

// fix starts
import {VocabularyManager} from "../index";
import {ModelFile} from "@accordproject/concerto-core/types/index";
//fix ends

/**
* A vocabulary for a concerto model
* @class
* @memberof module:concerto-vocabulary
*/
declare class Vocabulary {
    /**
     * Create the Vocabulary
     * @constructor
     * @param {VocabularyManager} vocabularyManager - the manager for this vocabulary
     * @param {object} voc - the JSON representation of the vocabulary
     */
    constructor(vocabularyManager: VocabularyManager, voc: object);
    vocabularyManager: VocabularyManager;
    content: any;
    /**
     * Returns the namespace for the vocabulary
     * @returns {string} the namespace for this vocabulary
     */
    getNamespace(): string;
    /**
     * Returns the locale for the vocabulary
     * @returns {string} the locale for this vocabulary
     */
    getLocale(): string;
    /**
     * Returns the identifier for the vocabulary, composed of the namespace plus the locale
     * @returns {string} the identifier for this vocabulary
     */
    getIdentifier(): string;
    /**
     * Returns all the declarations for this vocabulary
     * @returns {Array} an array of objects
     */
    getTerms(): any[];
    /**
     * Gets the term for a concept, enum or property
     * @param {string} declarationName the name of a concept or enum
     * @param {string} [propertyName] the name of a property (optional)
     * @returns {string} the term or null if it does not exist
     */
    getTerm(declarationName: string, propertyName?: string): string;
    /**
     * Validates a vocabulary against a ModelFile, returning errors for
     * missing and additional terms.
     * @param {ModelFile} modelFile the model file for this vocabulary
     * @returns {*} an object with missingTerms and additionalTerms properties
     */
    validate(modelFile: ModelFile): any;
    /**
     * Converts the object to JSON
     * @returns {*} the contens of this vocabulary
     */
    toJSON(): any;
}

It works. But I think these types should be auto-imported. I believe these type declarations are auto-generated using the JSDOC comments? @dselman

@mttrbrts
Copy link
Sponsor Member

mttrbrts commented Jun 7, 2023

@mttrbrts I investigated the error. Looks like the error is from concerto-vocabulary package. The following types shown in the error were not imported.

It works. But I think these types should be auto-imported. I believe these type declarations are auto-generated using the JSDOC comments? @dselman

Well spotted @sanketshevkar, I put in a fix here, accordproject/concerto#657

Once that is merged you can update your dependency on the concerto-vocabulary package here, and the build should work. (I tested that locally already).

@sanketshevkar
Copy link
Member Author

Okay got it. Thanks for the fix @mttrbrts 👍

@mttrbrts
Copy link
Sponsor Member

mttrbrts commented Jun 7, 2023

Try locally with the unstable package @accordproject/concerto-vocabulary@3.8.2-20230607124239, if it works for you, I'll make a stable release

@sanketshevkar
Copy link
Member Author

Try locally with the unstable package @accordproject/concerto-vocabulary@3.8.2-20230607124239, if it works for you, I'll make a stable release

@mttrbrts it's working locally. 🙌

@mttrbrts
Copy link
Sponsor Member

mttrbrts commented Jun 7, 2023

@mttrbrts it's working locally. 🙌

👍I've published 3.8.2 this evening.

Signed-off-by: sanketshevkar <shevkar.sanket@gmail.com>
@sanketshevkar
Copy link
Member Author

I've made the changes and pushed the code. Locally I've encountered a merge conflict with a snapshot file. I'll fix that and update you.

@coveralls
Copy link

Coverage Status

coverage: 98.942% (+0.04%) from 98.906% when pulling eee5036 on sanketshevkar:sanketshevkar/i21/create-bootstrap-eng-vocab-file into ba60afd on accordproject:main.

@sanketshevkar
Copy link
Member Author

Not sure why, this branch shows no conflict with main, but I'm trying to rebase with main on my local, it's showing merge conflicts.

@mttrbrts
Copy link
Sponsor Member

mttrbrts commented Jun 8, 2023

Not sure why, this branch shows no conflict with main, but I'm trying to rebase with main on my local, it's showing merge conflicts.

Likely your main branch has diverged. GitHub is happy, so we can merge.

I recommend deleting your local copy of main and checkout again. Otherwise, you can do a hard reset to the upstream branch.

@mttrbrts mttrbrts merged commit d38ddbc into accordproject:main Jun 8, 2023
11 checks passed
@sanketshevkar
Copy link
Member Author

Yep makes sense. Thanks for merging @mttrbrts. I think I should update the documentation next.

@sanketshevkar
Copy link
Member Author

Documentation for vocabulary code generation
accordproject/concerto-docs#16

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

Successfully merging this pull request may close these issues.

Code Generator to bootstrap a vocab file
4 participants