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

fix : Modify code generation script to include DCS Concerto model types #952

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/concerto-core/lib/decoratormanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -813,3 +813,4 @@ class DecoratorManager {
}

module.exports = DecoratorManager;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
module.exports = DecoratorManager;
module.exports = { DCS_MODEL, DecoratorManager };

Copy link
Member

Choose a reason for hiding this comment

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

Can you please export this using the index.js?

Copy link
Author

@Ayush1404 Ayush1404 Dec 4, 2024

Choose a reason for hiding this comment

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

But doing so will give an error as tests expect DecoratorManager to be exported as default , we can re-export it in the index.js but we have to keep the default export for tests to succeed .

Copy link
Member

Choose a reason for hiding this comment

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

Hmmm, I'm wondering we could just fix the tests with imports, but could this could break for someone whose not importing through index.js. Let me discuss this during today's WG call.

Copy link
Member

Choose a reason for hiding this comment

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

I just discussed, we decided to move DCS_MODEL to concerto-metamodel package. I'll raise a PR and cut a release and update it here to be used.

Can you please wait until I move things there?

Copy link
Author

Choose a reason for hiding this comment

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

@sanketshevkar yeah sure , no problem . I would like to contribute , could you direct me to something where i could ?

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @Ayush1404 , you'll have to move the DCS model in this repo and import it in core and types package in concerto.

Copy link
Author

Choose a reason for hiding this comment

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

@sanketshevkar , okay do i do it here in this PR or open a separate issue for it ? Also i meant to ask where else could i contribute to concerto or accord project in general .

module.exports.DCS_MODEL = DCS_MODEL;
sanketshevkar marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions packages/concerto-types/scripts/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ const { ModelManager } = require('@accordproject/concerto-core');
const { CodeGen: { TypescriptVisitor }} = require('@accordproject/concerto-codegen');
const { FileWriter } = require('@accordproject/concerto-util');
const path = require('path');
const { DCS_MODEL }= require('@accordproject/concerto-core');
sanketshevkar marked this conversation as resolved.
Show resolved Hide resolved

/**
* Generate TypeScript files from the metamodel.
*/
async function main() {
const modelManager = new ModelManager({addMetamodel:true, strict: true});
modelManager.addCTOModel(DCS_MODEL, '[email protected]');
sanketshevkar marked this conversation as resolved.
Show resolved Hide resolved
const visitor = new TypescriptVisitor();

const fileWriter = new FileWriter(path.resolve(__dirname, '..', 'src', 'generated'));
Expand Down
14 changes: 13 additions & 1 deletion packages/concerto-types/src/generated/unions/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ import type {
IModel,
IModels
} from './[email protected]';
import type {
sanketshevkar marked this conversation as resolved.
Show resolved Hide resolved
IDecoratorCommandSetReference,
CommandType,
ICommandTarget,
MapElement,
ICommand,
IDecoratorCommandSet
} from './[email protected]';

// interfaces
export interface IConcept {
Expand All @@ -51,7 +59,11 @@ ILongDomainValidator |
IAliasedType |
IImport |
IModel |
IModels;
IModels |
sanketshevkar marked this conversation as resolved.
Show resolved Hide resolved
IDecoratorCommandSetReference |
ICommandTarget |
ICommand |
IDecoratorCommandSet;

export interface IAsset extends IConcept {
$identifier: string;
Expand Down
47 changes: 47 additions & 0 deletions packages/concerto-types/src/generated/unions/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
// Generated code for namespace: [email protected]

// imports
import {IDecorator} from './[email protected]';
import {IConcept} from './[email protected]';

// interfaces
export interface IDecoratorCommandSetReference extends IConcept {
name: string;
version: string;
}

export enum CommandType {
UPSERT = 'UPSERT',
APPEND = 'APPEND',
}

export interface ICommandTarget extends IConcept {
namespace?: string;
declaration?: string;
property?: string;
properties?: string[];
type?: string;
mapElement?: MapElement;
}

export enum MapElement {
KEY = 'KEY',
VALUE = 'VALUE',
KEY_VALUE = 'KEY_VALUE',
}

export interface ICommand extends IConcept {
target: ICommandTarget;
decorator: IDecorator;
type: CommandType;
decoratorNamespace?: string;
}

export interface IDecoratorCommandSet extends IConcept {
name: string;
version: string;
includes?: IDecoratorCommandSetReference[];
commands: ICommand[];
}