diff --git a/packages/concerto-tools/lib/codegen/fromcto/protobuf/protobufvisitor.js b/packages/concerto-tools/lib/codegen/fromcto/protobuf/protobufvisitor.js index 4b8ba63d9f..6632f425a3 100644 --- a/packages/concerto-tools/lib/codegen/fromcto/protobuf/protobufvisitor.js +++ b/packages/concerto-tools/lib/codegen/fromcto/protobuf/protobufvisitor.js @@ -114,7 +114,7 @@ class ProtobufVisitor { * @public */ getNamesOfSubclassesOfClassRecursively(classDeclaration) { - return typeof classDeclaration.getAssignableClassDeclarations === 'function' + return typeof classDeclaration?.getAssignableClassDeclarations === 'function' ? classDeclaration.getAssignableClassDeclarations() ?.filter( assignableClass => assignableClass.getName() !== classDeclaration.getName() diff --git a/packages/concerto-tools/test/codegen/fromcto/protobuf/data/apapProtocol.cto b/packages/concerto-tools/test/codegen/fromcto/protobuf/data/apapProtocol.cto new file mode 100644 index 0000000000..6450b3a398 --- /dev/null +++ b/packages/concerto-tools/test/codegen/fromcto/protobuf/data/apapProtocol.cto @@ -0,0 +1,200 @@ +@description("Accord Project Agreement Protocol") +namespace org.accordproject.protocol@1.0.0 + +import concerto.metamodel@0.4.0.{Property,ConceptDeclaration,Model} from https://models.accordproject.org/concerto/metamodel@0.4.0.cto +import org.accordproject.commonmark@0.5.0.Document from https://models.accordproject.org/markdown/commonmark@0.5.0.cto +import org.accordproject.party@0.2.0.{Party} from https://models.accordproject.org/accordproject/party@0.2.0.cto + +scalar JSON extends String +scalar FullyQualifiedTypeName extends String + +@description("Bytes and mime type for a blob of data, such as images, files, etc.") +concept Blob { + o String base64 + o String mimeType // e.g. "image/jpeg", "application/pdf", "audio/mpeg", "video/mp4", etc... +} + +@description("The text for a template") +concept Text { + o Document templateMark +} + +@description("The concept declaration associated with a template") +concept TemplateModel { + o FullyQualifiedTypeName typeName // name of the type for this template + --> SharedModel sharedModel optional // reference to a shared model + o Model model optional // an inline model +} + +@description("A shared data model") +@resource +concept SharedModel identified by modelId { + o String modelId + o Model model +} + +@description("The type (language) of code") +enum CodeType { + o ES2015 + o WASM_BYTES +} + +@description("Code encoding scheme") +enum CodeEncodingType { + o PLAIN_TEXT + o BASE64 +} + +@description("Executable code") +concept Code { + o CodeType type + o CodeEncodingType encoding + o String value +} + +@description("A function for a template") +concept Function identified by name { + o String name + o FullyQualifiedTypeName requestType + o FullyQualifiedTypeName responseType optional + o FullyQualifiedTypeName[] emittedTypes optional + o Code code +} + +@description("The functions for a template") +concept Logic { + o FullyQualifiedTypeName stateType optional + o Function[] functions +} + +@resource +@description("An Accord Project template") +concept Template identified by name { + o String name + o String author + o String displayName optional + o String version + o String description optional + o String license + o String[] keywords optional + o Blob logo optional + o TemplateModel templateModel + o Text text + o Logic logic optional +} + +@description("A key/value pair") +concept KeyValue { + o String key + o String value +} + +@description("Generic metadata comprised of key/value pairs") +concept Metadata { + o KeyValue[] values +} + +@resource +@description("An Accord Project Agreement, an instance of a template") +concept Agreement identified by agreementId { + o String agreementId + o JSON data // Data for the agreement (an instance of the data for its template) + o JSON state optional // Runtime state of the agreement + --> Template template // Template for the the agreement + o AgreementParty[] agreementParties // Parties to the agreement + o Signature[] signatures // Signatures of the parties to the agreement + o AgreementStatusType agreementStatus // Current status of agreement + o HistoryEntry[] historyEntries // History of document state and details. + o Blob[] attachments // Pdfs, images, multimedia, etc. that form part of the agreement + o String[] references // uri/urls to external references relevant to agreement + o Metadata metadata // Additional data that may be relevant to the agreement +} + +@description("A Party to an Agreement") +participant AgreementParty extends Party { + o String name + o Boolean signatory // Sometimes a party named on an agreement are not required to sign (e.g. beneficiary) + o String role optional // Role of AgreementParty (e.g. "Owner", "Company Director", etc..) + o String email optional + o String phone optional + o String company optional + o String network optional + o Address address optional +} + +@description("An Address of an Agreement Party") +concept Address { + o String[] streetRoad + o String suburbTownCity optional + o String stateTerritoryRegion optional + o String postalCode optional + o String country optional +} + +@description("A history entry for an Agreement") +transaction HistoryEntry { + o AgreementStatusType agreementStatus // Status at time of change + o JSON data // Data at time of change + o Metadata metadata // Additional data that may be relevant to the agreement at time of change +} + +@description("A signature of an Agreement Party") +concept Signature { + o AgreementParty signatory // The Agreement Party signing the Agreement + o DateTime signedAt optional // When the signing occurred + o Metadata metadata // Geolocation data, IP address, etc. + o Blob[] signatureImage // Selfie, proof-of-id, sign-on-glass image +} + +@description("Abstract conversion options") +abstract concept ConversionOptions { +} + +@description("PDF conversion options") +concept PdfConversionOptions extends ConversionOptions { + o JSON styles optional +} + +@description("Server feature identifiers") +enum FeatureType { + // note: crud operations on templates is required + o TEMPLATE_VERIFY_SIGNATURES // verify a signed template + o TEMPLATE_LOGIC // templates with logic + o TEMPLATE_STATEFUL // stateful templates + + o AGREEMENT_MANAGE // crud operations on agreements + o AGREEMENT_TRIGGER // trigger agreements + o AGREEMENT_STATE // get the state of an agreement + o AGREEMENT_CONVERT_PDF // convert agreement to PDF + + // o AGREEMENT_SIGNING + + o SHARED_MODEL_MANAGE // manage shared models +} + +@description("Server capabilities") +concept Capabilities { + o FeatureType[] features +} + +@description("Trigger a function with a JSON payload") +concept TriggerRequest { + o String functionName + o JSON payload +} + +@description("Response of triggering a function") +concept TriggerResponse { + o JSON result optional + o Boolean isError + o String errorMessage optional + o String errorDetails optional +} + +@description("Runtime status of an agreement") +enum AgreementStatusType { + o DRAFT // No signatories have signed yet + o SIGNNG // Signed by some but not all signatories + o COMPLETED // Signing by all signatories completed + o SUPERSEDED // Superseded by subsequent agreement +} diff --git a/packages/concerto-tools/test/codegen/fromcto/protobuf/data/concerto.metamodel.v0_4_0-expected.proto b/packages/concerto-tools/test/codegen/fromcto/protobuf/data/concerto.metamodel.v0_4_0-expected.proto new file mode 100644 index 0000000000..4af174fd86 --- /dev/null +++ b/packages/concerto-tools/test/codegen/fromcto/protobuf/data/concerto.metamodel.v0_4_0-expected.proto @@ -0,0 +1,295 @@ +syntax = "proto3"; + +package concerto.metamodel.v0_4_0; + +import "google/protobuf/timestamp.proto"; + +message Position { + sint64 column = 1; + sint64 line = 2; + sint64 offset = 3; +} + +message Range { + Position end = 1; + optional string source = 2; + Position start = 3; +} + +message TypeIdentifier { + string name = 1; + optional string namespace = 2; +} + +message _Subclasses_of_class_DecoratorLiteral { + oneof _class_oneof_DecoratorLiteral { + DecoratorBoolean _subclass_of_class_DecoratorLiteral_DecoratorBoolean = 1; + DecoratorNumber _subclass_of_class_DecoratorLiteral_DecoratorNumber = 2; + DecoratorString _subclass_of_class_DecoratorLiteral_DecoratorString = 3; + DecoratorTypeReference _subclass_of_class_DecoratorLiteral_DecoratorTypeReference = 4; + } +} + +message DecoratorString { + optional Range location = 1; + string value = 2; +} + +message DecoratorNumber { + optional Range location = 1; + double value = 2; +} + +message DecoratorBoolean { + optional Range location = 1; + bool value = 2; +} + +message DecoratorTypeReference { + bool isArray = 1; + optional Range location = 2; + TypeIdentifier type = 3; +} + +message Decorator { + repeated _Subclasses_of_class_DecoratorLiteral arguments = 1; + optional Range location = 2; + string name = 3; +} + +message Identified {} + +message _Subclasses_of_class_Identified { + oneof _class_oneof_Identified { + Identified _subclass_of_class_Identified_Identified = 1; + IdentifiedBy _subclass_of_class_Identified_IdentifiedBy = 2; + } +} + +message IdentifiedBy { + string name = 1; +} + +message _Subclasses_of_class_Declaration { + oneof _class_oneof_Declaration { + AssetDeclaration _subclass_of_class_Declaration_AssetDeclaration = 1; + ConceptDeclaration _subclass_of_class_Declaration_ConceptDeclaration = 2; + EnumDeclaration _subclass_of_class_Declaration_EnumDeclaration = 3; + EventDeclaration _subclass_of_class_Declaration_EventDeclaration = 4; + ParticipantDeclaration _subclass_of_class_Declaration_ParticipantDeclaration = 5; + TransactionDeclaration _subclass_of_class_Declaration_TransactionDeclaration = 6; + } +} + +message EnumDeclaration { + repeated Decorator decorators = 1; + optional Range location = 2; + string name = 3; + repeated EnumProperty properties = 4; +} + +message EnumProperty { + repeated Decorator decorators = 1; + optional Range location = 2; + string name = 3; +} + +message ConceptDeclaration { + repeated Decorator decorators = 1; + optional _Subclasses_of_class_Identified identified = 2; + bool isAbstract = 3; + optional Range location = 4; + string name = 5; + repeated _Subclasses_of_class_Property properties = 6; + optional TypeIdentifier superType = 7; +} + +message _Subclasses_of_class_ConceptDeclaration { + oneof _class_oneof_ConceptDeclaration { + AssetDeclaration _subclass_of_class_ConceptDeclaration_AssetDeclaration = 1; + ConceptDeclaration _subclass_of_class_ConceptDeclaration_ConceptDeclaration = 2; + EventDeclaration _subclass_of_class_ConceptDeclaration_EventDeclaration = 3; + ParticipantDeclaration _subclass_of_class_ConceptDeclaration_ParticipantDeclaration = 4; + TransactionDeclaration _subclass_of_class_ConceptDeclaration_TransactionDeclaration = 5; + } +} + +message AssetDeclaration { + repeated Decorator decorators = 1; + optional _Subclasses_of_class_Identified identified = 2; + bool isAbstract = 3; + optional Range location = 4; + string name = 5; + repeated _Subclasses_of_class_Property properties = 6; + optional TypeIdentifier superType = 7; +} + +message ParticipantDeclaration { + repeated Decorator decorators = 1; + optional _Subclasses_of_class_Identified identified = 2; + bool isAbstract = 3; + optional Range location = 4; + string name = 5; + repeated _Subclasses_of_class_Property properties = 6; + optional TypeIdentifier superType = 7; +} + +message TransactionDeclaration { + repeated Decorator decorators = 1; + optional _Subclasses_of_class_Identified identified = 2; + bool isAbstract = 3; + optional Range location = 4; + string name = 5; + repeated _Subclasses_of_class_Property properties = 6; + optional TypeIdentifier superType = 7; +} + +message EventDeclaration { + repeated Decorator decorators = 1; + optional _Subclasses_of_class_Identified identified = 2; + bool isAbstract = 3; + optional Range location = 4; + string name = 5; + repeated _Subclasses_of_class_Property properties = 6; + optional TypeIdentifier superType = 7; +} + +message _Subclasses_of_class_Property { + oneof _class_oneof_Property { + BooleanProperty _subclass_of_class_Property_BooleanProperty = 1; + DateTimeProperty _subclass_of_class_Property_DateTimeProperty = 2; + DoubleProperty _subclass_of_class_Property_DoubleProperty = 3; + IntegerProperty _subclass_of_class_Property_IntegerProperty = 4; + LongProperty _subclass_of_class_Property_LongProperty = 5; + ObjectProperty _subclass_of_class_Property_ObjectProperty = 6; + RelationshipProperty _subclass_of_class_Property_RelationshipProperty = 7; + StringProperty _subclass_of_class_Property_StringProperty = 8; + } +} + +message RelationshipProperty { + repeated Decorator decorators = 1; + bool isArray = 2; + bool isOptional = 3; + optional Range location = 4; + string name = 5; + TypeIdentifier type = 6; +} + +message ObjectProperty { + repeated Decorator decorators = 1; + optional string defaultValue = 2; + bool isArray = 3; + bool isOptional = 4; + optional Range location = 5; + string name = 6; + TypeIdentifier type = 7; +} + +message BooleanProperty { + repeated Decorator decorators = 1; + optional bool defaultValue = 2; + bool isArray = 3; + bool isOptional = 4; + optional Range location = 5; + string name = 6; +} + +message DateTimeProperty { + repeated Decorator decorators = 1; + bool isArray = 2; + bool isOptional = 3; + optional Range location = 4; + string name = 5; +} + +message StringProperty { + repeated Decorator decorators = 1; + optional string defaultValue = 2; + bool isArray = 3; + bool isOptional = 4; + optional Range location = 5; + string name = 6; + optional StringRegexValidator validator = 7; +} + +message StringRegexValidator { + string flags = 1; + string pattern = 2; +} + +message DoubleProperty { + repeated Decorator decorators = 1; + optional double defaultValue = 2; + bool isArray = 3; + bool isOptional = 4; + optional Range location = 5; + string name = 6; + optional DoubleDomainValidator validator = 7; +} + +message DoubleDomainValidator { + optional double lower = 1; + optional double upper = 2; +} + +message IntegerProperty { + repeated Decorator decorators = 1; + optional sint64 defaultValue = 2; + bool isArray = 3; + bool isOptional = 4; + optional Range location = 5; + string name = 6; + optional IntegerDomainValidator validator = 7; +} + +message IntegerDomainValidator { + optional sint64 lower = 1; + optional sint64 upper = 2; +} + +message LongProperty { + repeated Decorator decorators = 1; + optional sint64 defaultValue = 2; + bool isArray = 3; + bool isOptional = 4; + optional Range location = 5; + string name = 6; + optional LongDomainValidator validator = 7; +} + +message LongDomainValidator { + optional sint64 lower = 1; + optional sint64 upper = 2; +} + +message _Subclasses_of_class_Import { + oneof _class_oneof_Import { + ImportAll _subclass_of_class_Import_ImportAll = 1; + ImportType _subclass_of_class_Import_ImportType = 2; + } +} + +message ImportAll { + string namespace = 1; + optional string uri = 2; +} + +message ImportType { + string name = 1; + string namespace = 2; + optional string uri = 3; +} + +message Model { + optional string concertoVersion = 1; + repeated _Subclasses_of_class_Declaration declarations = 2; + repeated _Subclasses_of_class_Import imports = 3; + string namespace = 4; + optional string sourceUri = 5; +} + +message Models { + repeated Model models = 1; +} + diff --git a/packages/concerto-tools/test/codegen/fromcto/protobuf/data/org.accordproject.commonmark.v0_5_0-expected.proto b/packages/concerto-tools/test/codegen/fromcto/protobuf/data/org.accordproject.commonmark.v0_5_0-expected.proto new file mode 100644 index 0000000000..30bc2050a4 --- /dev/null +++ b/packages/concerto-tools/test/codegen/fromcto/protobuf/data/org.accordproject.commonmark.v0_5_0-expected.proto @@ -0,0 +1,265 @@ +syntax = "proto3"; + +package org.accordproject.commonmark.v0_5_0; + +import "google/protobuf/timestamp.proto"; + +message _Subclasses_of_class_Node { + oneof _class_oneof_Node { + BlockQuote _subclass_of_class_Node_BlockQuote = 1; + Code _subclass_of_class_Node_Code = 2; + CodeBlock _subclass_of_class_Node_CodeBlock = 3; + Document _subclass_of_class_Node_Document = 4; + Emph _subclass_of_class_Node_Emph = 5; + HeaderCell _subclass_of_class_Node_HeaderCell = 6; + Heading _subclass_of_class_Node_Heading = 7; + HtmlBlock _subclass_of_class_Node_HtmlBlock = 8; + HtmlInline _subclass_of_class_Node_HtmlInline = 9; + Image _subclass_of_class_Node_Image = 10; + Item _subclass_of_class_Node_Item = 11; + Linebreak _subclass_of_class_Node_Linebreak = 12; + Link _subclass_of_class_Node_Link = 13; + List _subclass_of_class_Node_List = 14; + Paragraph _subclass_of_class_Node_Paragraph = 15; + Softbreak _subclass_of_class_Node_Softbreak = 16; + Strong _subclass_of_class_Node_Strong = 17; + Table _subclass_of_class_Node_Table = 18; + TableBody _subclass_of_class_Node_TableBody = 19; + TableCell _subclass_of_class_Node_TableCell = 20; + TableHead _subclass_of_class_Node_TableHead = 21; + TableRow _subclass_of_class_Node_TableRow = 22; + Text _subclass_of_class_Node_Text = 23; + ThematicBreak _subclass_of_class_Node_ThematicBreak = 24; + } +} + +message _Subclasses_of_class_Root { + oneof _class_oneof_Root { + Document _subclass_of_class_Root_Document = 1; + } +} + +message _Subclasses_of_class_Child { + oneof _class_oneof_Child { + BlockQuote _subclass_of_class_Child_BlockQuote = 1; + Code _subclass_of_class_Child_Code = 2; + CodeBlock _subclass_of_class_Child_CodeBlock = 3; + Emph _subclass_of_class_Child_Emph = 4; + HeaderCell _subclass_of_class_Child_HeaderCell = 5; + Heading _subclass_of_class_Child_Heading = 6; + HtmlBlock _subclass_of_class_Child_HtmlBlock = 7; + HtmlInline _subclass_of_class_Child_HtmlInline = 8; + Image _subclass_of_class_Child_Image = 9; + Item _subclass_of_class_Child_Item = 10; + Linebreak _subclass_of_class_Child_Linebreak = 11; + Link _subclass_of_class_Child_Link = 12; + List _subclass_of_class_Child_List = 13; + Paragraph _subclass_of_class_Child_Paragraph = 14; + Softbreak _subclass_of_class_Child_Softbreak = 15; + Strong _subclass_of_class_Child_Strong = 16; + Table _subclass_of_class_Child_Table = 17; + TableBody _subclass_of_class_Child_TableBody = 18; + TableCell _subclass_of_class_Child_TableCell = 19; + TableHead _subclass_of_class_Child_TableHead = 20; + TableRow _subclass_of_class_Child_TableRow = 21; + Text _subclass_of_class_Child_Text = 22; + ThematicBreak _subclass_of_class_Child_ThematicBreak = 23; + } +} + +message Text { + optional sint64 endLine = 1; + repeated _Subclasses_of_class_Node nodes = 2; + optional sint64 startLine = 3; + optional string text = 4; +} + +message Attribute { + string name = 1; + string value = 2; +} + +message TagInfo { + repeated Attribute attributes = 1; + string attributeString = 2; + bool closed = 3; + string content = 4; + string tagName = 5; +} + +message CodeBlock { + optional sint64 endLine = 1; + optional string info = 2; + repeated _Subclasses_of_class_Node nodes = 3; + optional sint64 startLine = 4; + optional TagInfo tag = 5; + optional string text = 6; +} + +message Code { + optional sint64 endLine = 1; + optional string info = 2; + repeated _Subclasses_of_class_Node nodes = 3; + optional sint64 startLine = 4; + optional string text = 5; +} + +message HtmlInline { + optional sint64 endLine = 1; + repeated _Subclasses_of_class_Node nodes = 2; + optional sint64 startLine = 3; + optional TagInfo tag = 4; + optional string text = 5; +} + +message HtmlBlock { + optional sint64 endLine = 1; + repeated _Subclasses_of_class_Node nodes = 2; + optional sint64 startLine = 3; + optional TagInfo tag = 4; + optional string text = 5; +} + +message Emph { + optional sint64 endLine = 1; + repeated _Subclasses_of_class_Node nodes = 2; + optional sint64 startLine = 3; + optional string text = 4; +} + +message Strong { + optional sint64 endLine = 1; + repeated _Subclasses_of_class_Node nodes = 2; + optional sint64 startLine = 3; + optional string text = 4; +} + +message BlockQuote { + optional sint64 endLine = 1; + repeated _Subclasses_of_class_Node nodes = 2; + optional sint64 startLine = 3; + optional string text = 4; +} + +message Heading { + optional sint64 endLine = 1; + string level = 2; + repeated _Subclasses_of_class_Node nodes = 3; + optional sint64 startLine = 4; + optional string text = 5; +} + +message ThematicBreak { + optional sint64 endLine = 1; + repeated _Subclasses_of_class_Node nodes = 2; + optional sint64 startLine = 3; + optional string text = 4; +} + +message Softbreak { + optional sint64 endLine = 1; + repeated _Subclasses_of_class_Node nodes = 2; + optional sint64 startLine = 3; + optional string text = 4; +} + +message Linebreak { + optional sint64 endLine = 1; + repeated _Subclasses_of_class_Node nodes = 2; + optional sint64 startLine = 3; + optional string text = 4; +} + +message Link { + string destination = 1; + optional sint64 endLine = 2; + repeated _Subclasses_of_class_Node nodes = 3; + optional sint64 startLine = 4; + optional string text = 5; + string title = 6; +} + +message Image { + string destination = 1; + optional sint64 endLine = 2; + repeated _Subclasses_of_class_Node nodes = 3; + optional sint64 startLine = 4; + optional string text = 5; + string title = 6; +} + +message Paragraph { + optional sint64 endLine = 1; + repeated _Subclasses_of_class_Node nodes = 2; + optional sint64 startLine = 3; + optional string text = 4; +} + +message List { + optional string delimiter = 1; + optional sint64 endLine = 2; + repeated _Subclasses_of_class_Node nodes = 3; + optional string start = 4; + optional sint64 startLine = 5; + optional string text = 6; + string tight = 7; + string type = 8; +} + +message Item { + optional sint64 endLine = 1; + repeated _Subclasses_of_class_Node nodes = 2; + optional sint64 startLine = 3; + optional string text = 4; +} + +message Document { + optional sint64 endLine = 1; + repeated _Subclasses_of_class_Node nodes = 2; + optional sint64 startLine = 3; + optional string text = 4; + string xmlns = 5; +} + +message Table { + optional sint64 endLine = 1; + repeated _Subclasses_of_class_Node nodes = 2; + optional sint64 startLine = 3; + optional string text = 4; +} + +message TableHead { + optional sint64 endLine = 1; + repeated _Subclasses_of_class_Node nodes = 2; + optional sint64 startLine = 3; + optional string text = 4; +} + +message TableBody { + optional sint64 endLine = 1; + repeated _Subclasses_of_class_Node nodes = 2; + optional sint64 startLine = 3; + optional string text = 4; +} + +message TableRow { + optional sint64 endLine = 1; + repeated _Subclasses_of_class_Node nodes = 2; + optional sint64 startLine = 3; + optional string text = 4; +} + +message HeaderCell { + optional sint64 endLine = 1; + repeated _Subclasses_of_class_Node nodes = 2; + optional sint64 startLine = 3; + optional string text = 4; +} + +message TableCell { + optional sint64 endLine = 1; + repeated _Subclasses_of_class_Node nodes = 2; + optional sint64 startLine = 3; + optional string text = 4; +} + diff --git a/packages/concerto-tools/test/codegen/fromcto/protobuf/data/org.accordproject.party.v0_2_0-expected.proto b/packages/concerto-tools/test/codegen/fromcto/protobuf/data/org.accordproject.party.v0_2_0-expected.proto new file mode 100644 index 0000000000..8c05f666b6 --- /dev/null +++ b/packages/concerto-tools/test/codegen/fromcto/protobuf/data/org.accordproject.party.v0_2_0-expected.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; + +package org.accordproject.party.v0_2_0; + +import "google/protobuf/timestamp.proto"; + +message Party { + string partyId = 1; +} + +message _Subclasses_of_class_Party { + oneof _class_oneof_Party { + AgreementParty _subclass_of_class_Party_AgreementParty = 1; + Party _subclass_of_class_Party_Party = 2; + } +} + diff --git a/packages/concerto-tools/test/codegen/fromcto/protobuf/data/org.accordproject.protocol.v1_0_0-expected.proto b/packages/concerto-tools/test/codegen/fromcto/protobuf/data/org.accordproject.protocol.v1_0_0-expected.proto new file mode 100644 index 0000000000..42b43a873c --- /dev/null +++ b/packages/concerto-tools/test/codegen/fromcto/protobuf/data/org.accordproject.protocol.v1_0_0-expected.proto @@ -0,0 +1,172 @@ +syntax = "proto3"; + +package org.accordproject.protocol.v1_0_0; + +import "google/protobuf/timestamp.proto"; +import "concerto.metamodel.v0_4_0.proto"; +import "org.accordproject.commonmark.v0_5_0.proto"; +import "org.accordproject.party.v0_2_0.proto"; + +message Blob { + string base64 = 1; + string mimeType = 2; +} + +message Text { + Document templateMark = 1; +} + +message TemplateModel { + optional Model model = 1; + optional string sharedModel = 2; + string typeName = 3; +} + +message SharedModel { + Model model = 1; + string modelId = 2; +} + +enum CodeType { + CodeType_ES2015 = 0; + CodeType_WASM_BYTES = 1; +} + +enum CodeEncodingType { + CodeEncodingType_BASE64 = 0; + CodeEncodingType_PLAIN_TEXT = 1; +} + +message Code { + CodeEncodingType encoding = 1; + CodeType type = 2; + string value = 3; +} + +message Function { + Code code = 1; + string emittedTypes = 2; + string name = 3; + string requestType = 4; + string responseType = 5; +} + +message Logic { + repeated Function functions = 1; + string stateType = 2; +} + +message Template { + string author = 1; + optional string description = 2; + optional string displayName = 3; + repeated string keywords = 4; + string license = 5; + optional Logic logic = 6; + optional Blob logo = 7; + string name = 8; + TemplateModel templateModel = 9; + Text text = 10; + string version = 11; +} + +message KeyValue { + string key = 1; + string value = 2; +} + +message Metadata { + repeated KeyValue values = 1; +} + +message Agreement { + string agreementId = 1; + repeated AgreementParty agreementParties = 2; + AgreementStatusType agreementStatus = 3; + repeated Blob attachments = 4; + string data = 5; + repeated HistoryEntry historyEntries = 6; + Metadata metadata = 7; + repeated string references = 8; + repeated Signature signatures = 9; + string state = 10; + string template = 11; +} + +message AgreementParty { + optional Address address = 1; + optional string company = 2; + optional string email = 3; + string name = 4; + optional string network = 5; + string partyId = 6; + optional string phone = 7; + optional string role = 8; + bool signatory = 9; +} + +message Address { + optional string country = 1; + optional string postalCode = 2; + optional string stateTerritoryRegion = 3; + repeated string streetRoad = 4; + optional string suburbTownCity = 5; +} + +message HistoryEntry { + AgreementStatusType agreementStatus = 1; + string data = 2; + Metadata metadata = 3; +} + +message Signature { + Metadata metadata = 1; + AgreementParty signatory = 2; + repeated Blob signatureImage = 3; + optional google.protobuf.Timestamp signedAt = 4; +} + +message _Subclasses_of_class_ConversionOptions { + oneof _class_oneof_ConversionOptions { + PdfConversionOptions _subclass_of_class_ConversionOptions_PdfConversionOptions = 1; + } +} + +message PdfConversionOptions { + string styles = 1; +} + +enum FeatureType { + FeatureType_AGREEMENT_CONVERT_PDF = 0; + FeatureType_AGREEMENT_MANAGE = 1; + FeatureType_AGREEMENT_STATE = 2; + FeatureType_AGREEMENT_TRIGGER = 3; + FeatureType_SHARED_MODEL_MANAGE = 4; + FeatureType_TEMPLATE_LOGIC = 5; + FeatureType_TEMPLATE_STATEFUL = 6; + FeatureType_TEMPLATE_VERIFY_SIGNATURES = 7; +} + +message Capabilities { + repeated FeatureType features = 1; +} + +message TriggerRequest { + string functionName = 1; + string payload = 2; +} + +message TriggerResponse { + optional string errorDetails = 1; + optional string errorMessage = 2; + bool isError = 3; + string result = 4; +} + +enum AgreementStatusType { + AgreementStatusType_COMPLETED = 0; + AgreementStatusType_DRAFT = 1; + AgreementStatusType_SIGNNG = 2; + AgreementStatusType_SUPERSEDED = 3; +} + diff --git a/packages/concerto-tools/test/codegen/fromcto/protobuf/protobufvisitor.js b/packages/concerto-tools/test/codegen/fromcto/protobuf/protobufvisitor.js index e74d37ba72..6fe741f25f 100644 --- a/packages/concerto-tools/test/codegen/fromcto/protobuf/protobufvisitor.js +++ b/packages/concerto-tools/test/codegen/fromcto/protobuf/protobufvisitor.js @@ -16,12 +16,18 @@ const chai = require('chai'); chai.should(); +const { assert } = chai; const sinon = require('sinon'); +const fs = require('fs'); +const path = require('path'); -const ProtobufVisitor = require('../../../../lib/codegen/fromcto/protobuf/protobufvisitor.js'); +const ProtobufVisitor = require( + '../../../../lib/codegen/fromcto/protobuf/protobufvisitor.js' +); const ModelFile = require('@accordproject/concerto-core').ModelFile; const ModelManager = require('@accordproject/concerto-core').ModelManager; +const ModelLoader = require('@accordproject/concerto-core').ModelLoader; const AssetDeclaration = require('@accordproject/concerto-core').AssetDeclaration; const ClassDeclaration = require('@accordproject/concerto-core').ClassDeclaration; const EnumDeclaration = require('@accordproject/concerto-core').EnumDeclaration; @@ -30,6 +36,7 @@ const Field = require('@accordproject/concerto-core').Field; const RelationshipDeclaration = require('@accordproject/concerto-core').RelationshipDeclaration; const TransactionDeclaration = require('@accordproject/concerto-core').TransactionDeclaration; const FileWriter = require('@accordproject/concerto-util').FileWriter; +const { InMemoryWriter } = require('@accordproject/concerto-util'); describe('ProtobufVisitor', function () { let protobufVisitor; @@ -390,4 +397,68 @@ describe('ProtobufVisitor', function () { param.fileWriter.writeLine.getCall(0).args.should.deep.equal([0, ' repeated string Bob = 0;']); }); }); + + describe('visit CTO file', () => { + it('should process an APAP protocol CTO file', async () => { + const modelManager = await ModelLoader.loadModelManager( + [path.resolve(__dirname, './data/apapProtocol.cto')] + ); + const writer = new InMemoryWriter(); + + modelManager.accept( + new ProtobufVisitor(), { + fileWriter: writer + } + ); + + const expectedMetamodelProtobuf = fs.readFileSync( + path.resolve( + __dirname, + './data/concerto.metamodel.v0_4_0-expected.proto' + ), + 'utf8' + ); + const expectedCommonmarkProtobuf = fs.readFileSync( + path.resolve( + __dirname, + './data/org.accordproject.commonmark.v0_5_0-expected.proto' + ), + 'utf8' + ); + const expectedApapPartyProtobuf = fs.readFileSync( + path.resolve( + __dirname, + './data/org.accordproject.party.v0_2_0-expected.proto' + ), + 'utf8' + ); + const expectedApapProtocolProtobuf = fs.readFileSync( + path.resolve( + __dirname, + './data/org.accordproject.protocol.v1_0_0-expected.proto' + ), + 'utf8' + ); + + assert.equal( + writer.data.get('concerto.metamodel.v0_4_0.proto'), + expectedMetamodelProtobuf.replace(/\r\n/g, '\n') + ); + + assert.equal( + writer.data.get('org.accordproject.commonmark.v0_5_0.proto'), + expectedCommonmarkProtobuf.replace(/\r\n/g, '\n') + ); + + assert.equal( + writer.data.get('org.accordproject.party.v0_2_0.proto'), + expectedApapPartyProtobuf.replace(/\r\n/g, '\n') + ); + + assert.equal( + writer.data.get('org.accordproject.protocol.v1_0_0.proto'), + expectedApapProtocolProtobuf.replace(/\r\n/g, '\n') + ); + }); + }); });