├── examples ├── .gitignore ├── proto │ ├── fabric │ │ ├── contract.proto │ │ └── metadata.proto │ ├── google │ │ ├── api │ │ │ └── annotations.proto │ │ └── protobuf │ │ │ ├── source_context.proto │ │ │ ├── empty.proto │ │ │ ├── struct.proto │ │ │ ├── wrappers.proto │ │ │ ├── duration.proto │ │ │ ├── timestamp.proto │ │ │ └── any.proto │ ├── basic-asset.proto │ └── AssetTransfer.proto └── go ├── dist ├── index.d.ts ├── cli.d.ts ├── protoc-plugin │ ├── protoc-gen-fabart.d.ts │ ├── google │ │ ├── api │ │ │ ├── annotations_pb.d.ts │ │ │ ├── annotations_pb.js │ │ │ └── http_pb.d.ts │ │ └── protobuf │ │ │ └── compiler │ │ │ └── plugin_pb.d.ts │ ├── fabric │ │ ├── contract_pb.d.ts │ │ └── metadata_pb.d.ts │ ├── hyperledger │ │ └── fabric │ │ │ ├── contract_pb.d.ts │ │ │ └── metadata_pb.d.ts │ ├── index.d.ts │ ├── index.js.map │ ├── index.js │ └── protoc-gen-fabart.js.map ├── config.d.ts ├── config.js ├── index.js ├── index.js.map ├── config.js.map ├── factory.js ├── factory.js.map ├── factory.d.ts ├── templates │ ├── metadata │ │ ├── cfg.yaml │ │ └── metadata-json.njk │ ├── singlepagesummary │ │ ├── cfg.yaml │ │ └── singleSummary-md.njk │ ├── domain_adts_ts │ │ ├── cfg.yaml │ │ └── class.njk │ ├── client_ts │ │ ├── cfg.yaml │ │ └── class.njk │ ├── client_java │ │ ├── cfg.yaml │ │ └── class.njk │ ├── domain_adts_java │ │ ├── cfg.yaml │ │ └── class.njk │ ├── contract_ts │ │ ├── cfg.yaml │ │ └── class.njk │ └── contract_java │ │ ├── cfg.yaml │ │ └── class.njk ├── conversionfactory.d.ts ├── resourcefactory.d.ts ├── cli.js.map ├── conversionfactory.js.map ├── cli.js ├── conversionfactory.js ├── resourcefactory.js.map ├── resourcefactory.js └── visitor.d.ts ├── src ├── index.ts ├── protos │ ├── fabric │ │ ├── contract.proto │ │ └── metadata.proto │ └── google │ │ ├── api │ │ └── annotations.proto │ │ └── protobuf │ │ ├── source_context.proto │ │ ├── empty.proto │ │ ├── struct.proto │ │ ├── wrappers.proto │ │ ├── duration.proto │ │ ├── timestamp.proto │ │ └── any.proto ├── config.ts ├── factory.ts ├── protoc-plugin │ ├── google │ │ ├── api │ │ │ ├── annotations_pb.d.ts │ │ │ ├── annotations_pb.js │ │ │ └── http_pb.d.ts │ │ └── protobuf │ │ │ └── compiler │ │ │ └── plugin_pb.d.ts │ ├── fabric │ │ ├── contract_pb.d.ts │ │ └── metadata_pb.d.ts │ ├── index.ts │ └── protoc-gen-fabart.ts ├── cli.ts ├── conversionfactory.ts └── resourcefactory.ts ├── templates ├── singlepagesummary │ ├── cfg.yaml │ └── singleSummary-md.njk ├── domain_adts_ts │ ├── cfg.yaml │ └── class.njk ├── contract_rust │ ├── cfg.yaml │ └── rustclass.njk ├── client_ts │ ├── cfg.yaml │ └── class.njk ├── client_java │ ├── cfg.yaml │ └── class.njk ├── domain_adts_java │ ├── cfg.yaml │ └── class.njk ├── contract_ts │ ├── cfg.yaml │ └── class.njk └── contract_java │ ├── cfg.yaml │ └── class.njk ├── tsconfig.json ├── tslint.json ├── generated ├── fabric │ ├── contract_pb.d.ts │ └── metadata_pb.d.ts └── hyperledger │ └── fabric │ ├── contract_pb.d.ts │ └── metadata_pb.d.ts ├── .gitignore ├── README.md ├── .npmignore └── package.json /examples/.gitignore: -------------------------------------------------------------------------------- 1 | generated -------------------------------------------------------------------------------- /dist/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './factory'; 2 | -------------------------------------------------------------------------------- /dist/cli.d.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | export {}; 3 | -------------------------------------------------------------------------------- /dist/protoc-plugin/protoc-gen-fabart.d.ts: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | export {}; 3 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | 2 | 'use strict'; 3 | /* 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | export * from './factory'; 8 | -------------------------------------------------------------------------------- /dist/config.d.ts: -------------------------------------------------------------------------------- 1 | export default interface Config { 2 | input: string; 3 | output: string; 4 | task: string; 5 | } 6 | -------------------------------------------------------------------------------- /dist/config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=config.js.map -------------------------------------------------------------------------------- /dist/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /dist/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,CAAC"} -------------------------------------------------------------------------------- /dist/config.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC"} -------------------------------------------------------------------------------- /dist/factory.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=factory.js.map -------------------------------------------------------------------------------- /dist/factory.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"factory.js","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC"} -------------------------------------------------------------------------------- /src/protos/fabric/contract.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package fabric; 4 | 5 | message ContractResult { 6 | int32 code = 1; 7 | string msg = 2; 8 | } 9 | -------------------------------------------------------------------------------- /examples/proto/fabric/contract.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package fabric; 4 | 5 | message ContractResult { 6 | int32 code = 1; 7 | string msg = 2; 8 | } 9 | -------------------------------------------------------------------------------- /src/config.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | export default interface Config { 7 | input: string; 8 | output: string; 9 | task: string; 10 | } 11 | -------------------------------------------------------------------------------- /dist/factory.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Then call start() to produce the documentation 3 | */ 4 | export default interface Factory { 5 | /** Starts the factory generating output based on the template configuration 6 | * 7 | */ 8 | start(): Promise; 9 | } 10 | -------------------------------------------------------------------------------- /src/factory.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | /** 8 | * Then call start() to produce the documentation 9 | */ 10 | export default interface Factory { 11 | 12 | /** Starts the factory generating output based on the template configuration 13 | * 14 | */ 15 | start(): Promise; 16 | } 17 | -------------------------------------------------------------------------------- /dist/templates/metadata/cfg.yaml: -------------------------------------------------------------------------------- 1 | cfg: 2 | name: Metadata 3 | description: Internal Metadata 4 | # The version of the metadata schema this generator can handle 5 | schemaref: version1 6 | filter: > 7 | [ 8 | { 9 | "_filename":"metadata", 10 | "_extension":".json", 11 | "_data":$$, 12 | "_template":"./metadata-json.njk", 13 | "_prettier":"none" 14 | } 15 | ] -------------------------------------------------------------------------------- /dist/protoc-plugin/google/api/annotations_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: google.api 2 | // file: google/api/annotations.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as google_api_http_pb from "../../google/api/http_pb"; 6 | import * as google_protobuf_descriptor_pb from "google-protobuf/google/protobuf/descriptor_pb"; 7 | 8 | export const http: jspb.ExtensionFieldInfo; 9 | 10 | -------------------------------------------------------------------------------- /src/protoc-plugin/google/api/annotations_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: google.api 2 | // file: google/api/annotations.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as google_api_http_pb from "../../google/api/http_pb"; 6 | import * as google_protobuf_descriptor_pb from "google-protobuf/google/protobuf/descriptor_pb"; 7 | 8 | export const http: jspb.ExtensionFieldInfo; 9 | 10 | -------------------------------------------------------------------------------- /templates/singlepagesummary/cfg.yaml: -------------------------------------------------------------------------------- 1 | cfg: 2 | name: SinglePageMarkdown 3 | description: Single page summary of contract 4 | # The version of the metadata schema this generator can handle 5 | schemaref: version1 6 | filter: > 7 | [ 8 | { 9 | "_filename":"docs", 10 | "_extension":".md", 11 | "_data":$$, 12 | "_template":"./singleSummary-md.njk", 13 | "_prettier":"none" 14 | } 15 | ] -------------------------------------------------------------------------------- /dist/templates/singlepagesummary/cfg.yaml: -------------------------------------------------------------------------------- 1 | cfg: 2 | name: SinglePageMarkdown 3 | description: Single page summary of contract 4 | # The version of the metadata schema this generator can handle 5 | schemaref: version1 6 | filter: > 7 | [ 8 | { 9 | "_filename":"docs", 10 | "_extension":".md", 11 | "_data":$$, 12 | "_template":"./singleSummary-md.njk", 13 | "_prettier":"none" 14 | } 15 | ] -------------------------------------------------------------------------------- /templates/domain_adts_ts/cfg.yaml: -------------------------------------------------------------------------------- 1 | cfg: 2 | name: domain_adts_ts 3 | description: Single class of contract 4 | # The version of the metadata schema this generator can handle 5 | schemaref: version1 6 | filter: > 7 | [ 8 | components.schemas.$keys().{ 9 | "_filename":$, 10 | "_extension":".ts", 11 | "_data":$lookup($$.components.schemas,$), 12 | "_template":"class.njk", 13 | "_prettier": "none" 14 | } 15 | ] -------------------------------------------------------------------------------- /dist/templates/domain_adts_ts/cfg.yaml: -------------------------------------------------------------------------------- 1 | cfg: 2 | name: domain_adts_ts 3 | description: Single class of contract 4 | # The version of the metadata schema this generator can handle 5 | schemaref: version1 6 | filter: > 7 | [ 8 | components.schemas.$keys().{ 9 | "_filename":$, 10 | "_extension":".ts", 11 | "_data":$lookup($$.components.schemas,$), 12 | "_template":"class.njk", 13 | "_prettier": "none" 14 | } 15 | ] -------------------------------------------------------------------------------- /templates/contract_rust/cfg.yaml: -------------------------------------------------------------------------------- 1 | cfg: 2 | name: contract_rust 3 | description: Single class of contract 4 | # The version of the metadata schema this generator can handle 5 | schemaref: version1 6 | filter: > 7 | [ 8 | contracts.$keys().{ 9 | "_filename":$, 10 | "_extension":".rs", 11 | "_data": { "contract": $lookup($$.contracts,$) , "components": $$.components }, 12 | "_template":"rustclass.njk", 13 | "_prettier": "none" 14 | } 15 | ] -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "dist", 4 | "target": "es2017", 5 | "moduleResolution": "node", 6 | "module": "commonjs", 7 | "declaration": true, 8 | "experimentalDecorators": true, 9 | "emitDecoratorMetadata": true, 10 | "sourceMap":true 11 | }, 12 | "include": [ 13 | "./src/**/*" 14 | ], 15 | "exclude": [ 16 | "./test/**/*", 17 | "node_modules" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /dist/conversionfactory.d.ts: -------------------------------------------------------------------------------- 1 | import Config from './config'; 2 | /** 3 | * Resource Factory 4 | * 5 | * Create an instance with an IConfig object 6 | * Then call start() to produce the documentation 7 | */ 8 | export default class ConversionFactory { 9 | private resolvedFilename; 10 | private data; 11 | private output; 12 | constructor(config: Config); 13 | /** Starts the factory generating output based on the template configuration 14 | * 15 | */ 16 | start(): Promise; 17 | } 18 | -------------------------------------------------------------------------------- /templates/client_ts/cfg.yaml: -------------------------------------------------------------------------------- 1 | cfg: 2 | name: client_ts 3 | description: Single class of contract 4 | # The version of the metadata schema this generator can handle 5 | schemaref: version1 6 | filter: > 7 | [ 8 | contracts.$keys().{ 9 | "_filename":$, 10 | "_extension":".ts", 11 | "_data":$lookup($$.contracts,$), 12 | "_template":"class.njk", 13 | "_prettier": { "parser":"typescript" , "options":{ 14 | "trailingComma":"all", 15 | "singleQuote":"true" 16 | } 17 | } 18 | } 19 | ] -------------------------------------------------------------------------------- /dist/templates/client_ts/cfg.yaml: -------------------------------------------------------------------------------- 1 | cfg: 2 | name: client_ts 3 | description: Single class of contract 4 | # The version of the metadata schema this generator can handle 5 | schemaref: version1 6 | filter: > 7 | [ 8 | contracts.$keys().{ 9 | "_filename":$, 10 | "_extension":".ts", 11 | "_data":$lookup($$.contracts,$), 12 | "_template":"class.njk", 13 | "_prettier": { "parser":"typescript" , "options":{ 14 | "trailingComma":"all", 15 | "singleQuote":"true" 16 | } 17 | } 18 | } 19 | ] -------------------------------------------------------------------------------- /templates/client_java/cfg.yaml: -------------------------------------------------------------------------------- 1 | cfg: 2 | name: client_ts 3 | description: Single class of contract 4 | # The version of the metadata schema this generator can handle 5 | schemaref: version1 6 | filter: > 7 | [ 8 | contracts.$keys().{ 9 | "_filename":$, 10 | "_extension":".ts", 11 | "_data":$lookup($$.contracts,$), 12 | "_template":"class.njk", 13 | "_prettier": { "parser":"typescript" , "options":{ 14 | "trailingComma":"all", 15 | "singleQuote":"true" 16 | } 17 | } 18 | } 19 | ] -------------------------------------------------------------------------------- /dist/templates/client_java/cfg.yaml: -------------------------------------------------------------------------------- 1 | cfg: 2 | name: client_ts 3 | description: Single class of contract 4 | # The version of the metadata schema this generator can handle 5 | schemaref: version1 6 | filter: > 7 | [ 8 | contracts.$keys().{ 9 | "_filename":$, 10 | "_extension":".ts", 11 | "_data":$lookup($$.contracts,$), 12 | "_template":"class.njk", 13 | "_prettier": { "parser":"typescript" , "options":{ 14 | "trailingComma":"all", 15 | "singleQuote":"true" 16 | } 17 | } 18 | } 19 | ] -------------------------------------------------------------------------------- /templates/domain_adts_java/cfg.yaml: -------------------------------------------------------------------------------- 1 | cfg: 2 | name: domain_adts_ts 3 | description: Single class of contract 4 | # The version of the metadata schema this generator can handle 5 | schemaref: version1 6 | filter: > 7 | [ 8 | components.schemas.$keys().{ 9 | "_filename":$, 10 | "_extension":".ts", 11 | "_data":$lookup($$.components.schemas,$), 12 | "_template":"class.njk", 13 | "_prettier": { "parser":"typescript" , "options":{ 14 | "trailingComma":"all", 15 | "singleQuote":"true" 16 | } 17 | } 18 | } 19 | ] -------------------------------------------------------------------------------- /dist/templates/domain_adts_java/cfg.yaml: -------------------------------------------------------------------------------- 1 | cfg: 2 | name: domain_adts_ts 3 | description: Single class of contract 4 | # The version of the metadata schema this generator can handle 5 | schemaref: version1 6 | filter: > 7 | [ 8 | components.schemas.$keys().{ 9 | "_filename":$, 10 | "_extension":".ts", 11 | "_data":$lookup($$.components.schemas,$), 12 | "_template":"class.njk", 13 | "_prettier": { "parser":"typescript" , "options":{ 14 | "trailingComma":"all", 15 | "singleQuote":"true" 16 | } 17 | } 18 | } 19 | ] -------------------------------------------------------------------------------- /templates/contract_ts/cfg.yaml: -------------------------------------------------------------------------------- 1 | cfg: 2 | name: contract_ts 3 | description: Single class of contract 4 | # The version of the metadata schema this generator can handle 5 | schemaref: version1 6 | filter: > 7 | [ 8 | contracts.$keys().{ 9 | "_filename":$, 10 | "_extension":".ts", 11 | "_data": { "contract": $lookup($$.contracts,$) , "components": $$.components }, 12 | "_template":"class.njk", 13 | "_prettier": { "parser":"typescript" , 14 | "trailingComma":"all", 15 | "singleQuote":true, "tabWidth":4 16 | 17 | } 18 | } 19 | ] -------------------------------------------------------------------------------- /dist/templates/contract_ts/cfg.yaml: -------------------------------------------------------------------------------- 1 | cfg: 2 | name: contract_ts 3 | description: Single class of contract 4 | # The version of the metadata schema this generator can handle 5 | schemaref: version1 6 | filter: > 7 | [ 8 | contracts.$keys().{ 9 | "_filename":$, 10 | "_extension":".ts", 11 | "_data": { "contract": $lookup($$.contracts,$) , "components": $$.components }, 12 | "_template":"class.njk", 13 | "_prettier": { "parser":"typescript" , 14 | "trailingComma":"all", 15 | "singleQuote":true, "tabWidth":4 16 | 17 | } 18 | } 19 | ] -------------------------------------------------------------------------------- /templates/contract_java/cfg.yaml: -------------------------------------------------------------------------------- 1 | cfg: 2 | name: contract_ts 3 | description: Single class of contract 4 | # The version of the metadata schema this generator can handle 5 | schemaref: version1 6 | filter: > 7 | [ 8 | contracts.$keys().{ 9 | "_filename":$, 10 | "_extension":".ts", 11 | "_data": { "contract": $lookup($$.contracts,$) , "components": $$.components }, 12 | "_template":"class.njk", 13 | "_prettier": { "parser":"typescript" , 14 | "trailingComma":"all", 15 | "singleQuote":true, "tabWidth":4 16 | 17 | } 18 | } 19 | ] -------------------------------------------------------------------------------- /dist/templates/contract_java/cfg.yaml: -------------------------------------------------------------------------------- 1 | cfg: 2 | name: contract_ts 3 | description: Single class of contract 4 | # The version of the metadata schema this generator can handle 5 | schemaref: version1 6 | filter: > 7 | [ 8 | contracts.$keys().{ 9 | "_filename":$, 10 | "_extension":".ts", 11 | "_data": { "contract": $lookup($$.contracts,$) , "components": $$.components }, 12 | "_template":"class.njk", 13 | "_prettier": { "parser":"typescript" , 14 | "trailingComma":"all", 15 | "singleQuote":true, "tabWidth":4 16 | 17 | } 18 | } 19 | ] -------------------------------------------------------------------------------- /dist/resourcefactory.d.ts: -------------------------------------------------------------------------------- 1 | import Config from './config'; 2 | import Factory from './factory'; 3 | /** 4 | * Resource Factory 5 | * 6 | * Create an instance with an IConfig object 7 | * Then call start() to produce the documentation 8 | */ 9 | export default class ResourceFactory implements Factory { 10 | private resolvedFilename; 11 | private jsonData; 12 | private templateRoot; 13 | private templateCfg; 14 | private output; 15 | private env; 16 | constructor(config: Config); 17 | /** Starts the factory generating output based on the template configuration 18 | * 19 | */ 20 | start(): Promise; 21 | } 22 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "defaultSeverity": "error", 3 | "extends": [ 4 | "tslint:recommended" 5 | ], 6 | "jsRules": {}, 7 | "rules": { 8 | "indent": [true, "spaces", 4], 9 | "linebreak-style": [true, "LF"], 10 | "quotemark": [true, "single"], 11 | "semicolon": [true, "always"], 12 | "no-console": false, 13 | "curly": true, 14 | "triple-equals": true, 15 | "no-string-throw": true, 16 | "no-var-keyword": true, 17 | "no-trailing-whitespace": true, 18 | "object-literal-key-quotes": [true, "as-needed"], 19 | "interface-name": [true, "never-prefix"], 20 | "max-line-length": [true, 160] 21 | }, 22 | "rulesDirectory": [] 23 | } 24 | -------------------------------------------------------------------------------- /examples/go: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -xe 4 | DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 5 | echo ${DIR} 6 | # Plugins need to have their absolute paths supplied 7 | # 8 | PROTOC_PLUGIN=$(which protoc-gen-fabart) 9 | 10 | # run the protoc tool to parse the proto files, ensures everything is correct 11 | # outdirectory supplied, with possible options (for illustration currently) 12 | protoc --plugin="${PROTOC_PLUGIN}" -I ${DIR}/proto ${DIR}/proto/AssetTransfer.proto --fabart_out=json=y:${DIR}/generated 13 | 14 | # run the template generation side of the plugin here 15 | #DEBUG=* fabart create --localfile ${DIR}/generated/assettransfer-md.json --outputdir ${DIR}/generated/ --template contract_ts domain_adts_ts domain_adts_java client_java 16 | DEBUG=* fabart create --localfile ${DIR}/generated/assettransfer-md.json --outputdir ${DIR}/generated/ --template contract_ts domain_adts_ts contract_rust 17 | -------------------------------------------------------------------------------- /src/protos/fabric/metadata.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package fabric; 4 | 5 | import "google/protobuf/descriptor.proto"; 6 | 7 | message Serialization { 8 | 9 | oneof method { 10 | DefaultMethods defaultstyle = 1; 11 | string customid = 2; 12 | } 13 | 14 | enum DefaultMethods { 15 | UNKNOWN = 0; 16 | JSON = 1; 17 | PROTOBUF = 2; 18 | } 19 | 20 | } 21 | 22 | extend google.protobuf.MessageOptions { 23 | Serialization network_serialization = 1501000; 24 | Serialization ledger_serialization = 1501001; 25 | } 26 | 27 | message Typing { 28 | Formats format = 1; 29 | enum Formats { 30 | UNKNOWN = 0; 31 | DATE_TIME= 1; // RFC 3339 32 | BYTE = 2; // base64 encoded 33 | } 34 | string pattern = 2; // (a valid regular expression, according to the Ecma-262 Edition 5.1 regular expression dialect) 35 | } 36 | 37 | extend google.protobuf.FieldOptions { 38 | Typing typeInfo = 1401000; 39 | bool transient = 1401001; 40 | } 41 | -------------------------------------------------------------------------------- /examples/proto/fabric/metadata.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package fabric; 4 | 5 | import "google/protobuf/descriptor.proto"; 6 | 7 | message Serialization { 8 | 9 | oneof method { 10 | DefaultMethods defaultstyle = 1; 11 | string customid = 2; 12 | } 13 | 14 | enum DefaultMethods { 15 | UNKNOWN = 0; 16 | JSON = 1; 17 | PROTOBUF = 2; 18 | } 19 | 20 | } 21 | 22 | extend google.protobuf.MessageOptions { 23 | Serialization network_serialization = 1501000; 24 | Serialization ledger_serialization = 1501001; 25 | } 26 | 27 | message Typing { 28 | Formats format = 1; 29 | enum Formats { 30 | UNKNOWN = 0; 31 | DATE_TIME= 1; // RFC 3339 32 | BYTE = 2; // base64 encoded 33 | } 34 | string pattern = 2; // (a valid regular expression, according to the Ecma-262 Edition 5.1 regular expression dialect) 35 | } 36 | 37 | extend google.protobuf.FieldOptions { 38 | Typing typeInfo = 1401000; 39 | bool transient = 1401001; 40 | } 41 | -------------------------------------------------------------------------------- /generated/fabric/contract_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: fabric 2 | // file: fabric/contract.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class ContractResult extends jspb.Message { 7 | getCode(): number; 8 | setCode(value: number): void; 9 | 10 | getMsg(): string; 11 | setMsg(value: string): void; 12 | 13 | serializeBinary(): Uint8Array; 14 | toObject(includeInstance?: boolean): ContractResult.AsObject; 15 | static toObject(includeInstance: boolean, msg: ContractResult): ContractResult.AsObject; 16 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 17 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 18 | static serializeBinaryToWriter(message: ContractResult, writer: jspb.BinaryWriter): void; 19 | static deserializeBinary(bytes: Uint8Array): ContractResult; 20 | static deserializeBinaryFromReader(message: ContractResult, reader: jspb.BinaryReader): ContractResult; 21 | } 22 | 23 | export namespace ContractResult { 24 | export type AsObject = { 25 | code: number, 26 | msg: string, 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /src/protoc-plugin/fabric/contract_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: fabric 2 | // file: fabric/contract.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class ContractResult extends jspb.Message { 7 | getCode(): number; 8 | setCode(value: number): void; 9 | 10 | getMsg(): string; 11 | setMsg(value: string): void; 12 | 13 | serializeBinary(): Uint8Array; 14 | toObject(includeInstance?: boolean): ContractResult.AsObject; 15 | static toObject(includeInstance: boolean, msg: ContractResult): ContractResult.AsObject; 16 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 17 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 18 | static serializeBinaryToWriter(message: ContractResult, writer: jspb.BinaryWriter): void; 19 | static deserializeBinary(bytes: Uint8Array): ContractResult; 20 | static deserializeBinaryFromReader(message: ContractResult, reader: jspb.BinaryReader): ContractResult; 21 | } 22 | 23 | export namespace ContractResult { 24 | export type AsObject = { 25 | code: number, 26 | msg: string, 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /dist/protoc-plugin/fabric/contract_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: fabric 2 | // file: fabric/contract.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class ContractResult extends jspb.Message { 7 | getCode(): number; 8 | setCode(value: number): void; 9 | 10 | getMsg(): string; 11 | setMsg(value: string): void; 12 | 13 | serializeBinary(): Uint8Array; 14 | toObject(includeInstance?: boolean): ContractResult.AsObject; 15 | static toObject(includeInstance: boolean, msg: ContractResult): ContractResult.AsObject; 16 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 17 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 18 | static serializeBinaryToWriter(message: ContractResult, writer: jspb.BinaryWriter): void; 19 | static deserializeBinary(bytes: Uint8Array): ContractResult; 20 | static deserializeBinaryFromReader(message: ContractResult, reader: jspb.BinaryReader): ContractResult; 21 | } 22 | 23 | export namespace ContractResult { 24 | export type AsObject = { 25 | code: number, 26 | msg: string, 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /generated/hyperledger/fabric/contract_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: hyperledger.fabric 2 | // file: hyperledger/fabric/contract.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class ContractResult extends jspb.Message { 7 | getCode(): number; 8 | setCode(value: number): void; 9 | 10 | getMsg(): string; 11 | setMsg(value: string): void; 12 | 13 | serializeBinary(): Uint8Array; 14 | toObject(includeInstance?: boolean): ContractResult.AsObject; 15 | static toObject(includeInstance: boolean, msg: ContractResult): ContractResult.AsObject; 16 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 17 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 18 | static serializeBinaryToWriter(message: ContractResult, writer: jspb.BinaryWriter): void; 19 | static deserializeBinary(bytes: Uint8Array): ContractResult; 20 | static deserializeBinaryFromReader(message: ContractResult, reader: jspb.BinaryReader): ContractResult; 21 | } 22 | 23 | export namespace ContractResult { 24 | export type AsObject = { 25 | code: number, 26 | msg: string, 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /dist/protoc-plugin/hyperledger/fabric/contract_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: hyperledger.fabric 2 | // file: hyperledger/fabric/contract.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class ContractResult extends jspb.Message { 7 | getCode(): number; 8 | setCode(value: number): void; 9 | 10 | getMsg(): string; 11 | setMsg(value: string): void; 12 | 13 | serializeBinary(): Uint8Array; 14 | toObject(includeInstance?: boolean): ContractResult.AsObject; 15 | static toObject(includeInstance: boolean, msg: ContractResult): ContractResult.AsObject; 16 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 17 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 18 | static serializeBinaryToWriter(message: ContractResult, writer: jspb.BinaryWriter): void; 19 | static deserializeBinary(bytes: Uint8Array): ContractResult; 20 | static deserializeBinaryFromReader(message: ContractResult, reader: jspb.BinaryReader): ContractResult; 21 | } 22 | 23 | export namespace ContractResult { 24 | export type AsObject = { 25 | code: number, 26 | msg: string, 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /templates/singlepagesummary/singleSummary-md.njk: -------------------------------------------------------------------------------- 1 | {% macro schema(s) -%} 2 | {% if s.type %} {{-s.type|trim-}} {% else %} {{-s.$ref|trim-}} {% endif %} 3 | {%- endmacro %} 4 | 5 | {% macro parameters(params) -%} 6 | {% for p in params -%} {{p.name}}:{{- schema(p.schema) -}} {%- if not loop.last -%}, {% endif -%} {%- endfor -%} 7 | {%- endmacro %} 8 | 9 | {% macro arglist(params) %} 10 | {% if params %} 11 | {% for p in params -%} JSON.stringify({{p.name}}) 12 | {%- if not loop.last -%}, {% endif -%} 13 | {%- endfor %} 14 | {%- endif %} 15 | {% endmacro %} 16 | 17 | # {{ info.title }} 18 | 19 | {{ info.title }} 20 | {{ info.version }} 21 | 22 | 23 | ## Contracts 24 | 25 | {% for key, contract in contracts %} 26 | ### {{key}} 27 | 28 | {% for tx in contract.transactions %} 29 | - {{tx.name}} :: {{ parameters(tx.parameters) }} 30 | {% endfor %} 31 | 32 | {% endfor %} 33 | 34 | ## Complex Data Types 35 | 36 | {% for key, type in components.schemas %} 37 | 38 | ### {{ key }} 39 | 40 | Properties for this type are: 41 | 42 | {% for propname, propdetails in type.properties %} 43 | | {{ propname }} | {{ propdetails.type }} | 44 | {% endfor %} 45 | 46 | {% endfor %} -------------------------------------------------------------------------------- /dist/templates/singlepagesummary/singleSummary-md.njk: -------------------------------------------------------------------------------- 1 | {% macro schema(s) -%} 2 | {% if s.type %} {{-s.type|trim-}} {% else %} {{-s.$ref|trim-}} {% endif %} 3 | {%- endmacro %} 4 | 5 | {% macro parameters(params) -%} 6 | {% for p in params -%} {{p.name}}:{{- schema(p.schema) -}} {%- if not loop.last -%}, {% endif -%} {%- endfor -%} 7 | {%- endmacro %} 8 | 9 | {% macro arglist(params) %} 10 | {% if params %} 11 | {% for p in params -%} JSON.stringify({{p.name}}) 12 | {%- if not loop.last -%}, {% endif -%} 13 | {%- endfor %} 14 | {%- endif %} 15 | {% endmacro %} 16 | 17 | # {{ info.title }} 18 | 19 | {{ info.title }} 20 | {{ info.version }} 21 | 22 | 23 | ## Contracts 24 | 25 | {% for key, contract in contracts %} 26 | ### {{key}} 27 | 28 | {% for tx in contract.transactions %} 29 | - {{tx.name}} :: {{ parameters(tx.parameters) }} 30 | {% endfor %} 31 | 32 | {% endfor %} 33 | 34 | ## Complex Data Types 35 | 36 | {% for key, type in components.schemas %} 37 | 38 | ### {{ key }} 39 | 40 | Properties for this type are: 41 | 42 | {% for propname, propdetails in type.properties %} 43 | | {{ propname }} | {{ propdetails.type }} | 44 | {% endfor %} 45 | 46 | {% endfor %} -------------------------------------------------------------------------------- /dist/protoc-plugin/index.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { CodeGeneratorRequest } from './google/protobuf/compiler/plugin_pb'; 3 | export default class Plugin { 4 | /** 5 | * Promise for incoming request, as CodeGeneratorRequest from google-protobuf 6 | * @param {stream} stdin Incoming stream, default: process.stdin 7 | * @return {Promise} Resolves to CodeGeneratorRequest from google-protobuf 8 | */ 9 | CodeGeneratorRequest(stdin?: NodeJS.ReadStream): Promise; 10 | /** 11 | * Promise for outgoing response, as CodeGeneratorResponse from google-protobuf 12 | * @param {stream} stdout Outgoing stream, default: process.stdout 13 | */ 14 | CodeGeneratorResponse(files: any, stdout?: NodeJS.WriteStream): void; 15 | /** 16 | * Convenience function for error-handlers 17 | * @param {stream} stdout Outgoing stream, default: process.stdout 18 | * @return {function} Error-handler that puts error into error-field of CodeGeneratorResponse and sends to stdout 19 | */ 20 | CodeGeneratorResponseError(err: any, stdout?: NodeJS.WriteStream): void; 21 | run(cb: any): Promise; 22 | } 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | dist -------------------------------------------------------------------------------- /src/protos/google/api/annotations.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.api; 18 | 19 | import "google/api/http.proto"; 20 | import "google/protobuf/descriptor.proto"; 21 | 22 | option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; 23 | option java_multiple_files = true; 24 | option java_outer_classname = "AnnotationsProto"; 25 | option java_package = "com.google.api"; 26 | option objc_class_prefix = "GAPI"; 27 | 28 | extend google.protobuf.MethodOptions { 29 | // See `HttpRule`. 30 | HttpRule http = 72295728; 31 | } 32 | -------------------------------------------------------------------------------- /examples/proto/google/api/annotations.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.api; 18 | 19 | import "google/api/http.proto"; 20 | import "google/protobuf/descriptor.proto"; 21 | 22 | option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; 23 | option java_multiple_files = true; 24 | option java_outer_classname = "AnnotationsProto"; 25 | option java_package = "com.google.api"; 26 | option objc_class_prefix = "GAPI"; 27 | 28 | extend google.protobuf.MethodOptions { 29 | // See `HttpRule`. 30 | HttpRule http = 72295728; 31 | } 32 | -------------------------------------------------------------------------------- /dist/templates/metadata/metadata-json.njk: -------------------------------------------------------------------------------- 1 | {% macro schema(s) -%} 2 | {% if s.type %} {{-s.type|trim-}} {% else %} {{-s.$ref|trim-}} {% endif %} 3 | {%- endmacro %} 4 | 5 | {% macro parameters(params) -%} 6 | {% for p in params -%} {{p.name}}:{{- schema(p.schema) -}} {%- if not loop.last -%}, {% endif -%} {%- endfor -%} 7 | {%- endmacro %} 8 | 9 | {% macro arglist(params) %} 10 | {% if params %} 11 | {% for p in params -%} JSON.stringify({{p.name}}) 12 | {%- if not loop.last -%}, {% endif -%} 13 | {%- endfor %} 14 | {%- endif %} 15 | {% endmacro %} 16 | 17 | { 18 | "$schema": "https://fabric-shim.github.io/release-1.4/contract-schema.json", 19 | "components": { 20 | "schemas": { 21 | } 22 | }, 23 | "contracts": { 24 | 25 | 26 | {% for f in file %} 27 | 28 | {% for s in f.service %} 29 | "{{ s.name}}" : { 30 | "name" : "{{s.name}}", 31 | "transactions" : [ 32 | {% for tx in s.method %} 33 | 34 | { 35 | "name" :"{{tx.name}}", 36 | "tag":"", 37 | "returns":"{{tx.inputType}}", 38 | "parameters":["{{tx.outputType}}"] 39 | } 40 | {%- if not loop.last -%}, {% endif -%} 41 | {% endfor %} 42 | 43 | 44 | ] 45 | } 46 | {% endfor %} 47 | 48 | {% endfor %} 49 | 50 | }, 51 | "info":{"title": "???", "version": "???" } 52 | } -------------------------------------------------------------------------------- /dist/cli.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,YAAY,CAAC;;AAEb;;EAEE;AACF,iCAA0B;AAC1B,+BAA+B;AAI/B,uDAAgD;AAEhD,MAAM,GAAG,GAAG,eAAK,CAAC,qBAAqB,CAAC,CAAC;AAEzC,MAAM,OAAO,GAAG,KAAK;KAChB,OAAO,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,kBAAkB,EAAE;IAC3C,SAAS,EAAE;QACP,KAAK,EAAE,GAAG;QACV,OAAO,EAAE,eAAe;QACxB,YAAY,EAAE,IAAI;QAClB,QAAQ,EAAE,mCAAmC;QAC7C,WAAW,EAAE,IAAI;KACpB;IACD,SAAS,EAAE;QACP,KAAK,EAAE,GAAG;QACV,OAAO,EAAE,KAAK;QACd,YAAY,EAAE,IAAI;QAClB,QAAQ,EAAE,sEAAsE;QAChF,WAAW,EAAE,IAAI;KACpB;IACD,QAAQ,EAAE;QACN,KAAK,EAAE,GAAG;QACV,OAAO,EAAE,mBAAmB;QAC5B,YAAY,EAAE,IAAI;QAClB,QAAQ,EAAE,8DAA8D;QACxE,KAAK,EAAE,IAAI;KACd;CAEJ,CAAC;KACD,IAAI,EAAE;KACN,IAAI,CAAC,IAAI,CAAC;KACV,KAAK,CAAC,GAAG,EAAE,SAAS,CAAC;KACrB,OAAO,CAAC,OAAO,CAAC;KAChB,QAAQ,CAAC,GAAG,EAAE,0BAA0B,CAAC;KACzC,MAAM,EAAE;KACR,IAAI,CAAC;AAEV,0BAA0B;AAC1B,IAAI,MAAc,CAAC;AACnB,IAAI,OAAO,GAAoB,EAAE,CAAC;AAElC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,EAAE;IACtC,MAAM,GAAG;QACL,KAAK,EAAE,OAAO,CAAC,SAAS;QACxB,MAAM,EAAE,OAAO,CAAC,SAAS;QACzB,IAAI,EAAE,YAAY;KACrB,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,IAAI,yBAAe,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;AACtD,CAAC,CAAC,CAAA;AAIF,GAAG,CAAC,uBAAuB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAErD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;IAC3B,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AACxB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACb,GAAG,CAAC,GAAG,CAAC,CAAC;IACT,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACrB,CAAC,CAAC,CAAC"} -------------------------------------------------------------------------------- /dist/conversionfactory.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"conversionfactory.js","sourceRoot":"","sources":["../src/conversionfactory.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb;;;EAGE;AACF,iCAA0B;AAC1B,yBAA0B;AAG1B,iCAAiC;AAEjC,6BAA8B;AAC9B,qCAAsC;AAGtC,yDAA6D;AAC7D,uCAAwC;AAExC,MAAM,GAAG,GAAG,eAAK,CAAC,yBAAyB,CAAC,CAAC;AAE7C;;;;;GAKG;AACH,MAAqB,iBAAiB;IAMlC,YAAmB,MAAc;QAE7B,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACnD,GAAG,CAAC,oBAAoB,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC;QAEjD,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;QAC3D,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC1C,GAAG,CAAC,iCAAiC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QACpD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE7B,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,KAAK;QACd,MAAM,YAAY,GAAG,IAAI,gCAAY,EAAE,CAAC;QACxC,MAAM,QAAQ,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACzC,MAAM,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;YACxC,OAAO,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;QACH,YAAY,CAAC,aAAa,CAAC,UAAU,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;QACvD,MAAM,YAAY,CAAC,oBAAoB,EAAE,CAAC;QAE1C,MAAM,OAAO,GAAG,IAAI,iBAAe,EAAE,CAAC;QAEtC,MAAM,UAAU,GAAG,EAAE,CAAC;QACtB,2DAA2D;QAC3D,MAAM,IAAI,GAAG,YAAY,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QACtD,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QAC7E,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC,EAAE,UAAU,CAAC,CAAC;IAC1E,CAAC;CACJ;AAtCD,oCAsCC"} -------------------------------------------------------------------------------- /generated/hyperledger/fabric/metadata_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: hyperledger.fabric 2 | // file: hyperledger/fabric/metadata.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as google_protobuf_descriptor_pb from "google-protobuf/google/protobuf/descriptor_pb"; 6 | 7 | export class Typing extends jspb.Message { 8 | getFormat(): Typing.FormatsMap[keyof Typing.FormatsMap]; 9 | setFormat(value: Typing.FormatsMap[keyof Typing.FormatsMap]): void; 10 | 11 | getPattern(): string; 12 | setPattern(value: string): void; 13 | 14 | serializeBinary(): Uint8Array; 15 | toObject(includeInstance?: boolean): Typing.AsObject; 16 | static toObject(includeInstance: boolean, msg: Typing): Typing.AsObject; 17 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 18 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 19 | static serializeBinaryToWriter(message: Typing, writer: jspb.BinaryWriter): void; 20 | static deserializeBinary(bytes: Uint8Array): Typing; 21 | static deserializeBinaryFromReader(message: Typing, reader: jspb.BinaryReader): Typing; 22 | } 23 | 24 | export namespace Typing { 25 | export type AsObject = { 26 | format: Typing.FormatsMap[keyof Typing.FormatsMap], 27 | pattern: string, 28 | } 29 | 30 | export interface FormatsMap { 31 | DATE_TIME: 0; 32 | BYTE: 1; 33 | } 34 | 35 | export const Formats: FormatsMap; 36 | } 37 | 38 | export const typeInfo: jspb.ExtensionFieldInfo; 39 | 40 | -------------------------------------------------------------------------------- /dist/protoc-plugin/hyperledger/fabric/metadata_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: hyperledger.fabric 2 | // file: hyperledger/fabric/metadata.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as google_protobuf_descriptor_pb from "google-protobuf/google/protobuf/descriptor_pb"; 6 | 7 | export class Typing extends jspb.Message { 8 | getFormat(): Typing.FormatsMap[keyof Typing.FormatsMap]; 9 | setFormat(value: Typing.FormatsMap[keyof Typing.FormatsMap]): void; 10 | 11 | getPattern(): string; 12 | setPattern(value: string): void; 13 | 14 | serializeBinary(): Uint8Array; 15 | toObject(includeInstance?: boolean): Typing.AsObject; 16 | static toObject(includeInstance: boolean, msg: Typing): Typing.AsObject; 17 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 18 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 19 | static serializeBinaryToWriter(message: Typing, writer: jspb.BinaryWriter): void; 20 | static deserializeBinary(bytes: Uint8Array): Typing; 21 | static deserializeBinaryFromReader(message: Typing, reader: jspb.BinaryReader): Typing; 22 | } 23 | 24 | export namespace Typing { 25 | export type AsObject = { 26 | format: Typing.FormatsMap[keyof Typing.FormatsMap], 27 | pattern: string, 28 | } 29 | 30 | export interface FormatsMap { 31 | DATE_TIME: 0; 32 | BYTE: 1; 33 | } 34 | 35 | export const Formats: FormatsMap; 36 | } 37 | 38 | export const typeInfo: jspb.ExtensionFieldInfo; 39 | 40 | -------------------------------------------------------------------------------- /dist/protoc-plugin/google/api/annotations_pb.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview 3 | * @enhanceable 4 | * @public 5 | */ 6 | // GENERATED CODE -- DO NOT EDIT! 7 | 8 | var jspb = require('google-protobuf'); 9 | var goog = jspb; 10 | var global = Function('return this')(); 11 | 12 | var google_api_http_pb = require('../../google/api/http_pb.js'); 13 | var google_protobuf_descriptor_pb = require('google-protobuf/google/protobuf/descriptor_pb.js'); 14 | goog.exportSymbol('proto.google.api.http', null, global); 15 | 16 | /** 17 | * A tuple of {field number, class constructor} for the extension 18 | * field named `http`. 19 | * @type {!jspb.ExtensionFieldInfo.} 20 | */ 21 | proto.google.api.http = new jspb.ExtensionFieldInfo( 22 | 72295728, 23 | {http: 0}, 24 | google_api_http_pb.HttpRule, 25 | /** @type {?function((boolean|undefined),!jspb.Message=): !Object} */ ( 26 | google_api_http_pb.HttpRule.toObject), 27 | 0); 28 | 29 | google_protobuf_descriptor_pb.MethodOptions.extensionsBinary[72295728] = new jspb.ExtensionFieldBinaryInfo( 30 | proto.google.api.http, 31 | jspb.BinaryReader.prototype.readMessage, 32 | jspb.BinaryWriter.prototype.writeMessage, 33 | google_api_http_pb.HttpRule.serializeBinaryToWriter, 34 | google_api_http_pb.HttpRule.deserializeBinaryFromReader, 35 | false); 36 | // This registers the extension field with the extended class, so that 37 | // toObject() will function correctly. 38 | google_protobuf_descriptor_pb.MethodOptions.extensions[72295728] = proto.google.api.http; 39 | 40 | goog.object.extend(exports, proto.google.api); 41 | -------------------------------------------------------------------------------- /src/protoc-plugin/google/api/annotations_pb.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview 3 | * @enhanceable 4 | * @public 5 | */ 6 | // GENERATED CODE -- DO NOT EDIT! 7 | 8 | var jspb = require('google-protobuf'); 9 | var goog = jspb; 10 | var global = Function('return this')(); 11 | 12 | var google_api_http_pb = require('../../google/api/http_pb.js'); 13 | var google_protobuf_descriptor_pb = require('google-protobuf/google/protobuf/descriptor_pb.js'); 14 | goog.exportSymbol('proto.google.api.http', null, global); 15 | 16 | /** 17 | * A tuple of {field number, class constructor} for the extension 18 | * field named `http`. 19 | * @type {!jspb.ExtensionFieldInfo.} 20 | */ 21 | proto.google.api.http = new jspb.ExtensionFieldInfo( 22 | 72295728, 23 | {http: 0}, 24 | google_api_http_pb.HttpRule, 25 | /** @type {?function((boolean|undefined),!jspb.Message=): !Object} */ ( 26 | google_api_http_pb.HttpRule.toObject), 27 | 0); 28 | 29 | google_protobuf_descriptor_pb.MethodOptions.extensionsBinary[72295728] = new jspb.ExtensionFieldBinaryInfo( 30 | proto.google.api.http, 31 | jspb.BinaryReader.prototype.readMessage, 32 | jspb.BinaryWriter.prototype.writeMessage, 33 | google_api_http_pb.HttpRule.serializeBinaryToWriter, 34 | google_api_http_pb.HttpRule.deserializeBinaryFromReader, 35 | false); 36 | // This registers the extension field with the extended class, so that 37 | // toObject() will function correctly. 38 | google_protobuf_descriptor_pb.MethodOptions.extensions[72295728] = proto.google.api.http; 39 | 40 | goog.object.extend(exports, proto.google.api); 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fabric Resource Generator 2 | 3 | 4 | 1) Write your definition of the object model and the services that are required from the Smart Contract. This is using the protobuf syntax, using the additional options/attributes that provide fine grained control 5 | 2) Decide on what language you want to use for the contract implementation. Choices are Java, Go, JavaScript, TypeScript, Rust 6 | 3) Decide on what langauges you want to use for the client implementations 7 | 4) Generate the resources for the contract and client implementations. Starting point is the proto definitions (a) 8 | 5) Fill out the code, and deploy 9 | 6) .... repeat 10 | 11 | (a) You can also start with the Contract Metadata JSON description. This is harder to read, but is more easily parsed and modified by tooling and the implementation libraries. It is akin to the 'intermediate representation' in a standard development tool chain. 12 | 13 | ## Resource generator 14 | 15 | The resource generator is a CLI that can be run either standalone or as a protoc plugin. 16 | 17 | 0) Ensure that you have protoc installed 18 | 1) `npm install -g fabric-resource-generator` (if you've clone this repo instead use `npm run build && npm link`) 19 | 2) Create a new directory to hold the protobufs. You need to have some of the google protobuf files to hand, and also the Fabric contract extensions. 20 | As an example copy the `examples` directory in this repo (TODO script this....) 21 | 3) Let's work with the `my-contract.proto` 22 | 23 | ``` 24 | protoc \ 25 | --plugin=protoc-fabric-gen \ 26 | -I ./proto \ 27 | ./proto/my-contract.proto \ 28 | --metadata_out=json=y,js=y,ts=y:./generated 29 | ``` 30 | This will generate the json metadata, js resources, and ts resources -------------------------------------------------------------------------------- /dist/cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | Object.defineProperty(exports, "__esModule", { value: true }); 4 | /* 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | const debug_1 = require("debug"); 8 | const yargs = require("yargs"); 9 | const resourcefactory_1 = require("./resourcefactory"); 10 | const LOG = debug_1.default('resourcefactory:cli'); 11 | const results = yargs 12 | .command(['create', '$0'], 'Create resources', { 13 | localfile: { 14 | alias: 'f', 15 | default: 'metadata.json', 16 | demandOption: true, 17 | describe: 'Name of the metadata file to load', 18 | requiresArg: true, 19 | }, 20 | outputdir: { 21 | alias: 'o', 22 | default: 'out', 23 | demandOption: true, 24 | describe: 'Directory files to be written to (will be created if does not exist)', 25 | requiresArg: true, 26 | }, 27 | template: { 28 | alias: 'n', 29 | default: 'singlepagesummary', 30 | demandOption: true, 31 | describe: 'The name of the template(s) to process. Space separated list', 32 | array: true 33 | }, 34 | }) 35 | .help() 36 | .wrap(null) 37 | .alias('v', 'version') 38 | .version('0.0.1') 39 | .describe('v', 'show version information') 40 | .strict() 41 | .argv; 42 | // setup the config here.. 43 | let config; 44 | let factory = []; 45 | results.template.forEach((templateName) => { 46 | config = { 47 | input: results.localfile, 48 | output: results.outputdir, 49 | task: templateName, 50 | }; 51 | factory.push(new resourcefactory_1.default(config).start()); 52 | }); 53 | LOG(`Using configuration ${JSON.stringify(config)}`); 54 | Promise.all(factory).then(() => { 55 | console.log('Done'); 56 | }).catch((err) => { 57 | LOG(err); 58 | process.exit(-1); 59 | }); 60 | //# sourceMappingURL=cli.js.map -------------------------------------------------------------------------------- /dist/protoc-plugin/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/protoc-plugin/index.ts"],"names":[],"mappings":";AAAA;;EAEE;;AAEF,6CAA8C;AAC9C,qDAAqD;AACrD,oEAAmG;AACnG,6CAA6C;AAC7C,OAAO,CAAC,6BAA6B,CAAC,CAAC;AACvC,OAAO,CAAC,sBAAsB,CAAC,CAAC;AAChC,OAAO,CAAC,sBAAsB,CAAC,CAAC;AAEhC,MAAqB,MAAM;IAEzB;;;;OAIG;IACI,KAAK,CAAC,oBAAoB,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK;QACrD,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,KAAK,CAAC,CAAC;QAC5C,OAAO,gCAAoB,CAAC,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9D,CAAC;IAED;;;OAGG;IACI,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM;QAEzD,IAAI,GAAG,GAA0B,IAAI,iCAAqB,EAAE,CAAC;QAE7D,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YACrB,MAAM,IAAI,GAAG,IAAI,iCAAqB,CAAC,IAAI,EAAE,CAAC;YAC9C,IAAI,CAAC,CAAC,IAAI,EAAE;gBACV,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;aACtB;YACD,IAAI,CAAC,CAAC,OAAO,EAAE;gBACb,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;aAC5B;YACD,IAAI,CAAC,CAAC,eAAe,EAAE;gBACrB,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC;aAC3C;YAED,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAEpB,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC;IACnD,CAAC;IAED;;;;OAIG;IACI,0BAA0B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM;QAC5D,MAAM,GAAG,GAAG,IAAI,iCAAqB,EAAE,CAAA;QACvC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC7B,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC,CAAC,CAAA;IAClD,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,EAAE;QAEjB,IAAI;YACF,IAAI,GAAG,GAAG,CAAC,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;YAEzD,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;YAClD,IAAI,MAAM,GAAG,GAAG,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAE1F,IAAI,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAC3B,OAAO,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;YAC9C,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;SACnC;QAAC,OAAO,GAAG,EAAE;YACZ,IAAI,CAAC,0BAA0B,CAAC,GAAG,CAAC,CAAC;SACtC;IACH,CAAC;CAEF;AAjED,yBAiEC"} -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed under the Apache License, Version 2.0 (the "License"); 3 | # you may not use this file except in compliance with the License. 4 | # You may obtain a copy of the License at 5 | # 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # 8 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | # 14 | 15 | # Logs 16 | logs 17 | *.log 18 | npm-debug.log* 19 | yarn-debug.log* 20 | yarn-error.log* 21 | 22 | # Runtime data 23 | pids 24 | *.pid 25 | *.seed 26 | *.pid.lock 27 | 28 | # Directory for instrumented libs generated by jscoverage/JSCover 29 | lib-cov 30 | 31 | # Coverage directory used by tools like istanbul 32 | coverage 33 | 34 | # nyc test coverage 35 | .nyc_output 36 | 37 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 38 | .grunt 39 | 40 | # Bower dependency directory (https://bower.io/) 41 | bower_components 42 | 43 | # node-waf configuration 44 | .lock-wscript 45 | 46 | # Compiled binary addons (https://nodejs.org/api/addons.html) 47 | build/Release 48 | 49 | # Dependency directories 50 | node_modules/ 51 | jspm_packages/ 52 | 53 | # TypeScript v1 declaration files 54 | typings/ 55 | 56 | # Optional npm cache directory 57 | .npm 58 | 59 | # Optional eslint cache 60 | .eslintcache 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | 74 | # parcel-bundler cache (https://parceljs.org/) 75 | .cache 76 | 77 | # next.js build output 78 | .next 79 | 80 | # nuxt.js build output 81 | .nuxt 82 | 83 | # vuepress build output 84 | .vuepress/dist 85 | 86 | # Serverless directories 87 | .serverless 88 | 89 | -------------------------------------------------------------------------------- /src/cli.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | 4 | /* 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | import debug from 'debug'; 8 | import * as yargs from 'yargs'; 9 | import Config from './config'; 10 | import ConversionFactory from './conversionfactory'; 11 | import Factory from './factory'; 12 | import ResourceFactory from './resourcefactory'; 13 | 14 | const LOG = debug('resourcefactory:cli'); 15 | 16 | const results = yargs 17 | .command(['create', '$0'], 'Create resources', { 18 | localfile: { 19 | alias: 'f', 20 | default: 'metadata.json', 21 | demandOption: true, 22 | describe: 'Name of the metadata file to load', 23 | requiresArg: true, 24 | }, 25 | outputdir: { 26 | alias: 'o', 27 | default: 'out', 28 | demandOption: true, 29 | describe: 'Directory files to be written to (will be created if does not exist)', 30 | requiresArg: true, 31 | }, 32 | template: { 33 | alias: 'n', 34 | default: 'singlepagesummary', 35 | demandOption: true, 36 | describe: 'The name of the template(s) to process. Space separated list', 37 | array: true 38 | }, 39 | 40 | }) 41 | .help() 42 | .wrap(null) 43 | .alias('v', 'version') 44 | .version('0.0.1') 45 | .describe('v', 'show version information') 46 | .strict() 47 | .argv; 48 | 49 | // setup the config here.. 50 | let config: Config; 51 | let factory: Promise[] = []; 52 | 53 | results.template.forEach((templateName) => { 54 | config = { 55 | input: results.localfile, 56 | output: results.outputdir, 57 | task: templateName, 58 | }; 59 | factory.push(new ResourceFactory(config).start()); 60 | }) 61 | 62 | 63 | 64 | LOG(`Using configuration ${JSON.stringify(config)}`); 65 | 66 | Promise.all(factory).then(() => { 67 | console.log('Done'); 68 | }).catch((err) => { 69 | LOG(err); 70 | process.exit(-1); 71 | }); 72 | -------------------------------------------------------------------------------- /dist/conversionfactory.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | /* 4 | * 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | const debug_1 = require("debug"); 8 | const fs = require("fs"); 9 | const mkdirp = require("mkdirp"); 10 | const path = require("path"); 11 | const prettier = require("prettier"); 12 | const composer_concerto_1 = require("composer-concerto"); 13 | const visitor_1 = require("./visitor"); 14 | const LOG = debug_1.default('resourcefactory:factory'); 15 | /** 16 | * Resource Factory 17 | * 18 | * Create an instance with an IConfig object 19 | * Then call start() to produce the documentation 20 | */ 21 | class ConversionFactory { 22 | constructor(config) { 23 | this.resolvedFilename = path.resolve(config.input); 24 | LOG(`Using input file ${this.resolvedFilename}`); 25 | this.data = fs.readFileSync(this.resolvedFilename, 'utf8'); 26 | this.output = path.resolve(config.output); 27 | LOG(`Using the output directory of ${this.output}`); 28 | mkdirp.sync(this.output); 29 | } 30 | /** Starts the factory generating output based on the template configuration 31 | * 32 | */ 33 | async start() { 34 | const modelManager = new composer_concerto_1.ModelManager(); 35 | const ctoFiles = [this.resolvedFilename]; 36 | const modelFiles = ctoFiles.map((ctoFile) => { 37 | return fs.readFileSync(ctoFile, 'utf8'); 38 | }); 39 | modelManager.addModelFiles(modelFiles, ctoFiles, true); 40 | await modelManager.updateExternalModels(); 41 | const visitor = new visitor_1.default(); 42 | const parameters = {}; 43 | // parameters.fileWriter = new FileWriter(outputDirectory); 44 | const data = modelManager.accept(visitor, parameters); 45 | const jsonOutput = prettier.format(JSON.stringify(data), { parser: 'json' }); 46 | fs.writeFileSync(path.join(this.output, 'metadata.json'), jsonOutput); 47 | } 48 | } 49 | exports.default = ConversionFactory; 50 | //# sourceMappingURL=conversionfactory.js.map -------------------------------------------------------------------------------- /templates/contract_java/class.njk: -------------------------------------------------------------------------------- 1 | {% macro schema(s) %} 2 | {% if s.type %} 3 | {{s.type }} 4 | {% else %} 5 | {{s.$ref | objectname }} 6 | {% endif %} 7 | {% endmacro %} 8 | 9 | {% macro parameters(params) %} 10 | {% for p in params -%} {{p.name}}:{{- schema(p.schema) -}} 11 | {%- if not loop.last -%}, {% endif -%} 12 | {%- endfor %} 13 | {% endmacro %} 14 | 15 | {% macro arglist(params) %} 16 | {% if params %} 17 | {% for p in params -%} JSON.stringify({{p.name}}) 18 | {%- if not loop.last -%}, {% endif -%} 19 | {%- endfor %} 20 | {%- endif %} 21 | {% endmacro %} 22 | 23 | import { Contract, Info, Returns, Transaction } from 'fabric-contract-api'; 24 | import { {% for name,comp in components.schemas %}{{ name }} {%- if not loop.last -%}, {% endif -%} {% endfor %} } from 'domain-adts'; 25 | 26 | /* 27 | * Licensed to the Apache Software Foundation (ASF) under one or more 28 | * contributor license agreements. See the NOTICE file distributed with 29 | * this work for additional information regarding copyright ownership. 30 | * The ASF licenses this file to You under the Apache License, Version 2.0 31 | * (the "License"); you may not use this file except in compliance with 32 | * the License. You may obtain a copy of the License at 33 | * 34 | * http://www.apache.org/licenses/LICENSE-2.0 35 | * 36 | * Unless required by applicable law or agreed to in writing, software 37 | * distributed under the License is distributed on an "AS IS" BASIS, 38 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 39 | * See the License for the specific language governing permissions and 40 | * limitations under the License. 41 | */ 42 | 43 | @Info({ title: '', description: ''}) 44 | export default class {{ contract.name | replace(".","_") }} extends Contract { 45 | 46 | public constructor() { 47 | super(); 48 | } 49 | 50 | {% for tx in contract.transactions %} 51 | @Transaction() 52 | @Returns({{ schema(tx.return[0].schema) | trim }}) 53 | public async {{tx.name}}(ctx: Context, {{- parameters(tx.parameters) | trim -}}): Promise<{{ schema(tx.return[0].schema) | trim }}>{ 54 | // Please could you enter something here... 55 | return; 56 | } 57 | {% endfor %} 58 | 59 | } 60 | 61 | -------------------------------------------------------------------------------- /templates/contract_ts/class.njk: -------------------------------------------------------------------------------- 1 | {% macro schema(s) %} 2 | {% if s.type %} 3 | {{s.type }} 4 | {% else %} 5 | {{s.$ref | objectname }} 6 | {% endif %} 7 | {% endmacro %} 8 | 9 | {% macro parameters(params) %} 10 | {% for p in params -%} {{p.name}}:{{- schema(p.schema) -}} 11 | {%- if not loop.last -%}, {% endif -%} 12 | {%- endfor %} 13 | {% endmacro %} 14 | 15 | {% macro arglist(params) %} 16 | {% if params %} 17 | {% for p in params -%} JSON.stringify({{p.name}}) 18 | {%- if not loop.last -%}, {% endif -%} 19 | {%- endfor %} 20 | {%- endif %} 21 | {% endmacro %} 22 | 23 | import { Contract, Info, Returns, Transaction } from 'fabric-contract-api'; 24 | import { {% for name,comp in components.schemas %}{{ name }} {%- if not loop.last -%}, {% endif -%} {% endfor %} } from 'domain-adts'; 25 | 26 | /* 27 | * Licensed to the Apache Software Foundation (ASF) under one or more 28 | * contributor license agreements. See the NOTICE file distributed with 29 | * this work for additional information regarding copyright ownership. 30 | * The ASF licenses this file to You under the Apache License, Version 2.0 31 | * (the "License"); you may not use this file except in compliance with 32 | * the License. You may obtain a copy of the License at 33 | * 34 | * http://www.apache.org/licenses/LICENSE-2.0 35 | * 36 | * Unless required by applicable law or agreed to in writing, software 37 | * distributed under the License is distributed on an "AS IS" BASIS, 38 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 39 | * See the License for the specific language governing permissions and 40 | * limitations under the License. 41 | */ 42 | 43 | @Info({ title: '', description: ''}) 44 | export default class {{ contract.name | replace(".","_") }} extends Contract { 45 | 46 | public constructor() { 47 | super(); 48 | } 49 | 50 | {% for tx in contract.transactions %} 51 | @Transaction() 52 | @Returns({{ schema(tx.return[0].schema) | trim }}) 53 | public async {{tx.name}}(ctx: Context, {{- parameters(tx.parameters) | trim -}}): Promise<{{ schema(tx.return[0].schema) | trim }}>{ 54 | // Please could you enter something here... 55 | return; 56 | } 57 | {% endfor %} 58 | 59 | } 60 | 61 | -------------------------------------------------------------------------------- /dist/templates/contract_java/class.njk: -------------------------------------------------------------------------------- 1 | {% macro schema(s) %} 2 | {% if s.type %} 3 | {{s.type }} 4 | {% else %} 5 | {{s.$ref | objectname }} 6 | {% endif %} 7 | {% endmacro %} 8 | 9 | {% macro parameters(params) %} 10 | {% for p in params -%} {{p.name}}:{{- schema(p.schema) -}} 11 | {%- if not loop.last -%}, {% endif -%} 12 | {%- endfor %} 13 | {% endmacro %} 14 | 15 | {% macro arglist(params) %} 16 | {% if params %} 17 | {% for p in params -%} JSON.stringify({{p.name}}) 18 | {%- if not loop.last -%}, {% endif -%} 19 | {%- endfor %} 20 | {%- endif %} 21 | {% endmacro %} 22 | 23 | import { Contract, Info, Returns, Transaction } from 'fabric-contract-api'; 24 | import { {% for name,comp in components.schemas %}{{ name }} {%- if not loop.last -%}, {% endif -%} {% endfor %} } from 'domain-adts'; 25 | 26 | /* 27 | * Licensed to the Apache Software Foundation (ASF) under one or more 28 | * contributor license agreements. See the NOTICE file distributed with 29 | * this work for additional information regarding copyright ownership. 30 | * The ASF licenses this file to You under the Apache License, Version 2.0 31 | * (the "License"); you may not use this file except in compliance with 32 | * the License. You may obtain a copy of the License at 33 | * 34 | * http://www.apache.org/licenses/LICENSE-2.0 35 | * 36 | * Unless required by applicable law or agreed to in writing, software 37 | * distributed under the License is distributed on an "AS IS" BASIS, 38 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 39 | * See the License for the specific language governing permissions and 40 | * limitations under the License. 41 | */ 42 | 43 | @Info({ title: '', description: ''}) 44 | export default class {{ contract.name | replace(".","_") }} extends Contract { 45 | 46 | public constructor() { 47 | super(); 48 | } 49 | 50 | {% for tx in contract.transactions %} 51 | @Transaction() 52 | @Returns({{ schema(tx.return[0].schema) | trim }}) 53 | public async {{tx.name}}(ctx: Context, {{- parameters(tx.parameters) | trim -}}): Promise<{{ schema(tx.return[0].schema) | trim }}>{ 54 | // Please could you enter something here... 55 | return; 56 | } 57 | {% endfor %} 58 | 59 | } 60 | 61 | -------------------------------------------------------------------------------- /dist/templates/contract_ts/class.njk: -------------------------------------------------------------------------------- 1 | {% macro schema(s) %} 2 | {% if s.type %} 3 | {{s.type }} 4 | {% else %} 5 | {{s.$ref | objectname }} 6 | {% endif %} 7 | {% endmacro %} 8 | 9 | {% macro parameters(params) %} 10 | {% for p in params -%} {{p.name}}:{{- schema(p.schema) -}} 11 | {%- if not loop.last -%}, {% endif -%} 12 | {%- endfor %} 13 | {% endmacro %} 14 | 15 | {% macro arglist(params) %} 16 | {% if params %} 17 | {% for p in params -%} JSON.stringify({{p.name}}) 18 | {%- if not loop.last -%}, {% endif -%} 19 | {%- endfor %} 20 | {%- endif %} 21 | {% endmacro %} 22 | 23 | import { Contract, Info, Returns, Transaction } from 'fabric-contract-api'; 24 | import { {% for name,comp in components.schemas %}{{ name }} {%- if not loop.last -%}, {% endif -%} {% endfor %} } from 'domain-adts'; 25 | 26 | /* 27 | * Licensed to the Apache Software Foundation (ASF) under one or more 28 | * contributor license agreements. See the NOTICE file distributed with 29 | * this work for additional information regarding copyright ownership. 30 | * The ASF licenses this file to You under the Apache License, Version 2.0 31 | * (the "License"); you may not use this file except in compliance with 32 | * the License. You may obtain a copy of the License at 33 | * 34 | * http://www.apache.org/licenses/LICENSE-2.0 35 | * 36 | * Unless required by applicable law or agreed to in writing, software 37 | * distributed under the License is distributed on an "AS IS" BASIS, 38 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 39 | * See the License for the specific language governing permissions and 40 | * limitations under the License. 41 | */ 42 | 43 | @Info({ title: '', description: ''}) 44 | export default class {{ contract.name | replace(".","_") }} extends Contract { 45 | 46 | public constructor() { 47 | super(); 48 | } 49 | 50 | {% for tx in contract.transactions %} 51 | @Transaction() 52 | @Returns({{ schema(tx.return[0].schema) | trim }}) 53 | public async {{tx.name}}(ctx: Context, {{- parameters(tx.parameters) | trim -}}): Promise<{{ schema(tx.return[0].schema) | trim }}>{ 54 | // Please could you enter something here... 55 | return; 56 | } 57 | {% endfor %} 58 | 59 | } 60 | 61 | -------------------------------------------------------------------------------- /src/conversionfactory.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | import debug from 'debug'; 7 | import fs = require('fs'); 8 | import yaml = require('js-yaml'); 9 | import jsonata = require('jsonata'); 10 | import * as mkdirp from 'mkdirp'; 11 | import nunjucks = require('nunjucks'); 12 | import path = require('path'); 13 | import prettier = require('prettier'); 14 | import Config from './config'; 15 | 16 | import { FileWriter, ModelManager } from 'composer-concerto'; 17 | import MetadataVisitor from './visitor'; 18 | 19 | const LOG = debug('resourcefactory:factory'); 20 | 21 | /** 22 | * Resource Factory 23 | * 24 | * Create an instance with an IConfig object 25 | * Then call start() to produce the documentation 26 | */ 27 | export default class ConversionFactory { 28 | 29 | private resolvedFilename: string; 30 | private data: string; 31 | private output: string; 32 | 33 | public constructor(config: Config) { 34 | 35 | this.resolvedFilename = path.resolve(config.input); 36 | LOG(`Using input file ${this.resolvedFilename}`); 37 | 38 | this.data = fs.readFileSync(this.resolvedFilename, 'utf8'); 39 | this.output = path.resolve(config.output); 40 | LOG(`Using the output directory of ${this.output}`); 41 | mkdirp.sync(this.output); 42 | 43 | } 44 | 45 | /** Starts the factory generating output based on the template configuration 46 | * 47 | */ 48 | public async start(): Promise { 49 | const modelManager = new ModelManager(); 50 | const ctoFiles = [this.resolvedFilename]; 51 | const modelFiles = ctoFiles.map((ctoFile) => { 52 | return fs.readFileSync(ctoFile, 'utf8'); 53 | }); 54 | modelManager.addModelFiles(modelFiles, ctoFiles, true); 55 | await modelManager.updateExternalModels(); 56 | 57 | const visitor = new MetadataVisitor(); 58 | 59 | const parameters = {}; 60 | // parameters.fileWriter = new FileWriter(outputDirectory); 61 | const data = modelManager.accept(visitor, parameters); 62 | const jsonOutput = prettier.format(JSON.stringify(data), { parser: 'json' }); 63 | fs.writeFileSync(path.join(this.output, 'metadata.json'), jsonOutput); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /templates/domain_adts_java/class.njk: -------------------------------------------------------------------------------- 1 | {% macro schema(s) %} 2 | {% if s.type %} 3 | {{s.type }} 4 | {% else %} 5 | {{s.$ref | objectname }} 6 | {% endif %} 7 | {% endmacro %} 8 | 9 | {% macro parameters(params) %} 10 | {% for p in params -%} {{p.name}}:{{- schema(p.schema) -}} 11 | {%- if not loop.last -%}, {% endif -%} 12 | {%- endfor %} 13 | {% endmacro %} 14 | 15 | {% macro arglist(params) %} 16 | {% if params %} 17 | {% for p in params -%} JSON.stringify({{p.name}}) 18 | {%- if not loop.last -%}, {% endif -%} 19 | {%- endfor %} 20 | {%- endif %} 21 | {% endmacro %} 22 | 23 | import { Object as DataType, Property } from 'fabric-contract-api'; 24 | import { State } from 'fabric-data'; 25 | 26 | /* 27 | * Licensed to the Apache Software Foundation (ASF) under one or more 28 | * contributor license agreements. See the NOTICE file distributed with 29 | * this work for additional information regarding copyright ownership. 30 | * The ASF licenses this file to You under the Apache License, Version 2.0 31 | * (the "License"); you may not use this file except in compliance with 32 | * the License. You may obtain a copy of the License at 33 | * 34 | * http://www.apache.org/licenses/LICENSE-2.0 35 | * 36 | * Unless required by applicable law or agreed to in writing, software 37 | * distributed under the License is distributed on an "AS IS" BASIS, 38 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 39 | * See the License for the specific language governing permissions and 40 | * limitations under the License. 41 | */ 42 | @DataType 43 | export default class {{ title | replace(".","_") }} extends State { 44 | 45 | // no-arg constructor required 46 | public constructor() { 47 | } 48 | 49 | {% for name,details in properties %} 50 | @Property 51 | private {{ name }}: {{ details.type }}; 52 | 53 | /** 54 | * Getter ${{name}} 55 | * @return { {{ details.type }} } 56 | */ 57 | public get ${{name}}(): {{ details.type }} { 58 | return this.{{name}}; 59 | } 60 | 61 | /** 62 | * Setter ${{name}} 63 | * @param { {{ details.type }} } value 64 | */ 65 | public set ${{name}}(value: {{ details.type }}) { 66 | this.{{name}} = value; 67 | } 68 | {% endfor %} 69 | 70 | } 71 | 72 | -------------------------------------------------------------------------------- /dist/templates/domain_adts_java/class.njk: -------------------------------------------------------------------------------- 1 | {% macro schema(s) %} 2 | {% if s.type %} 3 | {{s.type }} 4 | {% else %} 5 | {{s.$ref | objectname }} 6 | {% endif %} 7 | {% endmacro %} 8 | 9 | {% macro parameters(params) %} 10 | {% for p in params -%} {{p.name}}:{{- schema(p.schema) -}} 11 | {%- if not loop.last -%}, {% endif -%} 12 | {%- endfor %} 13 | {% endmacro %} 14 | 15 | {% macro arglist(params) %} 16 | {% if params %} 17 | {% for p in params -%} JSON.stringify({{p.name}}) 18 | {%- if not loop.last -%}, {% endif -%} 19 | {%- endfor %} 20 | {%- endif %} 21 | {% endmacro %} 22 | 23 | import { Object as DataType, Property } from 'fabric-contract-api'; 24 | import { State } from 'fabric-data'; 25 | 26 | /* 27 | * Licensed to the Apache Software Foundation (ASF) under one or more 28 | * contributor license agreements. See the NOTICE file distributed with 29 | * this work for additional information regarding copyright ownership. 30 | * The ASF licenses this file to You under the Apache License, Version 2.0 31 | * (the "License"); you may not use this file except in compliance with 32 | * the License. You may obtain a copy of the License at 33 | * 34 | * http://www.apache.org/licenses/LICENSE-2.0 35 | * 36 | * Unless required by applicable law or agreed to in writing, software 37 | * distributed under the License is distributed on an "AS IS" BASIS, 38 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 39 | * See the License for the specific language governing permissions and 40 | * limitations under the License. 41 | */ 42 | @DataType 43 | export default class {{ title | replace(".","_") }} extends State { 44 | 45 | // no-arg constructor required 46 | public constructor() { 47 | } 48 | 49 | {% for name,details in properties %} 50 | @Property 51 | private {{ name }}: {{ details.type }}; 52 | 53 | /** 54 | * Getter ${{name}} 55 | * @return { {{ details.type }} } 56 | */ 57 | public get ${{name}}(): {{ details.type }} { 58 | return this.{{name}}; 59 | } 60 | 61 | /** 62 | * Setter ${{name}} 63 | * @param { {{ details.type }} } value 64 | */ 65 | public set ${{name}}(value: {{ details.type }}) { 66 | this.{{name}} = value; 67 | } 68 | {% endfor %} 69 | 70 | } 71 | 72 | -------------------------------------------------------------------------------- /templates/contract_rust/rustclass.njk: -------------------------------------------------------------------------------- 1 | {% macro schema(s) %} 2 | {% if s.type %} 3 | {{s.type }} 4 | {% else %} 5 | {{s.$ref | objectname }} 6 | {% endif %} 7 | {% endmacro %} 8 | 9 | {% macro parameters(params) %} 10 | {% for p in params -%} {{p.name}}:{{- schema(p.schema) -}} 11 | {%- if not loop.last -%}, {% endif -%} 12 | {%- endfor %} 13 | {% endmacro %} 14 | 15 | {% macro arglist(params) %} 16 | {% if params %} 17 | {% for p in params -%} JSON.stringify({{p.name}}) 18 | {%- if not loop.last -%}, {% endif -%} 19 | {%- endfor %} 20 | {%- endif %} 21 | {% endmacro %} 22 | 23 | /* 24 | * SPDX-License-Identifier: Apache-2.0 25 | */ 26 | 27 | //! Basic CRUD style asset contract 28 | //! 29 | //! 30 | 31 | use fabric_contract::contractapi::contract::*; 32 | use fabric_contract::contractapi::context::*; 33 | use fabric_contract::contractapi::contract::Routing; 34 | 35 | // macros for marking up the contract 36 | use contract_macros::contract_impl; 37 | 38 | pub struct {{ contract.name | replace(".","_") }} { 39 | 40 | 41 | } 42 | 43 | // Implementation of the contract trait for the {{ contract.name }} 44 | /// There are default implementation methods, but can be modified if you wish 45 | /// 46 | /// Recommended that the name() function is always modified 47 | impl Contract for {{ contract.name | replace(".","_") }} { 48 | 49 | //! Name of the contract 50 | fn name(&self) -> String { 51 | format!("{{ contract.name }}") 52 | } 53 | 54 | /// Implementing a customer before transaction 55 | fn before_transaction(&self,ctx: Context) { 56 | ctx.log(String::from("Custom Before_Transaction")); 57 | } 58 | 59 | } 60 | 61 | 62 | #[contract_impl] 63 | impl {{ contract.name | replace(".","_") }} { 64 | 65 | pub fn new() -> {{ contract.name | replace(".","_") }} { 66 | {{ contract.name | replace(".","_") }} { 67 | } 68 | } 69 | {% for tx in contract.transactions %} 70 | @Transaction() 71 | @Returns({{ schema(tx.return[0].schema) | trim }}) 72 | pub fn {{tx.name}}(&self, mut ctx: Context, {{- parameters(tx.parameters) | trim -}}) -> Result<{{ schema(tx.return[0].schema) | trim }},String>{ 73 | // Please could you enter something here... 74 | Ok(0) 75 | } 76 | {% endfor %} 77 | } 78 | 79 | 80 | -------------------------------------------------------------------------------- /templates/client_java/class.njk: -------------------------------------------------------------------------------- 1 | {% macro schema(s) %} 2 | {% if s.type %} 3 | {{s.type }} 4 | {% else %} 5 | {{s.$ref | objectname }} 6 | {% endif %} 7 | {% endmacro %} 8 | 9 | {% macro parameters(params) %} 10 | {% for p in params -%} {{p.name}}:{{- schema(p.schema) -}} 11 | {%- if not loop.last -%}, {% endif -%} 12 | {%- endfor %} 13 | {% endmacro %} 14 | 15 | {% macro arglist(params) %} 16 | {% if params %} 17 | {% for p in params -%} JSON.stringify({{p.name}}) 18 | {%- if not loop.last -%}, {% endif -%} 19 | {%- endfor %} 20 | {%- endif %} 21 | {% endmacro %} 22 | 23 | import { Contract, Network } from 'fabric-network'; 24 | 25 | /* 26 | * Licensed to the Apache Software Foundation (ASF) under one or more 27 | * contributor license agreements. See the NOTICE file distributed with 28 | * this work for additional information regarding copyright ownership. 29 | * The ASF licenses this file to You under the Apache License, Version 2.0 30 | * (the "License"); you may not use this file except in compliance with 31 | * the License. You may obtain a copy of the License at 32 | * 33 | * http://www.apache.org/licenses/LICENSE-2.0 34 | * 35 | * Unless required by applicable law or agreed to in writing, software 36 | * distributed under the License is distributed on an "AS IS" BASIS, 37 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 38 | * See the License for the specific language governing permissions and 39 | * limitations under the License. 40 | */ 41 | 42 | export default class {{ name | replace(".","_") | lower }} { 43 | 44 | private contractName = '{{ name | lower }}'; 45 | 46 | private network: Network; 47 | private contract: Contract; 48 | 49 | public constructor(network) { 50 | this.network = network; 51 | } 52 | 53 | public async init(chaincodeId: string) { 54 | this.contract = await this.network.getContract(chaincodeId, this.contractName); 55 | } 56 | 57 | {% for tx in transactions %} 58 | public async {{tx.name}}({{- parameters(tx.parameters) | trim -}}): Promise<{{ schema(tx.return[0].schema) | trim }}>{ 59 | const _tx = await this.contract.createTransaction('{{tx.name}}'); 60 | const result = await _tx.submit({{- arglist(tx.parameters) -}}); 61 | return JSON.parse(result.toString()); 62 | } 63 | {% endfor %} 64 | 65 | } 66 | 67 | -------------------------------------------------------------------------------- /templates/client_ts/class.njk: -------------------------------------------------------------------------------- 1 | {% macro schema(s) %} 2 | {% if s.type %} 3 | {{s.type }} 4 | {% else %} 5 | {{s.$ref | objectname }} 6 | {% endif %} 7 | {% endmacro %} 8 | 9 | {% macro parameters(params) %} 10 | {% for p in params -%} {{p.name}}:{{- schema(p.schema) -}} 11 | {%- if not loop.last -%}, {% endif -%} 12 | {%- endfor %} 13 | {% endmacro %} 14 | 15 | {% macro arglist(params) %} 16 | {% if params %} 17 | {% for p in params -%} JSON.stringify({{p.name}}) 18 | {%- if not loop.last -%}, {% endif -%} 19 | {%- endfor %} 20 | {%- endif %} 21 | {% endmacro %} 22 | 23 | import { Contract, Network } from 'fabric-network'; 24 | 25 | /* 26 | * Licensed to the Apache Software Foundation (ASF) under one or more 27 | * contributor license agreements. See the NOTICE file distributed with 28 | * this work for additional information regarding copyright ownership. 29 | * The ASF licenses this file to You under the Apache License, Version 2.0 30 | * (the "License"); you may not use this file except in compliance with 31 | * the License. You may obtain a copy of the License at 32 | * 33 | * http://www.apache.org/licenses/LICENSE-2.0 34 | * 35 | * Unless required by applicable law or agreed to in writing, software 36 | * distributed under the License is distributed on an "AS IS" BASIS, 37 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 38 | * See the License for the specific language governing permissions and 39 | * limitations under the License. 40 | */ 41 | 42 | export default class {{ name | replace(".","_") | lower }} { 43 | 44 | private contractName = '{{ name | lower }}'; 45 | 46 | private network: Network; 47 | private contract: Contract; 48 | 49 | public constructor(network) { 50 | this.network = network; 51 | } 52 | 53 | public async init(chaincodeId: string) { 54 | this.contract = await this.network.getContract(chaincodeId, this.contractName); 55 | } 56 | 57 | {% for tx in transactions %} 58 | public async {{tx.name}}({{- parameters(tx.parameters) | trim -}}): Promise<{{ schema(tx.return[0].schema) | trim }}>{ 59 | const _tx = await this.contract.createTransaction('{{tx.name}}'); 60 | const result = await _tx.submit({{- arglist(tx.parameters) -}}); 61 | return JSON.parse(result.toString()); 62 | } 63 | {% endfor %} 64 | 65 | } 66 | 67 | -------------------------------------------------------------------------------- /dist/templates/client_java/class.njk: -------------------------------------------------------------------------------- 1 | {% macro schema(s) %} 2 | {% if s.type %} 3 | {{s.type }} 4 | {% else %} 5 | {{s.$ref | objectname }} 6 | {% endif %} 7 | {% endmacro %} 8 | 9 | {% macro parameters(params) %} 10 | {% for p in params -%} {{p.name}}:{{- schema(p.schema) -}} 11 | {%- if not loop.last -%}, {% endif -%} 12 | {%- endfor %} 13 | {% endmacro %} 14 | 15 | {% macro arglist(params) %} 16 | {% if params %} 17 | {% for p in params -%} JSON.stringify({{p.name}}) 18 | {%- if not loop.last -%}, {% endif -%} 19 | {%- endfor %} 20 | {%- endif %} 21 | {% endmacro %} 22 | 23 | import { Contract, Network } from 'fabric-network'; 24 | 25 | /* 26 | * Licensed to the Apache Software Foundation (ASF) under one or more 27 | * contributor license agreements. See the NOTICE file distributed with 28 | * this work for additional information regarding copyright ownership. 29 | * The ASF licenses this file to You under the Apache License, Version 2.0 30 | * (the "License"); you may not use this file except in compliance with 31 | * the License. You may obtain a copy of the License at 32 | * 33 | * http://www.apache.org/licenses/LICENSE-2.0 34 | * 35 | * Unless required by applicable law or agreed to in writing, software 36 | * distributed under the License is distributed on an "AS IS" BASIS, 37 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 38 | * See the License for the specific language governing permissions and 39 | * limitations under the License. 40 | */ 41 | 42 | export default class {{ name | replace(".","_") | lower }} { 43 | 44 | private contractName = '{{ name | lower }}'; 45 | 46 | private network: Network; 47 | private contract: Contract; 48 | 49 | public constructor(network) { 50 | this.network = network; 51 | } 52 | 53 | public async init(chaincodeId: string) { 54 | this.contract = await this.network.getContract(chaincodeId, this.contractName); 55 | } 56 | 57 | {% for tx in transactions %} 58 | public async {{tx.name}}({{- parameters(tx.parameters) | trim -}}): Promise<{{ schema(tx.return[0].schema) | trim }}>{ 59 | const _tx = await this.contract.createTransaction('{{tx.name}}'); 60 | const result = await _tx.submit({{- arglist(tx.parameters) -}}); 61 | return JSON.parse(result.toString()); 62 | } 63 | {% endfor %} 64 | 65 | } 66 | 67 | -------------------------------------------------------------------------------- /dist/templates/client_ts/class.njk: -------------------------------------------------------------------------------- 1 | {% macro schema(s) %} 2 | {% if s.type %} 3 | {{s.type }} 4 | {% else %} 5 | {{s.$ref | objectname }} 6 | {% endif %} 7 | {% endmacro %} 8 | 9 | {% macro parameters(params) %} 10 | {% for p in params -%} {{p.name}}:{{- schema(p.schema) -}} 11 | {%- if not loop.last -%}, {% endif -%} 12 | {%- endfor %} 13 | {% endmacro %} 14 | 15 | {% macro arglist(params) %} 16 | {% if params %} 17 | {% for p in params -%} JSON.stringify({{p.name}}) 18 | {%- if not loop.last -%}, {% endif -%} 19 | {%- endfor %} 20 | {%- endif %} 21 | {% endmacro %} 22 | 23 | import { Contract, Network } from 'fabric-network'; 24 | 25 | /* 26 | * Licensed to the Apache Software Foundation (ASF) under one or more 27 | * contributor license agreements. See the NOTICE file distributed with 28 | * this work for additional information regarding copyright ownership. 29 | * The ASF licenses this file to You under the Apache License, Version 2.0 30 | * (the "License"); you may not use this file except in compliance with 31 | * the License. You may obtain a copy of the License at 32 | * 33 | * http://www.apache.org/licenses/LICENSE-2.0 34 | * 35 | * Unless required by applicable law or agreed to in writing, software 36 | * distributed under the License is distributed on an "AS IS" BASIS, 37 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 38 | * See the License for the specific language governing permissions and 39 | * limitations under the License. 40 | */ 41 | 42 | export default class {{ name | replace(".","_") | lower }} { 43 | 44 | private contractName = '{{ name | lower }}'; 45 | 46 | private network: Network; 47 | private contract: Contract; 48 | 49 | public constructor(network) { 50 | this.network = network; 51 | } 52 | 53 | public async init(chaincodeId: string) { 54 | this.contract = await this.network.getContract(chaincodeId, this.contractName); 55 | } 56 | 57 | {% for tx in transactions %} 58 | public async {{tx.name}}({{- parameters(tx.parameters) | trim -}}): Promise<{{ schema(tx.return[0].schema) | trim }}>{ 59 | const _tx = await this.contract.createTransaction('{{tx.name}}'); 60 | const result = await _tx.submit({{- arglist(tx.parameters) -}}); 61 | return JSON.parse(result.toString()); 62 | } 63 | {% endfor %} 64 | 65 | } 66 | 67 | -------------------------------------------------------------------------------- /templates/domain_adts_ts/class.njk: -------------------------------------------------------------------------------- 1 | {% macro schema(s) %} 2 | {% if s.type %} 3 | {{s.type }} 4 | {% else %} 5 | {{s.$ref | objectname }} 6 | {% endif %} 7 | {% endmacro %} 8 | 9 | {% macro parameters(params) %} 10 | {% for p in params -%} {{p.name}}:{{- schema(p.schema) -}} 11 | {%- if not loop.last -%}, {% endif -%} 12 | {%- endfor %} 13 | {% endmacro %} 14 | 15 | {% macro arglist(params) %} 16 | {% if params %} 17 | {% for p in params -%} JSON.stringify({{p.name}}) 18 | {%- if not loop.last -%}, {% endif -%} 19 | {%- endfor %} 20 | {%- endif %} 21 | {% endmacro %} 22 | 23 | import { Object as DataType, Property } from 'fabric-contract-api'; 24 | import { State } from 'fabric-data'; 25 | 26 | /* 27 | * Licensed to the Apache Software Foundation (ASF) under one or more 28 | * contributor license agreements. See the NOTICE file distributed with 29 | * this work for additional information regarding copyright ownership. 30 | * The ASF licenses this file to You under the Apache License, Version 2.0 31 | * (the "License"); you may not use this file except in compliance with 32 | * the License. You may obtain a copy of the License at 33 | * 34 | * http://www.apache.org/licenses/LICENSE-2.0 35 | * 36 | * Unless required by applicable law or agreed to in writing, software 37 | * distributed under the License is distributed on an "AS IS" BASIS, 38 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 39 | * See the License for the specific language governing permissions and 40 | * limitations under the License. 41 | */ 42 | @DataType 43 | export default class {{ title | replace(".","_") }} extends State { 44 | 45 | // no-arg constructor required 46 | public constructor() { 47 | } 48 | 49 | {% for name,details in properties %} 50 | @Property 51 | private {{ name }}: {{ details.type | default(details.type , 'undefined') }}; 52 | 53 | /** 54 | * Getter ${{name}} 55 | * @return { {{ details.type }} } 56 | */ 57 | public get ${{name}}(): {{ details.type |default(details.type , 'undefined') }} { 58 | return this.{{name}}; 59 | } 60 | 61 | /** 62 | * Setter ${{name}} 63 | * @param { {{ details.type }} } value 64 | */ 65 | public set ${{name}}(value: {{ details.type |default(details.type , 'undefined') }}) { 66 | this.{{name}} = value; 67 | } 68 | {% endfor %} 69 | 70 | } 71 | 72 | -------------------------------------------------------------------------------- /dist/templates/domain_adts_ts/class.njk: -------------------------------------------------------------------------------- 1 | {% macro schema(s) %} 2 | {% if s.type %} 3 | {{s.type }} 4 | {% else %} 5 | {{s.$ref | objectname }} 6 | {% endif %} 7 | {% endmacro %} 8 | 9 | {% macro parameters(params) %} 10 | {% for p in params -%} {{p.name}}:{{- schema(p.schema) -}} 11 | {%- if not loop.last -%}, {% endif -%} 12 | {%- endfor %} 13 | {% endmacro %} 14 | 15 | {% macro arglist(params) %} 16 | {% if params %} 17 | {% for p in params -%} JSON.stringify({{p.name}}) 18 | {%- if not loop.last -%}, {% endif -%} 19 | {%- endfor %} 20 | {%- endif %} 21 | {% endmacro %} 22 | 23 | import { Object as DataType, Property } from 'fabric-contract-api'; 24 | import { State } from 'fabric-data'; 25 | 26 | /* 27 | * Licensed to the Apache Software Foundation (ASF) under one or more 28 | * contributor license agreements. See the NOTICE file distributed with 29 | * this work for additional information regarding copyright ownership. 30 | * The ASF licenses this file to You under the Apache License, Version 2.0 31 | * (the "License"); you may not use this file except in compliance with 32 | * the License. You may obtain a copy of the License at 33 | * 34 | * http://www.apache.org/licenses/LICENSE-2.0 35 | * 36 | * Unless required by applicable law or agreed to in writing, software 37 | * distributed under the License is distributed on an "AS IS" BASIS, 38 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 39 | * See the License for the specific language governing permissions and 40 | * limitations under the License. 41 | */ 42 | @DataType 43 | export default class {{ title | replace(".","_") }} extends State { 44 | 45 | // no-arg constructor required 46 | public constructor() { 47 | } 48 | 49 | {% for name,details in properties %} 50 | @Property 51 | private {{ name }}: {{ details.type | default(details.type , 'undefined') }}; 52 | 53 | /** 54 | * Getter ${{name}} 55 | * @return { {{ details.type }} } 56 | */ 57 | public get ${{name}}(): {{ details.type |default(details.type , 'undefined') }} { 58 | return this.{{name}}; 59 | } 60 | 61 | /** 62 | * Setter ${{name}} 63 | * @param { {{ details.type }} } value 64 | */ 65 | public set ${{name}}(value: {{ details.type |default(details.type , 'undefined') }}) { 66 | this.{{name}} = value; 67 | } 68 | {% endfor %} 69 | 70 | } 71 | 72 | -------------------------------------------------------------------------------- /examples/proto/basic-asset.proto: -------------------------------------------------------------------------------- 1 | // 2 | // SPDX-License-Identifier: Apache-2.0 3 | // 4 | 5 | // need generator for a sample 6 | 7 | syntax = "proto3"; 8 | package assettransfer; 9 | 10 | import "fabric/contract.proto"; 11 | import "fabric/metadata.proto"; 12 | 13 | // common result message 14 | message ContractResult { 15 | int32 code = 1; 16 | string msg = 2; 17 | } 18 | 19 | message Asset { 20 | option (fabric.network_serialization).defaultstyle = JSON; 21 | option (fabric.ledger_serialization).defaultstyle = JSON; 22 | 23 | message Key { 24 | string key = 1; 25 | } 26 | 27 | Key uuid = 1; 28 | string value = 2; 29 | } 30 | 31 | 32 | // --------------------------------------------------------------------- 33 | // Transactions: 34 | // For each there is a Request and Result type 35 | message AssetExistsTx { 36 | message Request { 37 | Asset.Key key = 1; 38 | } 39 | message Result { 40 | ContractResult result =1; 41 | } 42 | } 43 | 44 | message ReadAssetTx { 45 | message Request { 46 | Asset.Key key = 1; 47 | } 48 | message Result {9 49 | ContractResult result = 1; 50 | Asset asset = 2; 51 | } 52 | } 53 | 54 | message CreateAssetTx { 55 | message Request{ 56 | Asset.Key key = 1; 57 | string value = 2; 58 | } 59 | message Result { 60 | ContractResult result =1; 61 | } 62 | } 63 | 64 | message UpdateAssetTx { 65 | message Request{ 66 | Asset.Key key = 1; 67 | string value = 2; 68 | } 69 | message Result { 70 | ContractResult result =1; 71 | } 72 | } 73 | 74 | message DeleteAssetTx { 75 | message Request { 76 | Asset.Key key = 1; 77 | } 78 | message Result { 79 | ContractResult result =1; 80 | } 81 | } 82 | 83 | 84 | // API definitions 85 | service AssetTransfer { 86 | rpc propseBuyAgreement(BuyAgreementTx.Request) returns (BuyAgreementTx.Result); 87 | rpc confirmBuyAgreement(ConfirmBuyAgreementTx.Request) returns (ConfirmBuyAgreementTx.Result); 88 | 89 | rpc assetExists (AssetExistsTx.Request) returns (AssetExistsTx.Result); 90 | rpc createAsset (CreateAssetTx.Request) returns (CreateAssetTx.Result); 91 | rpc readAsset (ReadAssetTx.Request) returns (ReadAssetTx.Result); 92 | rpc updateAsset (UpdateAssetTx.Request) returns (UpdateAssetTx.Result); 93 | rpc deleteAsset (DeleteAssetTx.Request) returns (DeleteAssetTx.Result); 94 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "generator", 3 | "version": "1.0.0", 4 | "description": "Resource Generator from metadata", 5 | "main": "dist/index.js", 6 | "bin": { 7 | "fabart": "./dist/cli.js", 8 | "protoc-gen-fabart": "./dist/protoc-plugin/protoc-gen-fabart.js" 9 | }, 10 | "typings": "dist/index.d.ts", 11 | "engines": { 12 | "node": ">=8", 13 | "npm": ">=5" 14 | }, 15 | "scripts": { 16 | "lint": "tslint -c tslint.json 'src/**/*.ts'", 17 | "pretest": "npm run lint", 18 | "test": "nyc mocha -r ts-node/register src/**/*.spec.ts", 19 | "build": "tsc && cp -r ./templates ./dist/ && cp -r ./src/protoc-plugin/google ./dist/protoc-plugin/ && cp -r ./src/protoc-plugin/fabric ./dist/protoc-plugin/", 20 | "build:watch": "tsc -w", 21 | "prepublishOnly": "npm run build" 22 | }, 23 | "author": "", 24 | "license": "ISC", 25 | "dependencies": { 26 | "ajv": "^6.6.1", 27 | "buffer-to-uint8array": "^1.1.0", 28 | "composer-concerto": "^0.70.5", 29 | "google-protobuf": "^3.11.4", 30 | "jsonata": "^1.8.3", 31 | "mkdirp": "^0.5.1", 32 | "nunjucks": "^3.1.7", 33 | "prettier": "^1.15.3", 34 | "protobufjs": "^6.9.0", 35 | "stream-to-promise": "^2.2.0", 36 | "ts-protoc-gen": "^0.12.0", 37 | "tsc": "^1.20150623.0", 38 | "yargs": "^12.0.5" 39 | }, 40 | "devDependencies": { 41 | "@types/chai": "^4.1.4", 42 | "@types/mocha": "^5.2.3", 43 | "@types/node": "^10.3.6", 44 | "@types/sinon": "^5.0.7", 45 | "@types/sinon-chai": "^3.2.0", 46 | "chai": "^4.1.2", 47 | "mocha": "^5.2.0", 48 | "nyc": "^12.0.2", 49 | "sinon": "^6.0.0", 50 | "sinon-chai": "^3.2.0", 51 | "standard-version": "^4.4.0", 52 | "ts-node": "^7.0.0", 53 | "tslint": "^5.10.0", 54 | "typescript": "^3.3.3" 55 | }, 56 | "nyc": { 57 | "extension": [ 58 | ".ts", 59 | ".tsx" 60 | ], 61 | "exclude": [ 62 | "coverage/**", 63 | "dist/**" 64 | ], 65 | "reporter": [ 66 | "text-summary", 67 | "html" 68 | ], 69 | "all": true, 70 | "check-coverage": true, 71 | "statements": 100, 72 | "branches": 100, 73 | "functions": 100, 74 | "lines": 100 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/protos/google/protobuf/source_context.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option java_package = "com.google.protobuf"; 37 | option java_outer_classname = "SourceContextProto"; 38 | option java_multiple_files = true; 39 | option objc_class_prefix = "GPB"; 40 | option go_package = "google.golang.org/genproto/protobuf/source_context;source_context"; 41 | 42 | // `SourceContext` represents information about the source of a 43 | // protobuf element, like the file in which it is defined. 44 | message SourceContext { 45 | // The path-qualified name of the .proto file that contained the associated 46 | // protobuf element. For example: `"google/protobuf/source_context.proto"`. 47 | string file_name = 1; 48 | } 49 | -------------------------------------------------------------------------------- /examples/proto/google/protobuf/source_context.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option java_package = "com.google.protobuf"; 37 | option java_outer_classname = "SourceContextProto"; 38 | option java_multiple_files = true; 39 | option objc_class_prefix = "GPB"; 40 | option go_package = "google.golang.org/genproto/protobuf/source_context;source_context"; 41 | 42 | // `SourceContext` represents information about the source of a 43 | // protobuf element, like the file in which it is defined. 44 | message SourceContext { 45 | // The path-qualified name of the .proto file that contained the associated 46 | // protobuf element. For example: `"google/protobuf/source_context.proto"`. 47 | string file_name = 1; 48 | } 49 | -------------------------------------------------------------------------------- /src/protos/google/protobuf/empty.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option go_package = "github.com/golang/protobuf/ptypes/empty"; 37 | option java_package = "com.google.protobuf"; 38 | option java_outer_classname = "EmptyProto"; 39 | option java_multiple_files = true; 40 | option objc_class_prefix = "GPB"; 41 | option cc_enable_arenas = true; 42 | 43 | // A generic empty message that you can re-use to avoid defining duplicated 44 | // empty messages in your APIs. A typical example is to use it as the request 45 | // or the response type of an API method. For instance: 46 | // 47 | // service Foo { 48 | // rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); 49 | // } 50 | // 51 | // The JSON representation for `Empty` is empty JSON object `{}`. 52 | message Empty {} 53 | -------------------------------------------------------------------------------- /examples/proto/google/protobuf/empty.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option go_package = "github.com/golang/protobuf/ptypes/empty"; 37 | option java_package = "com.google.protobuf"; 38 | option java_outer_classname = "EmptyProto"; 39 | option java_multiple_files = true; 40 | option objc_class_prefix = "GPB"; 41 | option cc_enable_arenas = true; 42 | 43 | // A generic empty message that you can re-use to avoid defining duplicated 44 | // empty messages in your APIs. A typical example is to use it as the request 45 | // or the response type of an API method. For instance: 46 | // 47 | // service Foo { 48 | // rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); 49 | // } 50 | // 51 | // The JSON representation for `Empty` is empty JSON object `{}`. 52 | message Empty {} 53 | -------------------------------------------------------------------------------- /src/protoc-plugin/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-License-Identifier: Apache-2.0 3 | */ 4 | 5 | import tou8 = require('buffer-to-uint8array'); 6 | import * as streamToPromise from 'stream-to-promise'; 7 | import { CodeGeneratorRequest, CodeGeneratorResponse } from './google/protobuf/compiler/plugin_pb'; 8 | // extensions must be required before parsing 9 | require('./google/api/annotations_pb'); 10 | require('./fabric/contract_pb'); 11 | require('./fabric/metadata_pb'); 12 | 13 | export default class Plugin { 14 | 15 | /** 16 | * Promise for incoming request, as CodeGeneratorRequest from google-protobuf 17 | * @param {stream} stdin Incoming stream, default: process.stdin 18 | * @return {Promise} Resolves to CodeGeneratorRequest from google-protobuf 19 | */ 20 | public async CodeGeneratorRequest(stdin = process.stdin) { 21 | const buffer = await streamToPromise(stdin); 22 | return CodeGeneratorRequest.deserializeBinary(tou8(buffer)); 23 | } 24 | 25 | /** 26 | * Promise for outgoing response, as CodeGeneratorResponse from google-protobuf 27 | * @param {stream} stdout Outgoing stream, default: process.stdout 28 | */ 29 | public CodeGeneratorResponse(files, stdout = process.stdout) { 30 | 31 | let out: CodeGeneratorResponse = new CodeGeneratorResponse(); 32 | 33 | files.forEach((f, i) => { 34 | const file = new CodeGeneratorResponse.File(); 35 | if (f.name) { 36 | file.setName(f.name); 37 | } 38 | if (f.content) { 39 | file.setContent(f.content); 40 | } 41 | if (f.insertion_point) { 42 | file.setInsertionPoint(f.insertion_point); 43 | } 44 | 45 | out.addFile(file); 46 | 47 | }); 48 | stdout.write(Buffer.from(out.serializeBinary())); 49 | } 50 | 51 | /** 52 | * Convenience function for error-handlers 53 | * @param {stream} stdout Outgoing stream, default: process.stdout 54 | * @return {function} Error-handler that puts error into error-field of CodeGeneratorResponse and sends to stdout 55 | */ 56 | public CodeGeneratorResponseError(err, stdout = process.stdout) { 57 | const out = new CodeGeneratorResponse() 58 | out.setError(err.toString()); 59 | stdout.write(Buffer.from(out.serializeBinary())) 60 | } 61 | 62 | public async run(cb) { 63 | 64 | try { 65 | let req = (await this.CodeGeneratorRequest()).toObject(); 66 | 67 | console.error(`${JSON.stringify(req.parameter)}`); 68 | let protos = req.protoFileList.filter(p => req.fileToGenerateList.indexOf(p.name) !== -1); 69 | 70 | let files = protos.map(cb); 71 | console.error(`Going to create the response`); 72 | this.CodeGeneratorResponse(files); 73 | } catch (err) { 74 | this.CodeGeneratorResponseError(err); 75 | } 76 | } 77 | 78 | } 79 | 80 | 81 | -------------------------------------------------------------------------------- /dist/resourcefactory.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"resourcefactory.js","sourceRoot":"","sources":["../src/resourcefactory.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb;;EAEE;AACF,iCAA0B;AAC1B,yBAA0B;AAC1B,gCAAiC;AACjC,mCAAoC;AACpC,iCAAiC;AACjC,qCAAsC;AACtC,6BAA8B;AAC9B,qCAAsC;AAItC,MAAM,GAAG,GAAG,eAAK,CAAC,yBAAyB,CAAC,CAAC;AAE7C;;;;;GAKG;AACH,MAAqB,eAAe;IAShC,YAAmB,MAAc;QAE7B,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACnD,GAAG,CAAC,uBAAuB,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC;QAEpD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAW,CAAC,CAAC;QACrF,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QACnE,GAAG,CAAC,8BAA8B,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;QACvD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,EAAC;YAClC,MAAM,IAAI,KAAK,CAAC,qBAAqB,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;SAC7D;QAED,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACtD,GAAG,CAAC,iCAAiC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QACpD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAEzB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,QAAQ,CAC5B,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;QAEvE,4BAA4B;QAC5B,IAAI,CAAC,GAAG,GAAG,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAEjD,qDAAqD;QACrD,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC,GAAG,GAAG,EAAE,EAAE,EAAE;YACxC,MAAM,QAAQ,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;YAC5B,IAAI,QAAQ,KAAK,EAAE,EAAE;gBACjB,OAAO,MAAM,CAAC;aACjB;iBAAM;gBACH,OAAO,QAAQ,CAAC;aACnB;QACL,CAAC,CAAC,CAAC;QAEH,qDAAqD;QACrD,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,YAAY,EAAE,CAAC,GAAG,GAAG,EAAE,EAAE,EAAE;YAC1C,MAAM,QAAQ,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;YAC5B,uCAAuC;YACvC,IAAI,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;gBAE1B,OAAO,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;aAC5D;iBAAM;gBACH,OAAO,QAAQ,CAAC;aACnB;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,KAAK;QACd,MAAM,MAAM,GAAG,QAAQ,CAAC;QACxB,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;QACrD,MAAM,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAClD,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACnB,2BAA2B;QAC3B,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YACtB,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;YAChE,MAAM,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC;YAEtC,+CAA+C;YAC/C,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,MAAM,CAAC,SAAS,OAAO,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YAExG,0CAA0C;YAC1C,IAAI,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;YAEzD,IAAI,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,SAAS,KAAK,MAAM,EAAE;gBACjD,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;gBACtB,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;aACtD;YACD,GAAG,CAAC,uBAAuB,cAAc,EAAE,CAAC,CAAC;YAC7C,EAAE,CAAC,aAAa,CAAC,GAAG,cAAc,GAAG,MAAM,CAAC,UAAU,EAAE,EAAE,MAAM,CAAC,CAAC;QACtE,CAAC,CAAC,CAAC;IAEP,CAAC;CACJ;AAlFD,kCAkFC"} -------------------------------------------------------------------------------- /dist/protoc-plugin/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /* 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const tou8 = require("buffer-to-uint8array"); 7 | const streamToPromise = require("stream-to-promise"); 8 | const plugin_pb_1 = require("./google/protobuf/compiler/plugin_pb"); 9 | // extensions must be required before parsing 10 | require('./google/api/annotations_pb'); 11 | require('./fabric/contract_pb'); 12 | require('./fabric/metadata_pb'); 13 | class Plugin { 14 | /** 15 | * Promise for incoming request, as CodeGeneratorRequest from google-protobuf 16 | * @param {stream} stdin Incoming stream, default: process.stdin 17 | * @return {Promise} Resolves to CodeGeneratorRequest from google-protobuf 18 | */ 19 | async CodeGeneratorRequest(stdin = process.stdin) { 20 | const buffer = await streamToPromise(stdin); 21 | return plugin_pb_1.CodeGeneratorRequest.deserializeBinary(tou8(buffer)); 22 | } 23 | /** 24 | * Promise for outgoing response, as CodeGeneratorResponse from google-protobuf 25 | * @param {stream} stdout Outgoing stream, default: process.stdout 26 | */ 27 | CodeGeneratorResponse(files, stdout = process.stdout) { 28 | let out = new plugin_pb_1.CodeGeneratorResponse(); 29 | files.forEach((f, i) => { 30 | const file = new plugin_pb_1.CodeGeneratorResponse.File(); 31 | if (f.name) { 32 | file.setName(f.name); 33 | } 34 | if (f.content) { 35 | file.setContent(f.content); 36 | } 37 | if (f.insertion_point) { 38 | file.setInsertionPoint(f.insertion_point); 39 | } 40 | out.addFile(file); 41 | }); 42 | stdout.write(Buffer.from(out.serializeBinary())); 43 | } 44 | /** 45 | * Convenience function for error-handlers 46 | * @param {stream} stdout Outgoing stream, default: process.stdout 47 | * @return {function} Error-handler that puts error into error-field of CodeGeneratorResponse and sends to stdout 48 | */ 49 | CodeGeneratorResponseError(err, stdout = process.stdout) { 50 | const out = new plugin_pb_1.CodeGeneratorResponse(); 51 | out.setError(err.toString()); 52 | stdout.write(Buffer.from(out.serializeBinary())); 53 | } 54 | async run(cb) { 55 | try { 56 | let req = (await this.CodeGeneratorRequest()).toObject(); 57 | console.error(`${JSON.stringify(req.parameter)}`); 58 | let protos = req.protoFileList.filter(p => req.fileToGenerateList.indexOf(p.name) !== -1); 59 | let files = protos.map(cb); 60 | console.error(`Going to create the response`); 61 | this.CodeGeneratorResponse(files); 62 | } 63 | catch (err) { 64 | this.CodeGeneratorResponseError(err); 65 | } 66 | } 67 | } 68 | exports.default = Plugin; 69 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /generated/fabric/metadata_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: fabric 2 | // file: fabric/metadata.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as google_protobuf_descriptor_pb from "google-protobuf/google/protobuf/descriptor_pb"; 6 | 7 | export class Serialization extends jspb.Message { 8 | hasDefaultstyle(): boolean; 9 | clearDefaultstyle(): void; 10 | getDefaultstyle(): Serialization.DefaultMethodsMap[keyof Serialization.DefaultMethodsMap]; 11 | setDefaultstyle(value: Serialization.DefaultMethodsMap[keyof Serialization.DefaultMethodsMap]): void; 12 | 13 | hasCustomid(): boolean; 14 | clearCustomid(): void; 15 | getCustomid(): string; 16 | setCustomid(value: string): void; 17 | 18 | getMethodCase(): Serialization.MethodCase; 19 | serializeBinary(): Uint8Array; 20 | toObject(includeInstance?: boolean): Serialization.AsObject; 21 | static toObject(includeInstance: boolean, msg: Serialization): Serialization.AsObject; 22 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 23 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 24 | static serializeBinaryToWriter(message: Serialization, writer: jspb.BinaryWriter): void; 25 | static deserializeBinary(bytes: Uint8Array): Serialization; 26 | static deserializeBinaryFromReader(message: Serialization, reader: jspb.BinaryReader): Serialization; 27 | } 28 | 29 | export namespace Serialization { 30 | export type AsObject = { 31 | defaultstyle: Serialization.DefaultMethodsMap[keyof Serialization.DefaultMethodsMap], 32 | customid: string, 33 | } 34 | 35 | export interface DefaultMethodsMap { 36 | UNKNOWN: 0; 37 | JSON: 1; 38 | PROTOBUF: 2; 39 | } 40 | 41 | export const DefaultMethods: DefaultMethodsMap; 42 | 43 | export enum MethodCase { 44 | METHOD_NOT_SET = 0, 45 | DEFAULTSTYLE = 1, 46 | CUSTOMID = 2, 47 | } 48 | } 49 | 50 | export class Typing extends jspb.Message { 51 | getFormat(): Typing.FormatsMap[keyof Typing.FormatsMap]; 52 | setFormat(value: Typing.FormatsMap[keyof Typing.FormatsMap]): void; 53 | 54 | getPattern(): string; 55 | setPattern(value: string): void; 56 | 57 | serializeBinary(): Uint8Array; 58 | toObject(includeInstance?: boolean): Typing.AsObject; 59 | static toObject(includeInstance: boolean, msg: Typing): Typing.AsObject; 60 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 61 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 62 | static serializeBinaryToWriter(message: Typing, writer: jspb.BinaryWriter): void; 63 | static deserializeBinary(bytes: Uint8Array): Typing; 64 | static deserializeBinaryFromReader(message: Typing, reader: jspb.BinaryReader): Typing; 65 | } 66 | 67 | export namespace Typing { 68 | export type AsObject = { 69 | format: Typing.FormatsMap[keyof Typing.FormatsMap], 70 | pattern: string, 71 | } 72 | 73 | export interface FormatsMap { 74 | UNKNOWN: 0; 75 | DATE_TIME: 1; 76 | BYTE: 2; 77 | } 78 | 79 | export const Formats: FormatsMap; 80 | } 81 | 82 | export const networkSerialization: jspb.ExtensionFieldInfo; 83 | 84 | export const ledgerSerialization: jspb.ExtensionFieldInfo; 85 | 86 | export const typeInfo: jspb.ExtensionFieldInfo; 87 | 88 | export const transient: jspb.ExtensionFieldInfo; 89 | 90 | -------------------------------------------------------------------------------- /dist/protoc-plugin/fabric/metadata_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: fabric 2 | // file: fabric/metadata.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as google_protobuf_descriptor_pb from "google-protobuf/google/protobuf/descriptor_pb"; 6 | 7 | export class Serialization extends jspb.Message { 8 | hasDefaultstyle(): boolean; 9 | clearDefaultstyle(): void; 10 | getDefaultstyle(): Serialization.DefaultMethodsMap[keyof Serialization.DefaultMethodsMap]; 11 | setDefaultstyle(value: Serialization.DefaultMethodsMap[keyof Serialization.DefaultMethodsMap]): void; 12 | 13 | hasCustomid(): boolean; 14 | clearCustomid(): void; 15 | getCustomid(): string; 16 | setCustomid(value: string): void; 17 | 18 | getMethodCase(): Serialization.MethodCase; 19 | serializeBinary(): Uint8Array; 20 | toObject(includeInstance?: boolean): Serialization.AsObject; 21 | static toObject(includeInstance: boolean, msg: Serialization): Serialization.AsObject; 22 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 23 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 24 | static serializeBinaryToWriter(message: Serialization, writer: jspb.BinaryWriter): void; 25 | static deserializeBinary(bytes: Uint8Array): Serialization; 26 | static deserializeBinaryFromReader(message: Serialization, reader: jspb.BinaryReader): Serialization; 27 | } 28 | 29 | export namespace Serialization { 30 | export type AsObject = { 31 | defaultstyle: Serialization.DefaultMethodsMap[keyof Serialization.DefaultMethodsMap], 32 | customid: string, 33 | } 34 | 35 | export interface DefaultMethodsMap { 36 | UNKNOWN: 0; 37 | JSON: 1; 38 | PROTOBUF: 2; 39 | } 40 | 41 | export const DefaultMethods: DefaultMethodsMap; 42 | 43 | export enum MethodCase { 44 | METHOD_NOT_SET = 0, 45 | DEFAULTSTYLE = 1, 46 | CUSTOMID = 2, 47 | } 48 | } 49 | 50 | export class Typing extends jspb.Message { 51 | getFormat(): Typing.FormatsMap[keyof Typing.FormatsMap]; 52 | setFormat(value: Typing.FormatsMap[keyof Typing.FormatsMap]): void; 53 | 54 | getPattern(): string; 55 | setPattern(value: string): void; 56 | 57 | serializeBinary(): Uint8Array; 58 | toObject(includeInstance?: boolean): Typing.AsObject; 59 | static toObject(includeInstance: boolean, msg: Typing): Typing.AsObject; 60 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 61 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 62 | static serializeBinaryToWriter(message: Typing, writer: jspb.BinaryWriter): void; 63 | static deserializeBinary(bytes: Uint8Array): Typing; 64 | static deserializeBinaryFromReader(message: Typing, reader: jspb.BinaryReader): Typing; 65 | } 66 | 67 | export namespace Typing { 68 | export type AsObject = { 69 | format: Typing.FormatsMap[keyof Typing.FormatsMap], 70 | pattern: string, 71 | } 72 | 73 | export interface FormatsMap { 74 | UNKNOWN: 0; 75 | DATE_TIME: 1; 76 | BYTE: 2; 77 | } 78 | 79 | export const Formats: FormatsMap; 80 | } 81 | 82 | export const networkSerialization: jspb.ExtensionFieldInfo; 83 | 84 | export const ledgerSerialization: jspb.ExtensionFieldInfo; 85 | 86 | export const typeInfo: jspb.ExtensionFieldInfo; 87 | 88 | export const transient: jspb.ExtensionFieldInfo; 89 | 90 | -------------------------------------------------------------------------------- /src/protoc-plugin/fabric/metadata_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: fabric 2 | // file: fabric/metadata.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as google_protobuf_descriptor_pb from "google-protobuf/google/protobuf/descriptor_pb"; 6 | 7 | export class Serialization extends jspb.Message { 8 | hasDefaultstyle(): boolean; 9 | clearDefaultstyle(): void; 10 | getDefaultstyle(): Serialization.DefaultMethodsMap[keyof Serialization.DefaultMethodsMap]; 11 | setDefaultstyle(value: Serialization.DefaultMethodsMap[keyof Serialization.DefaultMethodsMap]): void; 12 | 13 | hasCustomid(): boolean; 14 | clearCustomid(): void; 15 | getCustomid(): string; 16 | setCustomid(value: string): void; 17 | 18 | getMethodCase(): Serialization.MethodCase; 19 | serializeBinary(): Uint8Array; 20 | toObject(includeInstance?: boolean): Serialization.AsObject; 21 | static toObject(includeInstance: boolean, msg: Serialization): Serialization.AsObject; 22 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 23 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 24 | static serializeBinaryToWriter(message: Serialization, writer: jspb.BinaryWriter): void; 25 | static deserializeBinary(bytes: Uint8Array): Serialization; 26 | static deserializeBinaryFromReader(message: Serialization, reader: jspb.BinaryReader): Serialization; 27 | } 28 | 29 | export namespace Serialization { 30 | export type AsObject = { 31 | defaultstyle: Serialization.DefaultMethodsMap[keyof Serialization.DefaultMethodsMap], 32 | customid: string, 33 | } 34 | 35 | export interface DefaultMethodsMap { 36 | UNKNOWN: 0; 37 | JSON: 1; 38 | PROTOBUF: 2; 39 | } 40 | 41 | export const DefaultMethods: DefaultMethodsMap; 42 | 43 | export enum MethodCase { 44 | METHOD_NOT_SET = 0, 45 | DEFAULTSTYLE = 1, 46 | CUSTOMID = 2, 47 | } 48 | } 49 | 50 | export class Typing extends jspb.Message { 51 | getFormat(): Typing.FormatsMap[keyof Typing.FormatsMap]; 52 | setFormat(value: Typing.FormatsMap[keyof Typing.FormatsMap]): void; 53 | 54 | getPattern(): string; 55 | setPattern(value: string): void; 56 | 57 | serializeBinary(): Uint8Array; 58 | toObject(includeInstance?: boolean): Typing.AsObject; 59 | static toObject(includeInstance: boolean, msg: Typing): Typing.AsObject; 60 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 61 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 62 | static serializeBinaryToWriter(message: Typing, writer: jspb.BinaryWriter): void; 63 | static deserializeBinary(bytes: Uint8Array): Typing; 64 | static deserializeBinaryFromReader(message: Typing, reader: jspb.BinaryReader): Typing; 65 | } 66 | 67 | export namespace Typing { 68 | export type AsObject = { 69 | format: Typing.FormatsMap[keyof Typing.FormatsMap], 70 | pattern: string, 71 | } 72 | 73 | export interface FormatsMap { 74 | UNKNOWN: 0; 75 | DATE_TIME: 1; 76 | BYTE: 2; 77 | } 78 | 79 | export const Formats: FormatsMap; 80 | } 81 | 82 | export const networkSerialization: jspb.ExtensionFieldInfo; 83 | 84 | export const ledgerSerialization: jspb.ExtensionFieldInfo; 85 | 86 | export const typeInfo: jspb.ExtensionFieldInfo; 87 | 88 | export const transient: jspb.ExtensionFieldInfo; 89 | 90 | -------------------------------------------------------------------------------- /dist/resourcefactory.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | /* 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | const debug_1 = require("debug"); 7 | const fs = require("fs"); 8 | const yaml = require("js-yaml"); 9 | const jsonata = require("jsonata"); 10 | const mkdirp = require("mkdirp"); 11 | const nunjucks = require("nunjucks"); 12 | const path = require("path"); 13 | const prettier = require("prettier"); 14 | const LOG = debug_1.default('resourcefactory:factory'); 15 | /** 16 | * Resource Factory 17 | * 18 | * Create an instance with an IConfig object 19 | * Then call start() to produce the documentation 20 | */ 21 | class ResourceFactory { 22 | constructor(config) { 23 | this.resolvedFilename = path.resolve(config.input); 24 | LOG(`Using metadata file ${this.resolvedFilename}`); 25 | this.jsonData = JSON.parse(fs.readFileSync(this.resolvedFilename, 'utf8')); 26 | this.templateRoot = path.join(__dirname, 'templates', config.task); 27 | LOG(`Using the template root at ${this.templateRoot}`); 28 | if (!fs.existsSync(this.templateRoot)) { 29 | throw new Error(`Unknown template::${this.templateRoot}`); 30 | } 31 | this.output = path.resolve(config.output, config.task); 32 | LOG(`Using the output directory of ${this.output}`); 33 | mkdirp.sync(this.output); 34 | this.templateCfg = yaml.safeLoad(fs.readFileSync(path.join(this.templateRoot, 'cfg.yaml'), 'utf8')); 35 | // make the output directory 36 | this.env = nunjucks.configure(this.templateRoot); 37 | // trim out typenames and replace with void if needed 38 | this.env.addFilter('typename', (str = '') => { 39 | const typename = str.trim(); 40 | if (typename === '') { 41 | return 'void'; 42 | } 43 | else { 44 | return typename; 45 | } 46 | }); 47 | // trim out typenames and replace with void if needed 48 | this.env.addFilter('objectname', (str = '') => { 49 | const typename = str.trim(); 50 | // console.log(`=${typename.trim()}=`); 51 | if (typename.startsWith('#')) { 52 | return typename.substring(typename.lastIndexOf('/') + 1); 53 | } 54 | else { 55 | return typename; 56 | } 57 | }); 58 | } 59 | /** Starts the factory generating output based on the template configuration 60 | * 61 | */ 62 | async start() { 63 | const filter = 'filter'; 64 | const expression = jsonata(this.templateCfg[filter]); 65 | const result = expression.evaluate(this.jsonData); 66 | LOG(this.jsonData); 67 | // iterate over the results 68 | result.forEach((action) => { 69 | const outputFilename = path.join(this.output, action._filename); 70 | const templateFile = action._template; 71 | // writeout the data as well for debug purposes 72 | fs.writeFileSync(path.join(this.output, `data-${action._filename}.json`), JSON.stringify(action._data)); 73 | // render the output, and format is needed 74 | let output = nunjucks.render(templateFile, action._data); 75 | if (action._prettier && action._prettier !== 'none') { 76 | LOG(action._prettier); 77 | output = prettier.format(output, action._prettier); 78 | } 79 | LOG(`Writing output file ${outputFilename}`); 80 | fs.writeFileSync(`${outputFilename}${action._extension}`, output); 81 | }); 82 | } 83 | } 84 | exports.default = ResourceFactory; 85 | //# sourceMappingURL=resourcefactory.js.map -------------------------------------------------------------------------------- /src/resourcefactory.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | import debug from 'debug'; 6 | import fs = require('fs'); 7 | import yaml = require('js-yaml'); 8 | import jsonata = require('jsonata'); 9 | import * as mkdirp from 'mkdirp'; 10 | import nunjucks = require('nunjucks'); 11 | import path = require('path'); 12 | import prettier = require('prettier'); 13 | import Config from './config'; 14 | import Factory from './factory'; 15 | 16 | const LOG = debug('resourcefactory:factory'); 17 | 18 | /** 19 | * Resource Factory 20 | * 21 | * Create an instance with an IConfig object 22 | * Then call start() to produce the documentation 23 | */ 24 | export default class ResourceFactory implements Factory { 25 | 26 | private resolvedFilename: string; 27 | private jsonData: string; 28 | private templateRoot: string; 29 | private templateCfg: object; 30 | private output: string; 31 | private env: nunjucks; 32 | 33 | public constructor(config: Config) { 34 | 35 | this.resolvedFilename = path.resolve(config.input); 36 | LOG(`Using metadata file ${this.resolvedFilename}`); 37 | 38 | this.jsonData = JSON.parse(fs.readFileSync(this.resolvedFilename, 'utf8') as string); 39 | this.templateRoot = path.join(__dirname, 'templates', config.task); 40 | LOG(`Using the template root at ${this.templateRoot}`); 41 | if (!fs.existsSync(this.templateRoot)){ 42 | throw new Error(`Unknown template::${this.templateRoot}`); 43 | } 44 | 45 | this.output = path.resolve(config.output,config.task); 46 | LOG(`Using the output directory of ${this.output}`); 47 | mkdirp.sync(this.output); 48 | 49 | this.templateCfg = yaml.safeLoad( 50 | fs.readFileSync(path.join(this.templateRoot, 'cfg.yaml'), 'utf8')); 51 | 52 | // make the output directory 53 | this.env = nunjucks.configure(this.templateRoot); 54 | 55 | // trim out typenames and replace with void if needed 56 | this.env.addFilter('typename', (str = '') => { 57 | const typename = str.trim(); 58 | if (typename === '') { 59 | return 'void'; 60 | } else { 61 | return typename; 62 | } 63 | }); 64 | 65 | // trim out typenames and replace with void if needed 66 | this.env.addFilter('objectname', (str = '') => { 67 | const typename = str.trim(); 68 | // console.log(`=${typename.trim()}=`); 69 | if (typename.startsWith('#')) { 70 | 71 | return typename.substring(typename.lastIndexOf('/') + 1); 72 | } else { 73 | return typename; 74 | } 75 | }); 76 | } 77 | 78 | /** Starts the factory generating output based on the template configuration 79 | * 80 | */ 81 | public async start(): Promise { 82 | const filter = 'filter'; 83 | const expression = jsonata(this.templateCfg[filter]); 84 | const result = expression.evaluate(this.jsonData); 85 | LOG(this.jsonData); 86 | // iterate over the results 87 | result.forEach((action) => { 88 | const outputFilename = path.join(this.output, action._filename); 89 | const templateFile = action._template; 90 | 91 | // writeout the data as well for debug purposes 92 | fs.writeFileSync(path.join(this.output, `data-${action._filename}.json`), JSON.stringify(action._data)); 93 | 94 | // render the output, and format is needed 95 | let output = nunjucks.render(templateFile, action._data); 96 | 97 | if (action._prettier && action._prettier !== 'none') { 98 | LOG(action._prettier); 99 | output = prettier.format(output, action._prettier); 100 | } 101 | LOG(`Writing output file ${outputFilename}`); 102 | fs.writeFileSync(`${outputFilename}${action._extension}`, output); 103 | }); 104 | 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/protos/google/protobuf/struct.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option cc_enable_arenas = true; 37 | option go_package = "github.com/golang/protobuf/ptypes/struct;structpb"; 38 | option java_package = "com.google.protobuf"; 39 | option java_outer_classname = "StructProto"; 40 | option java_multiple_files = true; 41 | option objc_class_prefix = "GPB"; 42 | 43 | 44 | // `Struct` represents a structured data value, consisting of fields 45 | // which map to dynamically typed values. In some languages, `Struct` 46 | // might be supported by a native representation. For example, in 47 | // scripting languages like JS a struct is represented as an 48 | // object. The details of that representation are described together 49 | // with the proto support for the language. 50 | // 51 | // The JSON representation for `Struct` is JSON object. 52 | message Struct { 53 | // Unordered map of dynamically typed values. 54 | map fields = 1; 55 | } 56 | 57 | // `Value` represents a dynamically typed value which can be either 58 | // null, a number, a string, a boolean, a recursive struct value, or a 59 | // list of values. A producer of value is expected to set one of that 60 | // variants, absence of any variant indicates an error. 61 | // 62 | // The JSON representation for `Value` is JSON value. 63 | message Value { 64 | // The kind of value. 65 | oneof kind { 66 | // Represents a null value. 67 | NullValue null_value = 1; 68 | // Represents a double value. 69 | double number_value = 2; 70 | // Represents a string value. 71 | string string_value = 3; 72 | // Represents a boolean value. 73 | bool bool_value = 4; 74 | // Represents a structured value. 75 | Struct struct_value = 5; 76 | // Represents a repeated `Value`. 77 | ListValue list_value = 6; 78 | } 79 | } 80 | 81 | // `NullValue` is a singleton enumeration to represent the null value for the 82 | // `Value` type union. 83 | // 84 | // The JSON representation for `NullValue` is JSON `null`. 85 | enum NullValue { 86 | // Null value. 87 | NULL_VALUE = 0; 88 | } 89 | 90 | // `ListValue` is a wrapper around a repeated field of values. 91 | // 92 | // The JSON representation for `ListValue` is JSON array. 93 | message ListValue { 94 | // Repeated field of dynamically typed values. 95 | repeated Value values = 1; 96 | } 97 | -------------------------------------------------------------------------------- /examples/proto/google/protobuf/struct.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option cc_enable_arenas = true; 37 | option go_package = "github.com/golang/protobuf/ptypes/struct;structpb"; 38 | option java_package = "com.google.protobuf"; 39 | option java_outer_classname = "StructProto"; 40 | option java_multiple_files = true; 41 | option objc_class_prefix = "GPB"; 42 | 43 | 44 | // `Struct` represents a structured data value, consisting of fields 45 | // which map to dynamically typed values. In some languages, `Struct` 46 | // might be supported by a native representation. For example, in 47 | // scripting languages like JS a struct is represented as an 48 | // object. The details of that representation are described together 49 | // with the proto support for the language. 50 | // 51 | // The JSON representation for `Struct` is JSON object. 52 | message Struct { 53 | // Unordered map of dynamically typed values. 54 | map fields = 1; 55 | } 56 | 57 | // `Value` represents a dynamically typed value which can be either 58 | // null, a number, a string, a boolean, a recursive struct value, or a 59 | // list of values. A producer of value is expected to set one of that 60 | // variants, absence of any variant indicates an error. 61 | // 62 | // The JSON representation for `Value` is JSON value. 63 | message Value { 64 | // The kind of value. 65 | oneof kind { 66 | // Represents a null value. 67 | NullValue null_value = 1; 68 | // Represents a double value. 69 | double number_value = 2; 70 | // Represents a string value. 71 | string string_value = 3; 72 | // Represents a boolean value. 73 | bool bool_value = 4; 74 | // Represents a structured value. 75 | Struct struct_value = 5; 76 | // Represents a repeated `Value`. 77 | ListValue list_value = 6; 78 | } 79 | } 80 | 81 | // `NullValue` is a singleton enumeration to represent the null value for the 82 | // `Value` type union. 83 | // 84 | // The JSON representation for `NullValue` is JSON `null`. 85 | enum NullValue { 86 | // Null value. 87 | NULL_VALUE = 0; 88 | } 89 | 90 | // `ListValue` is a wrapper around a repeated field of values. 91 | // 92 | // The JSON representation for `ListValue` is JSON array. 93 | message ListValue { 94 | // Repeated field of dynamically typed values. 95 | repeated Value values = 1; 96 | } 97 | -------------------------------------------------------------------------------- /src/protos/google/protobuf/wrappers.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Wrappers for primitive (non-message) types. These types are useful 32 | // for embedding primitives in the `google.protobuf.Any` type and for places 33 | // where we need to distinguish between the absence of a primitive 34 | // typed field and its default value. 35 | 36 | syntax = "proto3"; 37 | 38 | package google.protobuf; 39 | 40 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 41 | option cc_enable_arenas = true; 42 | option go_package = "github.com/golang/protobuf/ptypes/wrappers"; 43 | option java_package = "com.google.protobuf"; 44 | option java_outer_classname = "WrappersProto"; 45 | option java_multiple_files = true; 46 | option objc_class_prefix = "GPB"; 47 | 48 | // Wrapper message for `double`. 49 | // 50 | // The JSON representation for `DoubleValue` is JSON number. 51 | message DoubleValue { 52 | // The double value. 53 | double value = 1; 54 | } 55 | 56 | // Wrapper message for `float`. 57 | // 58 | // The JSON representation for `FloatValue` is JSON number. 59 | message FloatValue { 60 | // The float value. 61 | float value = 1; 62 | } 63 | 64 | // Wrapper message for `int64`. 65 | // 66 | // The JSON representation for `Int64Value` is JSON string. 67 | message Int64Value { 68 | // The int64 value. 69 | int64 value = 1; 70 | } 71 | 72 | // Wrapper message for `uint64`. 73 | // 74 | // The JSON representation for `UInt64Value` is JSON string. 75 | message UInt64Value { 76 | // The uint64 value. 77 | uint64 value = 1; 78 | } 79 | 80 | // Wrapper message for `int32`. 81 | // 82 | // The JSON representation for `Int32Value` is JSON number. 83 | message Int32Value { 84 | // The int32 value. 85 | int32 value = 1; 86 | } 87 | 88 | // Wrapper message for `uint32`. 89 | // 90 | // The JSON representation for `UInt32Value` is JSON number. 91 | message UInt32Value { 92 | // The uint32 value. 93 | uint32 value = 1; 94 | } 95 | 96 | // Wrapper message for `bool`. 97 | // 98 | // The JSON representation for `BoolValue` is JSON `true` and `false`. 99 | message BoolValue { 100 | // The bool value. 101 | bool value = 1; 102 | } 103 | 104 | // Wrapper message for `string`. 105 | // 106 | // The JSON representation for `StringValue` is JSON string. 107 | message StringValue { 108 | // The string value. 109 | string value = 1; 110 | } 111 | 112 | // Wrapper message for `bytes`. 113 | // 114 | // The JSON representation for `BytesValue` is JSON string. 115 | message BytesValue { 116 | // The bytes value. 117 | bytes value = 1; 118 | } 119 | -------------------------------------------------------------------------------- /examples/proto/google/protobuf/wrappers.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Wrappers for primitive (non-message) types. These types are useful 32 | // for embedding primitives in the `google.protobuf.Any` type and for places 33 | // where we need to distinguish between the absence of a primitive 34 | // typed field and its default value. 35 | 36 | syntax = "proto3"; 37 | 38 | package google.protobuf; 39 | 40 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 41 | option cc_enable_arenas = true; 42 | option go_package = "github.com/golang/protobuf/ptypes/wrappers"; 43 | option java_package = "com.google.protobuf"; 44 | option java_outer_classname = "WrappersProto"; 45 | option java_multiple_files = true; 46 | option objc_class_prefix = "GPB"; 47 | 48 | // Wrapper message for `double`. 49 | // 50 | // The JSON representation for `DoubleValue` is JSON number. 51 | message DoubleValue { 52 | // The double value. 53 | double value = 1; 54 | } 55 | 56 | // Wrapper message for `float`. 57 | // 58 | // The JSON representation for `FloatValue` is JSON number. 59 | message FloatValue { 60 | // The float value. 61 | float value = 1; 62 | } 63 | 64 | // Wrapper message for `int64`. 65 | // 66 | // The JSON representation for `Int64Value` is JSON string. 67 | message Int64Value { 68 | // The int64 value. 69 | int64 value = 1; 70 | } 71 | 72 | // Wrapper message for `uint64`. 73 | // 74 | // The JSON representation for `UInt64Value` is JSON string. 75 | message UInt64Value { 76 | // The uint64 value. 77 | uint64 value = 1; 78 | } 79 | 80 | // Wrapper message for `int32`. 81 | // 82 | // The JSON representation for `Int32Value` is JSON number. 83 | message Int32Value { 84 | // The int32 value. 85 | int32 value = 1; 86 | } 87 | 88 | // Wrapper message for `uint32`. 89 | // 90 | // The JSON representation for `UInt32Value` is JSON number. 91 | message UInt32Value { 92 | // The uint32 value. 93 | uint32 value = 1; 94 | } 95 | 96 | // Wrapper message for `bool`. 97 | // 98 | // The JSON representation for `BoolValue` is JSON `true` and `false`. 99 | message BoolValue { 100 | // The bool value. 101 | bool value = 1; 102 | } 103 | 104 | // Wrapper message for `string`. 105 | // 106 | // The JSON representation for `StringValue` is JSON string. 107 | message StringValue { 108 | // The string value. 109 | string value = 1; 110 | } 111 | 112 | // Wrapper message for `bytes`. 113 | // 114 | // The JSON representation for `BytesValue` is JSON string. 115 | message BytesValue { 116 | // The bytes value. 117 | bytes value = 1; 118 | } 119 | -------------------------------------------------------------------------------- /examples/proto/AssetTransfer.proto: -------------------------------------------------------------------------------- 1 | // 2 | // SPDX-License-Identifier: Apache-2.0 3 | // 4 | 5 | // need generator for a sample 6 | 7 | syntax = "proto3"; 8 | package assettransfer; 9 | 10 | import "fabric/contract.proto"; 11 | import "fabric/metadata.proto"; 12 | 13 | // common result message 14 | message ContractResult { 15 | int32 code = 1; 16 | string msg = 2; 17 | } 18 | 19 | 20 | // Money is expressed as the value of the minor currency unit 21 | // eg cent or penny 22 | // and the ISO4217 Code (https://en.wikipedia.org/wiki/ISO_4217) 23 | message Monetary { 24 | uint32 minorvalue = 1; // unsigned 25 | string currency = 2 [(fabric.typeInfo).pattern="[A-Z][A-Z][A-Z]"]; 26 | } 27 | 28 | // This is the full description of the asset that will be held in 29 | // the private data collections, and will be hashed in other locations 30 | // or referred to via uuid 31 | message Asset { 32 | option (fabric.network_serialization).defaultstyle = JSON; 33 | option (fabric.ledger_serialization).defaultstyle = JSON; 34 | 35 | message Key { 36 | string partnumber = 1; 37 | string subtype = 2; 38 | } 39 | 40 | Key uuid = 1; 41 | string title = 2; // brief title eg. "The Mona Lisa" 42 | 43 | enum State { 44 | UNKNOWN = 0; 45 | OWNED = 1; 46 | MARKETED = 2; 47 | } 48 | State state = 3; 49 | } 50 | 51 | // a representation of an owner 52 | message Owner { 53 | option (fabric.network_serialization).defaultstyle = JSON; 54 | option (fabric.ledger_serialization).defaultstyle = JSON; 55 | 56 | message Key { 57 | string uuid = 1; 58 | } 59 | } 60 | 61 | // links the asset and the owner 62 | message Ownership { 63 | Owner.Key owner = 1; 64 | Asset.Key asset = 2; 65 | } 66 | 67 | // --------------------------------------------------------------------- 68 | // Transactions: 69 | // For each there is a Request and Result type 70 | message BuyAgreementTx { 71 | message Request { 72 | string expiryTimestamp = 3 [(fabric.typeInfo).format=DATE_TIME]; 73 | Asset.Key asset = 1 [(fabric.transient)=true]; 74 | Monetary price = 2 [(fabric.transient)=true]; 75 | } 76 | 77 | message Result { 78 | ContractResult result = 1; 79 | } 80 | } 81 | 82 | message ConfirmBuyAgreementTx { 83 | message Request { 84 | Asset.Key asset = 1 [(fabric.transient)=true]; 85 | Monetary price = 2 [(fabric.transient)=true]; 86 | } 87 | 88 | message Result { 89 | ContractResult result = 1; 90 | } 91 | } 92 | 93 | message AssetExistsTx { 94 | message Request { 95 | Asset.Key key = 1; 96 | } 97 | message Result { 98 | ContractResult result =1; 99 | } 100 | } 101 | 102 | message ReadAssetTx { 103 | message Request { 104 | Asset.Key key = 1; 105 | } 106 | message Result { 107 | ContractResult result = 1; 108 | Asset asset = 2; 109 | } 110 | } 111 | 112 | message CreateAssetTx { 113 | message Request{ 114 | Asset.Key key = 1; 115 | string value = 2; 116 | } 117 | message Result { 118 | ContractResult result =1; 119 | } 120 | } 121 | 122 | message UpdateAssetTx { 123 | message Request{ 124 | Asset.Key key = 1; 125 | string value = 2; 126 | } 127 | message Result { 128 | ContractResult result =1; 129 | } 130 | } 131 | 132 | message DeleteAssetTx { 133 | message Request { 134 | Asset.Key key = 1; 135 | } 136 | message Result { 137 | ContractResult result =1; 138 | } 139 | } 140 | 141 | 142 | // API definitions 143 | service AssetTransfer { 144 | rpc propseBuyAgreement(BuyAgreementTx.Request) returns (BuyAgreementTx.Result); 145 | rpc confirmBuyAgreement(ConfirmBuyAgreementTx.Request) returns (ConfirmBuyAgreementTx.Result); 146 | 147 | rpc assetExists (AssetExistsTx.Request) returns (AssetExistsTx.Result); 148 | rpc createAsset (CreateAssetTx.Request) returns (CreateAssetTx.Result); 149 | rpc readAsset (ReadAssetTx.Request) returns (ReadAssetTx.Result); 150 | rpc updateAsset (UpdateAssetTx.Request) returns (UpdateAssetTx.Result); 151 | rpc deleteAsset (DeleteAssetTx.Request) returns (DeleteAssetTx.Result); 152 | } -------------------------------------------------------------------------------- /src/protoc-plugin/google/api/http_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: google.api 2 | // file: google/api/http.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class Http extends jspb.Message { 7 | clearRulesList(): void; 8 | getRulesList(): Array; 9 | setRulesList(value: Array): void; 10 | addRules(value?: HttpRule, index?: number): HttpRule; 11 | 12 | serializeBinary(): Uint8Array; 13 | toObject(includeInstance?: boolean): Http.AsObject; 14 | static toObject(includeInstance: boolean, msg: Http): Http.AsObject; 15 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 16 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 17 | static serializeBinaryToWriter(message: Http, writer: jspb.BinaryWriter): void; 18 | static deserializeBinary(bytes: Uint8Array): Http; 19 | static deserializeBinaryFromReader(message: Http, reader: jspb.BinaryReader): Http; 20 | } 21 | 22 | export namespace Http { 23 | export type AsObject = { 24 | rulesList: Array, 25 | } 26 | } 27 | 28 | export class HttpRule extends jspb.Message { 29 | getSelector(): string; 30 | setSelector(value: string): void; 31 | 32 | hasGet(): boolean; 33 | clearGet(): void; 34 | getGet(): string; 35 | setGet(value: string): void; 36 | 37 | hasPut(): boolean; 38 | clearPut(): void; 39 | getPut(): string; 40 | setPut(value: string): void; 41 | 42 | hasPost(): boolean; 43 | clearPost(): void; 44 | getPost(): string; 45 | setPost(value: string): void; 46 | 47 | hasDelete(): boolean; 48 | clearDelete(): void; 49 | getDelete(): string; 50 | setDelete(value: string): void; 51 | 52 | hasPatch(): boolean; 53 | clearPatch(): void; 54 | getPatch(): string; 55 | setPatch(value: string): void; 56 | 57 | hasCustom(): boolean; 58 | clearCustom(): void; 59 | getCustom(): CustomHttpPattern | undefined; 60 | setCustom(value?: CustomHttpPattern): void; 61 | 62 | getBody(): string; 63 | setBody(value: string): void; 64 | 65 | clearAdditionalBindingsList(): void; 66 | getAdditionalBindingsList(): Array; 67 | setAdditionalBindingsList(value: Array): void; 68 | addAdditionalBindings(value?: HttpRule, index?: number): HttpRule; 69 | 70 | getPatternCase(): HttpRule.PatternCase; 71 | serializeBinary(): Uint8Array; 72 | toObject(includeInstance?: boolean): HttpRule.AsObject; 73 | static toObject(includeInstance: boolean, msg: HttpRule): HttpRule.AsObject; 74 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 75 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 76 | static serializeBinaryToWriter(message: HttpRule, writer: jspb.BinaryWriter): void; 77 | static deserializeBinary(bytes: Uint8Array): HttpRule; 78 | static deserializeBinaryFromReader(message: HttpRule, reader: jspb.BinaryReader): HttpRule; 79 | } 80 | 81 | export namespace HttpRule { 82 | export type AsObject = { 83 | selector: string, 84 | get: string, 85 | put: string, 86 | post: string, 87 | pb_delete: string, 88 | patch: string, 89 | custom?: CustomHttpPattern.AsObject, 90 | body: string, 91 | additionalBindingsList: Array, 92 | } 93 | 94 | export enum PatternCase { 95 | PATTERN_NOT_SET = 0, 96 | GET = 2, 97 | PUT = 3, 98 | POST = 4, 99 | DELETE = 5, 100 | PATCH = 6, 101 | CUSTOM = 8, 102 | } 103 | } 104 | 105 | export class CustomHttpPattern extends jspb.Message { 106 | getKind(): string; 107 | setKind(value: string): void; 108 | 109 | getPath(): string; 110 | setPath(value: string): void; 111 | 112 | serializeBinary(): Uint8Array; 113 | toObject(includeInstance?: boolean): CustomHttpPattern.AsObject; 114 | static toObject(includeInstance: boolean, msg: CustomHttpPattern): CustomHttpPattern.AsObject; 115 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 116 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 117 | static serializeBinaryToWriter(message: CustomHttpPattern, writer: jspb.BinaryWriter): void; 118 | static deserializeBinary(bytes: Uint8Array): CustomHttpPattern; 119 | static deserializeBinaryFromReader(message: CustomHttpPattern, reader: jspb.BinaryReader): CustomHttpPattern; 120 | } 121 | 122 | export namespace CustomHttpPattern { 123 | export type AsObject = { 124 | kind: string, 125 | path: string, 126 | } 127 | } 128 | 129 | -------------------------------------------------------------------------------- /dist/protoc-plugin/google/api/http_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: google.api 2 | // file: google/api/http.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | 6 | export class Http extends jspb.Message { 7 | clearRulesList(): void; 8 | getRulesList(): Array; 9 | setRulesList(value: Array): void; 10 | addRules(value?: HttpRule, index?: number): HttpRule; 11 | 12 | serializeBinary(): Uint8Array; 13 | toObject(includeInstance?: boolean): Http.AsObject; 14 | static toObject(includeInstance: boolean, msg: Http): Http.AsObject; 15 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 16 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 17 | static serializeBinaryToWriter(message: Http, writer: jspb.BinaryWriter): void; 18 | static deserializeBinary(bytes: Uint8Array): Http; 19 | static deserializeBinaryFromReader(message: Http, reader: jspb.BinaryReader): Http; 20 | } 21 | 22 | export namespace Http { 23 | export type AsObject = { 24 | rulesList: Array, 25 | } 26 | } 27 | 28 | export class HttpRule extends jspb.Message { 29 | getSelector(): string; 30 | setSelector(value: string): void; 31 | 32 | hasGet(): boolean; 33 | clearGet(): void; 34 | getGet(): string; 35 | setGet(value: string): void; 36 | 37 | hasPut(): boolean; 38 | clearPut(): void; 39 | getPut(): string; 40 | setPut(value: string): void; 41 | 42 | hasPost(): boolean; 43 | clearPost(): void; 44 | getPost(): string; 45 | setPost(value: string): void; 46 | 47 | hasDelete(): boolean; 48 | clearDelete(): void; 49 | getDelete(): string; 50 | setDelete(value: string): void; 51 | 52 | hasPatch(): boolean; 53 | clearPatch(): void; 54 | getPatch(): string; 55 | setPatch(value: string): void; 56 | 57 | hasCustom(): boolean; 58 | clearCustom(): void; 59 | getCustom(): CustomHttpPattern | undefined; 60 | setCustom(value?: CustomHttpPattern): void; 61 | 62 | getBody(): string; 63 | setBody(value: string): void; 64 | 65 | clearAdditionalBindingsList(): void; 66 | getAdditionalBindingsList(): Array; 67 | setAdditionalBindingsList(value: Array): void; 68 | addAdditionalBindings(value?: HttpRule, index?: number): HttpRule; 69 | 70 | getPatternCase(): HttpRule.PatternCase; 71 | serializeBinary(): Uint8Array; 72 | toObject(includeInstance?: boolean): HttpRule.AsObject; 73 | static toObject(includeInstance: boolean, msg: HttpRule): HttpRule.AsObject; 74 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 75 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 76 | static serializeBinaryToWriter(message: HttpRule, writer: jspb.BinaryWriter): void; 77 | static deserializeBinary(bytes: Uint8Array): HttpRule; 78 | static deserializeBinaryFromReader(message: HttpRule, reader: jspb.BinaryReader): HttpRule; 79 | } 80 | 81 | export namespace HttpRule { 82 | export type AsObject = { 83 | selector: string, 84 | get: string, 85 | put: string, 86 | post: string, 87 | pb_delete: string, 88 | patch: string, 89 | custom?: CustomHttpPattern.AsObject, 90 | body: string, 91 | additionalBindingsList: Array, 92 | } 93 | 94 | export enum PatternCase { 95 | PATTERN_NOT_SET = 0, 96 | GET = 2, 97 | PUT = 3, 98 | POST = 4, 99 | DELETE = 5, 100 | PATCH = 6, 101 | CUSTOM = 8, 102 | } 103 | } 104 | 105 | export class CustomHttpPattern extends jspb.Message { 106 | getKind(): string; 107 | setKind(value: string): void; 108 | 109 | getPath(): string; 110 | setPath(value: string): void; 111 | 112 | serializeBinary(): Uint8Array; 113 | toObject(includeInstance?: boolean): CustomHttpPattern.AsObject; 114 | static toObject(includeInstance: boolean, msg: CustomHttpPattern): CustomHttpPattern.AsObject; 115 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 116 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 117 | static serializeBinaryToWriter(message: CustomHttpPattern, writer: jspb.BinaryWriter): void; 118 | static deserializeBinary(bytes: Uint8Array): CustomHttpPattern; 119 | static deserializeBinaryFromReader(message: CustomHttpPattern, reader: jspb.BinaryReader): CustomHttpPattern; 120 | } 121 | 122 | export namespace CustomHttpPattern { 123 | export type AsObject = { 124 | kind: string, 125 | path: string, 126 | } 127 | } 128 | 129 | -------------------------------------------------------------------------------- /src/protos/google/protobuf/duration.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option cc_enable_arenas = true; 37 | option go_package = "github.com/golang/protobuf/ptypes/duration"; 38 | option java_package = "com.google.protobuf"; 39 | option java_outer_classname = "DurationProto"; 40 | option java_multiple_files = true; 41 | option objc_class_prefix = "GPB"; 42 | 43 | // A Duration represents a signed, fixed-length span of time represented 44 | // as a count of seconds and fractions of seconds at nanosecond 45 | // resolution. It is independent of any calendar and concepts like "day" 46 | // or "month". It is related to Timestamp in that the difference between 47 | // two Timestamp values is a Duration and it can be added or subtracted 48 | // from a Timestamp. Range is approximately +-10,000 years. 49 | // 50 | // Example 1: Compute Duration from two Timestamps in pseudo code. 51 | // 52 | // Timestamp start = ...; 53 | // Timestamp end = ...; 54 | // Duration duration = ...; 55 | // 56 | // duration.seconds = end.seconds - start.seconds; 57 | // duration.nanos = end.nanos - start.nanos; 58 | // 59 | // if (duration.seconds < 0 && duration.nanos > 0) { 60 | // duration.seconds += 1; 61 | // duration.nanos -= 1000000000; 62 | // } else if (durations.seconds > 0 && duration.nanos < 0) { 63 | // duration.seconds -= 1; 64 | // duration.nanos += 1000000000; 65 | // } 66 | // 67 | // Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. 68 | // 69 | // Timestamp start = ...; 70 | // Duration duration = ...; 71 | // Timestamp end = ...; 72 | // 73 | // end.seconds = start.seconds + duration.seconds; 74 | // end.nanos = start.nanos + duration.nanos; 75 | // 76 | // if (end.nanos < 0) { 77 | // end.seconds -= 1; 78 | // end.nanos += 1000000000; 79 | // } else if (end.nanos >= 1000000000) { 80 | // end.seconds += 1; 81 | // end.nanos -= 1000000000; 82 | // } 83 | // 84 | // Example 3: Compute Duration from datetime.timedelta in Python. 85 | // 86 | // td = datetime.timedelta(days=3, minutes=10) 87 | // duration = Duration() 88 | // duration.FromTimedelta(td) 89 | // 90 | // 91 | message Duration { 92 | 93 | // Signed seconds of the span of time. Must be from -315,576,000,000 94 | // to +315,576,000,000 inclusive. 95 | int64 seconds = 1; 96 | 97 | // Signed fractions of a second at nanosecond resolution of the span 98 | // of time. Durations less than one second are represented with a 0 99 | // `seconds` field and a positive or negative `nanos` field. For durations 100 | // of one second or more, a non-zero value for the `nanos` field must be 101 | // of the same sign as the `seconds` field. Must be from -999,999,999 102 | // to +999,999,999 inclusive. 103 | int32 nanos = 2; 104 | } 105 | -------------------------------------------------------------------------------- /examples/proto/google/protobuf/duration.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option cc_enable_arenas = true; 37 | option go_package = "github.com/golang/protobuf/ptypes/duration"; 38 | option java_package = "com.google.protobuf"; 39 | option java_outer_classname = "DurationProto"; 40 | option java_multiple_files = true; 41 | option objc_class_prefix = "GPB"; 42 | 43 | // A Duration represents a signed, fixed-length span of time represented 44 | // as a count of seconds and fractions of seconds at nanosecond 45 | // resolution. It is independent of any calendar and concepts like "day" 46 | // or "month". It is related to Timestamp in that the difference between 47 | // two Timestamp values is a Duration and it can be added or subtracted 48 | // from a Timestamp. Range is approximately +-10,000 years. 49 | // 50 | // Example 1: Compute Duration from two Timestamps in pseudo code. 51 | // 52 | // Timestamp start = ...; 53 | // Timestamp end = ...; 54 | // Duration duration = ...; 55 | // 56 | // duration.seconds = end.seconds - start.seconds; 57 | // duration.nanos = end.nanos - start.nanos; 58 | // 59 | // if (duration.seconds < 0 && duration.nanos > 0) { 60 | // duration.seconds += 1; 61 | // duration.nanos -= 1000000000; 62 | // } else if (durations.seconds > 0 && duration.nanos < 0) { 63 | // duration.seconds -= 1; 64 | // duration.nanos += 1000000000; 65 | // } 66 | // 67 | // Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. 68 | // 69 | // Timestamp start = ...; 70 | // Duration duration = ...; 71 | // Timestamp end = ...; 72 | // 73 | // end.seconds = start.seconds + duration.seconds; 74 | // end.nanos = start.nanos + duration.nanos; 75 | // 76 | // if (end.nanos < 0) { 77 | // end.seconds -= 1; 78 | // end.nanos += 1000000000; 79 | // } else if (end.nanos >= 1000000000) { 80 | // end.seconds += 1; 81 | // end.nanos -= 1000000000; 82 | // } 83 | // 84 | // Example 3: Compute Duration from datetime.timedelta in Python. 85 | // 86 | // td = datetime.timedelta(days=3, minutes=10) 87 | // duration = Duration() 88 | // duration.FromTimedelta(td) 89 | // 90 | // 91 | message Duration { 92 | 93 | // Signed seconds of the span of time. Must be from -315,576,000,000 94 | // to +315,576,000,000 inclusive. 95 | int64 seconds = 1; 96 | 97 | // Signed fractions of a second at nanosecond resolution of the span 98 | // of time. Durations less than one second are represented with a 0 99 | // `seconds` field and a positive or negative `nanos` field. For durations 100 | // of one second or more, a non-zero value for the `nanos` field must be 101 | // of the same sign as the `seconds` field. Must be from -999,999,999 102 | // to +999,999,999 inclusive. 103 | int32 nanos = 2; 104 | } 105 | -------------------------------------------------------------------------------- /dist/visitor.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Convert the contents of a {@link ModelManager} instance to a set of JSON 3 | * Schema v4 files - one per concrete asset and transaction type. 4 | * Set a fileWriter property (instance of {@link FileWriter}) on the parameters 5 | * object to control where the generated code is written to disk. 6 | * @private 7 | * @class 8 | * @memberof module:concerto-tools 9 | */ 10 | export default class MetadataVisitor { 11 | /** 12 | * Visitor design pattern 13 | * @param {Object} thing - the object being visited 14 | * @param {Object} parameters - the parameter 15 | * @return {Object} the result of visiting or null 16 | * @private 17 | */ 18 | visit(thing: any, parameters: any): any; 19 | /** 20 | * Visitor design pattern 21 | * @param {ModelManager} modelManager - the object being visited 22 | * @param {Object} parameters - the parameter 23 | * @return {Object} the result of visiting or null 24 | * @private 25 | */ 26 | visitModelManager(modelManager: any, parameters: any): any; 27 | /** 28 | * Visitor design pattern 29 | * @param {ModelFile} modelFile - the object being visited 30 | * @param {Object} parameters - the parameter 31 | * @return {Object} the result of visiting or null 32 | * @private 33 | */ 34 | visitModelFile(modelFile: any, parameters: any): any[]; 35 | /** 36 | * Visitor design pattern 37 | * @param {AssetDeclaration} assetDeclaration - the object being visited 38 | * @param {Object} parameters - the parameter 39 | * @return {Object} the result of visiting or null 40 | * @private 41 | */ 42 | visitAssetDeclaration(assetDeclaration: any, parameters: any): any; 43 | /** 44 | * Visitor design pattern 45 | * @param {TransactionDeclaration} transactionDeclaration - the object being visited 46 | * @param {Object} parameters - the parameter 47 | * @return {Object} the result of visiting or null 48 | * @private 49 | */ 50 | visitTransactionDeclaration(transactionDeclaration: any, parameters: any): any; 51 | /** 52 | * Visitor design pattern 53 | * @param {ConceptDeclaration} conceptDeclaration - the object being visited 54 | * @param {Object} parameters - the parameter 55 | * @return {Object} the result of visiting or null 56 | * @private 57 | */ 58 | visitConceptDeclaration(conceptDeclaration: any, parameters: any): any; 59 | /** 60 | * Visitor design pattern 61 | * @param {ClassDeclaration} classDeclaration - the object being visited 62 | * @param {Object} parameters - the parameter 63 | * @return {Object} the result of visiting or null 64 | * @private 65 | */ 66 | visitClassDeclaration(classDeclaration: any, parameters: any): any; 67 | /** 68 | * Visitor design pattern 69 | * @param {ClassDeclaration} classDeclaration - the object being visited 70 | * @param {Object} parameters - the parameter 71 | * @param {Object} jsonSchema - the base JSON Schema object to use 72 | * @return {Object} the result of visiting or null 73 | * @private 74 | */ 75 | visitClassDeclarationCommon(classDeclaration: any, parameters: any, jsonSchema: any): any; 76 | /** 77 | * Visitor design pattern 78 | * @param {Field} field - the object being visited 79 | * @param {Object} parameters - the parameter 80 | * @return {Object} the result of visiting or null 81 | * @private 82 | */ 83 | visitField(field: any, parameters: any): any; 84 | /** 85 | * Visitor design pattern 86 | * @param {EnumDeclaration} enumDeclaration - the object being visited 87 | * @param {Object} parameters - the parameter 88 | * @return {Object} the result of visiting or null 89 | * @private 90 | */ 91 | visitEnumDeclaration(enumDeclaration: any, parameters: any): { 92 | enum: any[]; 93 | }; 94 | /** 95 | * Visitor design pattern 96 | * @param {EnumValueDeclaration} enumValueDeclaration - the object being visited 97 | * @param {Object} parameters - the parameter 98 | * @return {Object} the result of visiting or null 99 | * @private 100 | */ 101 | visitEnumValueDeclaration(enumValueDeclaration: any, parameters: any): any; 102 | /** 103 | * Visitor design pattern 104 | * @param {RelationshipDeclaration} relationshipDeclaration - the object being visited 105 | * @param {Object} parameters - the parameter 106 | * @return {Object} the result of visiting or null 107 | * @private 108 | */ 109 | visitRelationshipDeclaration(relationshipDeclaration: any, parameters: any): any; 110 | } 111 | -------------------------------------------------------------------------------- /src/protos/google/protobuf/timestamp.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option cc_enable_arenas = true; 37 | option go_package = "github.com/golang/protobuf/ptypes/timestamp"; 38 | option java_package = "com.google.protobuf"; 39 | option java_outer_classname = "TimestampProto"; 40 | option java_multiple_files = true; 41 | option objc_class_prefix = "GPB"; 42 | 43 | // A Timestamp represents a point in time independent of any time zone 44 | // or calendar, represented as seconds and fractions of seconds at 45 | // nanosecond resolution in UTC Epoch time. It is encoded using the 46 | // Proleptic Gregorian Calendar which extends the Gregorian calendar 47 | // backwards to year one. It is encoded assuming all minutes are 60 48 | // seconds long, i.e. leap seconds are "smeared" so that no leap second 49 | // table is needed for interpretation. Range is from 50 | // 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. 51 | // By restricting to that range, we ensure that we can convert to 52 | // and from RFC 3339 date strings. 53 | // See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt). 54 | // 55 | // Example 1: Compute Timestamp from POSIX `time()`. 56 | // 57 | // Timestamp timestamp; 58 | // timestamp.set_seconds(time(NULL)); 59 | // timestamp.set_nanos(0); 60 | // 61 | // Example 2: Compute Timestamp from POSIX `gettimeofday()`. 62 | // 63 | // struct timeval tv; 64 | // gettimeofday(&tv, NULL); 65 | // 66 | // Timestamp timestamp; 67 | // timestamp.set_seconds(tv.tv_sec); 68 | // timestamp.set_nanos(tv.tv_usec * 1000); 69 | // 70 | // Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. 71 | // 72 | // FILETIME ft; 73 | // GetSystemTimeAsFileTime(&ft); 74 | // UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; 75 | // 76 | // // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z 77 | // // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. 78 | // Timestamp timestamp; 79 | // timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); 80 | // timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); 81 | // 82 | // Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. 83 | // 84 | // long millis = System.currentTimeMillis(); 85 | // 86 | // Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) 87 | // .setNanos((int) ((millis % 1000) * 1000000)).build(); 88 | // 89 | // 90 | // Example 5: Compute Timestamp from current time in Python. 91 | // 92 | // timestamp = Timestamp() 93 | // timestamp.GetCurrentTime() 94 | // 95 | // 96 | message Timestamp { 97 | 98 | // Represents seconds of UTC time since Unix epoch 99 | // 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to 100 | // 9999-12-31T23:59:59Z inclusive. 101 | int64 seconds = 1; 102 | 103 | // Non-negative fractions of a second at nanosecond resolution. Negative 104 | // second values with fractions must still have non-negative nanos values 105 | // that count forward in time. Must be from 0 to 999,999,999 106 | // inclusive. 107 | int32 nanos = 2; 108 | } 109 | -------------------------------------------------------------------------------- /examples/proto/google/protobuf/timestamp.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option cc_enable_arenas = true; 37 | option go_package = "github.com/golang/protobuf/ptypes/timestamp"; 38 | option java_package = "com.google.protobuf"; 39 | option java_outer_classname = "TimestampProto"; 40 | option java_multiple_files = true; 41 | option objc_class_prefix = "GPB"; 42 | 43 | // A Timestamp represents a point in time independent of any time zone 44 | // or calendar, represented as seconds and fractions of seconds at 45 | // nanosecond resolution in UTC Epoch time. It is encoded using the 46 | // Proleptic Gregorian Calendar which extends the Gregorian calendar 47 | // backwards to year one. It is encoded assuming all minutes are 60 48 | // seconds long, i.e. leap seconds are "smeared" so that no leap second 49 | // table is needed for interpretation. Range is from 50 | // 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. 51 | // By restricting to that range, we ensure that we can convert to 52 | // and from RFC 3339 date strings. 53 | // See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt). 54 | // 55 | // Example 1: Compute Timestamp from POSIX `time()`. 56 | // 57 | // Timestamp timestamp; 58 | // timestamp.set_seconds(time(NULL)); 59 | // timestamp.set_nanos(0); 60 | // 61 | // Example 2: Compute Timestamp from POSIX `gettimeofday()`. 62 | // 63 | // struct timeval tv; 64 | // gettimeofday(&tv, NULL); 65 | // 66 | // Timestamp timestamp; 67 | // timestamp.set_seconds(tv.tv_sec); 68 | // timestamp.set_nanos(tv.tv_usec * 1000); 69 | // 70 | // Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. 71 | // 72 | // FILETIME ft; 73 | // GetSystemTimeAsFileTime(&ft); 74 | // UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; 75 | // 76 | // // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z 77 | // // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. 78 | // Timestamp timestamp; 79 | // timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); 80 | // timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); 81 | // 82 | // Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. 83 | // 84 | // long millis = System.currentTimeMillis(); 85 | // 86 | // Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) 87 | // .setNanos((int) ((millis % 1000) * 1000000)).build(); 88 | // 89 | // 90 | // Example 5: Compute Timestamp from current time in Python. 91 | // 92 | // timestamp = Timestamp() 93 | // timestamp.GetCurrentTime() 94 | // 95 | // 96 | message Timestamp { 97 | 98 | // Represents seconds of UTC time since Unix epoch 99 | // 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to 100 | // 9999-12-31T23:59:59Z inclusive. 101 | int64 seconds = 1; 102 | 103 | // Non-negative fractions of a second at nanosecond resolution. Negative 104 | // second values with fractions must still have non-negative nanos values 105 | // that count forward in time. Must be from 0 to 999,999,999 106 | // inclusive. 107 | int32 nanos = 2; 108 | } 109 | -------------------------------------------------------------------------------- /dist/protoc-plugin/protoc-gen-fabart.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"protoc-gen-fabart.js","sourceRoot":"","sources":["../../src/protoc-plugin/protoc-gen-fabart.ts"],"names":[],"mappings":";;;AAGA,OAAO,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;AAC7C,mCAA6B;AAE7B,MAAM,KAAK,GAAG,EAAE,CAAC;AACjB,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,SAAS,GAAG,EAAE,CAAC;AAErB,SAAS,YAAY,CAAC,GAAW;IAC/B,IAAI,GAAG,EAAE;QACP,OAAO,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;KAChD;SAAM;QACL,OAAO,EAAE,CAAC;KACX;AACH,CAAC;AAED,SAAS,YAAY,CAAC,GAAW;IAC/B,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC3C,CAAC;AAuBD,uCAAuC;AACvC,oDAAoD;AACpD,0FAA0F;AAC1F,SAAS,WAAW,CAAC,KAAK,EAAE,GAAG;IAE7B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACrB,IAAI,QAAQ,GAAG,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;IAGvD,MAAM,MAAM,GAAW,EAAE,CAAC;IAC1B,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IACvE,QAAQ,KAAK,CAAC,IAAI,EAAE;QAClB,KAAK,CAAC;YACJ,MAAM,CAAC,IAAI,GAAG,SAAS,CAAC;YACxB,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC;YACxB,MAAM;QACR,KAAK,CAAC;YACJ,MAAM,CAAC,IAAI,GAAG,SAAS,CAAC;YACxB,MAAM;QACR,KAAK,CAAC;YACJ,MAAM,CAAC,IAAI,GAAG,QAAQ,CAAC;YACvB,IAAI,QAAQ,EAAE;gBACZ,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,EAAE;oBACtC,QAAQ,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE;wBACrC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,WAAW,CAAC;wBACpC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;qBAChC;iBACF;qBAAM,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE;oBACzC,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;iBACjD;aAEF;YACD,MAAM;QACR,KAAK,EAAE;YACL,MAAM,CAAC,IAAI,GAAG,SAAS,CAAC;YACxB,MAAM;QACR;YACE,MAAM,CAAC,IAAI,GAAG,wBAAwB,GAAG,EAAE,CAAC;YAC5C,MAAM;KACT;IAED,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AACpC,CAAC;AAED,oBAAoB;AACpB,SAAS,YAAY,CAAC,eAAe,EAAE,MAAM,GAAG,EAAE;IAEhD,eAAe,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE;QACtC,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC;QAElC,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;YAC9C,QAAQ,CAAC,GAAG,MAAM,GAAG,QAAQ,EAAE,CAAC,GAAG,WAAW,CAAC;SAChD;aAAM,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;YACpD,SAAS,CAAC,GAAG,MAAM,GAAG,QAAQ,EAAE,CAAC,GAAG,WAAW,CAAC;SACjD;aAAM;YACL,KAAK,CAAC,GAAG,MAAM,GAAG,QAAQ,EAAE,CAAC,GAAG,WAAW,CAAC;SAC7C;QAED,6CAA6C;QAC7C,IAAI,WAAW,CAAC,cAAc,EAAE;YAC9B,YAAY,CAAC,WAAW,CAAC,cAAc,EAAE,GAAG,QAAQ,GAAG,CAAC,CAAC;SAC1D;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,QAAQ,CAAC,KAAK;IACrB,IAAI;QACF,MAAM,QAAQ,GAAG;YACf,OAAO,EAAE,0FAA0F;YACnG,UAAU,EAAE;gBACV,OAAO,EAAE,EAAE;aACZ;YACD,SAAS,EAAE,EAAE;YACb,IAAI,EAAE;gBACJ,KAAK,EAAE,KAAK,CAAC,UAAU;gBACvB,OAAO,EAAE,EAAE;aACZ;SACF,CAAC;QAEF,wBAAwB;QACxB,YAAY,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;QACpC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACxB,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACzB,iBAAiB;QACjB,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAEpC,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG;gBACjC,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,YAAY,EAAE,EAAE;aACjB,CAAC;YAEF,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;gBACpC,MAAM,IAAI,GAAS,EAAE,CAAC;gBACtB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;gBACxB,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;gBACd,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;gBACrB,OAAO,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;gBACpC,IAAI,MAAM,CAAC,UAAU,EAAE;oBACrB,IAAI,cAAc,GAAG,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;oBACrD,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;oBAC9B,MAAM,UAAU,GAAG,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;oBAC5D,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;iBAC7G;gBAED,MAAM,QAAQ,GAAG,YAAY,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;gBAChD,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;oBACvD,oBAAoB;oBACpB,qDAAqD;oBACrD,OAAO,WAAW,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;gBAElD,CAAC,CAAC,CAAC;gBAEH,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC3D,CAAC,CAAC,CAAC;QAEL,CAAC,CAAC,CAAC;QAEH,oCAAoC;QACpC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YACnF,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YAEtB,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;gBACvC,KAAK,EAAE,IAAI,CAAC,IAAI;gBAChB,KAAK,EAAE,IAAI,CAAC,IAAI;gBAChB,WAAW,EAAE,EAAE;gBACf,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE,EAAE;aACf,CAAC;YAEF,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;gBAC3B,MAAM,OAAO,GAAG,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;gBACzC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;YACvG,CAAC,CAAC,CAAC;QAEL,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,KAAK,CAAC,cAAc,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC;QACjD,IAAI,IAAI,GAAG;YACT,IAAI,EAAE,GAAG,KAAK,CAAC,UAAU,UAAU;YACnC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;SAC3C,CAAC;QAEF,OAAO,CAAC,KAAK,CAAC,wBAAwB,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC;QAC1D,OAAO,IAAI,CAAC;KAEb;IACD,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACjB,MAAM,CAAC,CAAC;KACT;AAEH,CAAC;AAGD,IAAI,eAAM,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC;KACvB,IAAI,CAAC,GAAG,EAAE;IACT,iDAAiD;IACjD,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AAC7B,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC"} -------------------------------------------------------------------------------- /src/protos/google/protobuf/any.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option go_package = "github.com/golang/protobuf/ptypes/any"; 37 | option java_package = "com.google.protobuf"; 38 | option java_outer_classname = "AnyProto"; 39 | option java_multiple_files = true; 40 | option objc_class_prefix = "GPB"; 41 | 42 | // `Any` contains an arbitrary serialized protocol buffer message along with a 43 | // URL that describes the type of the serialized message. 44 | // 45 | // Protobuf library provides support to pack/unpack Any values in the form 46 | // of utility functions or additional generated methods of the Any type. 47 | // 48 | // Example 1: Pack and unpack a message in C++. 49 | // 50 | // Foo foo = ...; 51 | // Any any; 52 | // any.PackFrom(foo); 53 | // ... 54 | // if (any.UnpackTo(&foo)) { 55 | // ... 56 | // } 57 | // 58 | // Example 2: Pack and unpack a message in Java. 59 | // 60 | // Foo foo = ...; 61 | // Any any = Any.pack(foo); 62 | // ... 63 | // if (any.is(Foo.class)) { 64 | // foo = any.unpack(Foo.class); 65 | // } 66 | // 67 | // Example 3: Pack and unpack a message in Python. 68 | // 69 | // foo = Foo(...) 70 | // any = Any() 71 | // any.Pack(foo) 72 | // ... 73 | // if any.Is(Foo.DESCRIPTOR): 74 | // any.Unpack(foo) 75 | // ... 76 | // 77 | // The pack methods provided by protobuf library will by default use 78 | // 'type.googleapis.com/full.type.name' as the type URL and the unpack 79 | // methods only use the fully qualified type name after the last '/' 80 | // in the type URL, for example "foo.bar.com/x/y.z" will yield type 81 | // name "y.z". 82 | // 83 | // 84 | // JSON 85 | // ==== 86 | // The JSON representation of an `Any` value uses the regular 87 | // representation of the deserialized, embedded message, with an 88 | // additional field `@type` which contains the type URL. Example: 89 | // 90 | // package google.profile; 91 | // message Person { 92 | // string first_name = 1; 93 | // string last_name = 2; 94 | // } 95 | // 96 | // { 97 | // "@type": "type.googleapis.com/google.profile.Person", 98 | // "firstName": , 99 | // "lastName": 100 | // } 101 | // 102 | // If the embedded message type is well-known and has a custom JSON 103 | // representation, that representation will be embedded adding a field 104 | // `value` which holds the custom JSON in addition to the `@type` 105 | // field. Example (for message [google.protobuf.Duration][]): 106 | // 107 | // { 108 | // "@type": "type.googleapis.com/google.protobuf.Duration", 109 | // "value": "1.212s" 110 | // } 111 | // 112 | message Any { 113 | // A URL/resource name whose content describes the type of the 114 | // serialized protocol buffer message. 115 | // 116 | // For URLs which use the scheme `http`, `https`, or no scheme, the 117 | // following restrictions and interpretations apply: 118 | // 119 | // * If no scheme is provided, `https` is assumed. 120 | // * The last segment of the URL's path must represent the fully 121 | // qualified name of the type (as in `path/google.protobuf.Duration`). 122 | // The name should be in a canonical form (e.g., leading "." is 123 | // not accepted). 124 | // * An HTTP GET on the URL must yield a [google.protobuf.Type][] 125 | // value in binary format, or produce an error. 126 | // * Applications are allowed to cache lookup results based on the 127 | // URL, or have them precompiled into a binary to avoid any 128 | // lookup. Therefore, binary compatibility needs to be preserved 129 | // on changes to types. (Use versioned type names to manage 130 | // breaking changes.) 131 | // 132 | // Schemes other than `http`, `https` (or the empty scheme) might be 133 | // used with implementation specific semantics. 134 | // 135 | string type_url = 1; 136 | 137 | // Must be a valid serialized protocol buffer of the above specified type. 138 | bytes value = 2; 139 | } 140 | -------------------------------------------------------------------------------- /examples/proto/google/protobuf/any.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option go_package = "github.com/golang/protobuf/ptypes/any"; 37 | option java_package = "com.google.protobuf"; 38 | option java_outer_classname = "AnyProto"; 39 | option java_multiple_files = true; 40 | option objc_class_prefix = "GPB"; 41 | 42 | // `Any` contains an arbitrary serialized protocol buffer message along with a 43 | // URL that describes the type of the serialized message. 44 | // 45 | // Protobuf library provides support to pack/unpack Any values in the form 46 | // of utility functions or additional generated methods of the Any type. 47 | // 48 | // Example 1: Pack and unpack a message in C++. 49 | // 50 | // Foo foo = ...; 51 | // Any any; 52 | // any.PackFrom(foo); 53 | // ... 54 | // if (any.UnpackTo(&foo)) { 55 | // ... 56 | // } 57 | // 58 | // Example 2: Pack and unpack a message in Java. 59 | // 60 | // Foo foo = ...; 61 | // Any any = Any.pack(foo); 62 | // ... 63 | // if (any.is(Foo.class)) { 64 | // foo = any.unpack(Foo.class); 65 | // } 66 | // 67 | // Example 3: Pack and unpack a message in Python. 68 | // 69 | // foo = Foo(...) 70 | // any = Any() 71 | // any.Pack(foo) 72 | // ... 73 | // if any.Is(Foo.DESCRIPTOR): 74 | // any.Unpack(foo) 75 | // ... 76 | // 77 | // The pack methods provided by protobuf library will by default use 78 | // 'type.googleapis.com/full.type.name' as the type URL and the unpack 79 | // methods only use the fully qualified type name after the last '/' 80 | // in the type URL, for example "foo.bar.com/x/y.z" will yield type 81 | // name "y.z". 82 | // 83 | // 84 | // JSON 85 | // ==== 86 | // The JSON representation of an `Any` value uses the regular 87 | // representation of the deserialized, embedded message, with an 88 | // additional field `@type` which contains the type URL. Example: 89 | // 90 | // package google.profile; 91 | // message Person { 92 | // string first_name = 1; 93 | // string last_name = 2; 94 | // } 95 | // 96 | // { 97 | // "@type": "type.googleapis.com/google.profile.Person", 98 | // "firstName": , 99 | // "lastName": 100 | // } 101 | // 102 | // If the embedded message type is well-known and has a custom JSON 103 | // representation, that representation will be embedded adding a field 104 | // `value` which holds the custom JSON in addition to the `@type` 105 | // field. Example (for message [google.protobuf.Duration][]): 106 | // 107 | // { 108 | // "@type": "type.googleapis.com/google.protobuf.Duration", 109 | // "value": "1.212s" 110 | // } 111 | // 112 | message Any { 113 | // A URL/resource name whose content describes the type of the 114 | // serialized protocol buffer message. 115 | // 116 | // For URLs which use the scheme `http`, `https`, or no scheme, the 117 | // following restrictions and interpretations apply: 118 | // 119 | // * If no scheme is provided, `https` is assumed. 120 | // * The last segment of the URL's path must represent the fully 121 | // qualified name of the type (as in `path/google.protobuf.Duration`). 122 | // The name should be in a canonical form (e.g., leading "." is 123 | // not accepted). 124 | // * An HTTP GET on the URL must yield a [google.protobuf.Type][] 125 | // value in binary format, or produce an error. 126 | // * Applications are allowed to cache lookup results based on the 127 | // URL, or have them precompiled into a binary to avoid any 128 | // lookup. Therefore, binary compatibility needs to be preserved 129 | // on changes to types. (Use versioned type names to manage 130 | // breaking changes.) 131 | // 132 | // Schemes other than `http`, `https` (or the empty scheme) might be 133 | // used with implementation specific semantics. 134 | // 135 | string type_url = 1; 136 | 137 | // Must be a valid serialized protocol buffer of the above specified type. 138 | bytes value = 2; 139 | } 140 | -------------------------------------------------------------------------------- /src/protoc-plugin/protoc-gen-fabart.ts: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | 3 | // Create a simple log of incoming CodeGeneratorRequest messages 4 | console.error(`==> Processing the protobug`); 5 | import Plugin from './index'; 6 | 7 | const types = {}; 8 | const requests = {}; 9 | const responses = {}; 10 | 11 | function _lastElement(str: string): string { 12 | if (str) { 13 | return str.substring(str.lastIndexOf('.') + 1); 14 | } else { 15 | return ''; 16 | } 17 | } 18 | 19 | function _getTypeName(str: string): string{ 20 | return str.split('.').slice(2).join('.'); 21 | } 22 | 23 | // Simple typescript definitations of objects 24 | // ported from JavaScript 25 | interface Schema { 26 | type?: string; 27 | format?: string; 28 | pattern?: string; 29 | $ref?: string; 30 | } 31 | 32 | interface TxFn { 33 | name?: string; 34 | tag?: string[]; 35 | parameters?: Schema[]; 36 | returns?: TypeDefn; 37 | } 38 | 39 | interface TypeDefn { 40 | name?: string; 41 | schema?: Schema; 42 | } 43 | 44 | // map a field to the schema definition 45 | // integers here are the protobuf typecodes liste at 46 | // https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/type.proto 47 | function mapToSchema(field, fqn): TypeDefn { 48 | 49 | console.error(field); 50 | let typeinfo = field.options && field.options.typeinfo; 51 | 52 | 53 | const schema: Schema = {}; 54 | const typename = field.name.substring(field.name.lastIndexOf('.') + 1); 55 | switch (field.type) { 56 | case 5: 57 | schema.type = 'integer'; 58 | schema.format = 'int32'; 59 | break; 60 | case 8: 61 | schema.type = 'boolean'; 62 | break; 63 | case 9: 64 | schema.type = 'string'; 65 | if (typeinfo) { 66 | if (field.options.typeinfo.format != 0) { 67 | switch (field.options.typeinfo.format) { 68 | case 1: schema.format = "data-time"; 69 | case 2: schema.format = "byte"; 70 | } 71 | } else if (field.options.typeinfo.pattern) { 72 | schema.pattern = field.options.typeinfo.pattern; 73 | } 74 | 75 | } 76 | break; 77 | case 13: 78 | schema.type = 'integer'; 79 | break; 80 | default: 81 | schema.$ref = `#/components/schemas/${fqn}`; 82 | break; 83 | } 84 | 85 | return { name: typename, schema }; 86 | } 87 | 88 | // process the types 89 | function processTypes(messageTypeList, prefix = '') { 90 | 91 | messageTypeList.forEach((messagetype) => { 92 | const typeName = messagetype.name; 93 | 94 | if (typeName.toLowerCase().includes('request')) { 95 | requests[`${prefix}${typeName}`] = messagetype; 96 | } else if (typeName.toLowerCase().includes('result')) { 97 | responses[`${prefix}${typeName}`] = messagetype; 98 | } else { 99 | types[`${prefix}${typeName}`] = messagetype; 100 | } 101 | 102 | // handle the nested types, typically the key 103 | if (messagetype.nestedTypeList) { 104 | processTypes(messagetype.nestedTypeList, `${typeName}.`); 105 | } 106 | }); 107 | } 108 | 109 | function callback(proto) { 110 | try { 111 | const metadata = { 112 | $schema: 'https://hyperledger.github.io/fabric-chaincode-node/release-2.0/api/contract-schema.json', 113 | components: { 114 | schemas: {} 115 | }, 116 | contracts: {}, 117 | info: { 118 | title: proto.pb_package, 119 | version: '', 120 | }, 121 | }; 122 | 123 | // load the messageTypes 124 | processTypes(proto.messageTypeList); 125 | console.error(types); 126 | console.error(requests); 127 | console.error(responses); 128 | // main contracts 129 | proto.serviceList.forEach((service) => { 130 | 131 | metadata.contracts[service.name] = { 132 | name: service.name, 133 | transactions: [], 134 | }; 135 | 136 | service.methodList.forEach((method) => { 137 | const txFn: TxFn = {}; 138 | txFn.name = method.name; 139 | txFn.tag = []; 140 | txFn.parameters = []; 141 | console.error(`TxFn: ${txFn.name}`); 142 | if (method.outputType) { 143 | let returnTypeName = _getTypeName(method.outputType); 144 | console.error(returnTypeName); 145 | const returnType = (responses[returnTypeName].fieldList[0]); 146 | txFn.returns = mapToSchema(returnType, method.outputType.substring(method.outputType.lastIndexOf('.') + 1)); 147 | } 148 | 149 | const typeName = _getTypeName(method.inputType); 150 | txFn.parameters = requests[typeName].fieldList.map((f) => { 151 | // console.error(f); 152 | // let p = { name: f.name, schema: mapToSchema(f) }; 153 | return mapToSchema(f, _lastElement(f.typeName)); 154 | 155 | }); 156 | 157 | metadata.contracts[service.name].transactions.push(txFn); 158 | }); 159 | 160 | }); 161 | 162 | // don't want to include the request 163 | Object.keys(types).filter((t) => !t.toLowerCase().includes('request')).forEach((t) => { 164 | const type = types[t]; 165 | 166 | metadata.components.schemas[type.name] = { 167 | title: type.name, 168 | '$id': type.name, 169 | description: '', 170 | type: 'object', 171 | properties: {}, 172 | }; 173 | 174 | type.fieldList.forEach((f) => { 175 | const pgkName = _lastElement(f.typeName); 176 | metadata.components.schemas[type.name].properties[f.name] = mapToSchema(f, _lastElement(f.typeName)); 177 | }); 178 | 179 | }); 180 | 181 | console.error(`Working on ${proto.pb_package}.`); 182 | let data = { 183 | name: `${proto.pb_package}-md.json`, 184 | content: JSON.stringify(metadata, null, 2), 185 | }; 186 | 187 | console.error(`Finished working on ${proto.pb_package}`); 188 | return data; 189 | 190 | } 191 | catch (e) { 192 | console.error(e); 193 | throw e; 194 | } 195 | 196 | } 197 | 198 | 199 | new Plugin().run(callback) 200 | .then(() => { 201 | // I use error, because stdout is used for plugin 202 | console.error('Complete.'); 203 | }).catch(e => console.error(e)); 204 | -------------------------------------------------------------------------------- /src/protoc-plugin/google/protobuf/compiler/plugin_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: google.protobuf.compiler 2 | // file: google/protobuf/compiler/plugin.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as google_protobuf_descriptor_pb from "google-protobuf/google/protobuf/descriptor_pb"; 6 | 7 | export class Version extends jspb.Message { 8 | hasMajor(): boolean; 9 | clearMajor(): void; 10 | getMajor(): number | undefined; 11 | setMajor(value: number): void; 12 | 13 | hasMinor(): boolean; 14 | clearMinor(): void; 15 | getMinor(): number | undefined; 16 | setMinor(value: number): void; 17 | 18 | hasPatch(): boolean; 19 | clearPatch(): void; 20 | getPatch(): number | undefined; 21 | setPatch(value: number): void; 22 | 23 | hasSuffix(): boolean; 24 | clearSuffix(): void; 25 | getSuffix(): string | undefined; 26 | setSuffix(value: string): void; 27 | 28 | serializeBinary(): Uint8Array; 29 | toObject(includeInstance?: boolean): Version.AsObject; 30 | static toObject(includeInstance: boolean, msg: Version): Version.AsObject; 31 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 32 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 33 | static serializeBinaryToWriter(message: Version, writer: jspb.BinaryWriter): void; 34 | static deserializeBinary(bytes: Uint8Array): Version; 35 | static deserializeBinaryFromReader(message: Version, reader: jspb.BinaryReader): Version; 36 | } 37 | 38 | export namespace Version { 39 | export type AsObject = { 40 | major?: number, 41 | minor?: number, 42 | patch?: number, 43 | suffix?: string, 44 | } 45 | } 46 | 47 | export class CodeGeneratorRequest extends jspb.Message { 48 | clearFileToGenerateList(): void; 49 | getFileToGenerateList(): Array; 50 | setFileToGenerateList(value: Array): void; 51 | addFileToGenerate(value: string, index?: number): string; 52 | 53 | hasParameter(): boolean; 54 | clearParameter(): void; 55 | getParameter(): string | undefined; 56 | setParameter(value: string): void; 57 | 58 | clearProtoFileList(): void; 59 | getProtoFileList(): Array; 60 | setProtoFileList(value: Array): void; 61 | addProtoFile(value?: google_protobuf_descriptor_pb.FileDescriptorProto, index?: number): google_protobuf_descriptor_pb.FileDescriptorProto; 62 | 63 | hasCompilerVersion(): boolean; 64 | clearCompilerVersion(): void; 65 | getCompilerVersion(): Version | undefined; 66 | setCompilerVersion(value?: Version): void; 67 | 68 | serializeBinary(): Uint8Array; 69 | toObject(includeInstance?: boolean): CodeGeneratorRequest.AsObject; 70 | static toObject(includeInstance: boolean, msg: CodeGeneratorRequest): CodeGeneratorRequest.AsObject; 71 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 72 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 73 | static serializeBinaryToWriter(message: CodeGeneratorRequest, writer: jspb.BinaryWriter): void; 74 | static deserializeBinary(bytes: Uint8Array): CodeGeneratorRequest; 75 | static deserializeBinaryFromReader(message: CodeGeneratorRequest, reader: jspb.BinaryReader): CodeGeneratorRequest; 76 | } 77 | 78 | export namespace CodeGeneratorRequest { 79 | export type AsObject = { 80 | fileToGenerateList: Array, 81 | parameter?: string, 82 | protoFileList: Array, 83 | compilerVersion?: Version.AsObject, 84 | } 85 | } 86 | 87 | export class CodeGeneratorResponse extends jspb.Message { 88 | hasError(): boolean; 89 | clearError(): void; 90 | getError(): string | undefined; 91 | setError(value: string): void; 92 | 93 | clearFileList(): void; 94 | getFileList(): Array; 95 | setFileList(value: Array): void; 96 | addFile(value?: CodeGeneratorResponse.File, index?: number): CodeGeneratorResponse.File; 97 | 98 | serializeBinary(): Uint8Array; 99 | toObject(includeInstance?: boolean): CodeGeneratorResponse.AsObject; 100 | static toObject(includeInstance: boolean, msg: CodeGeneratorResponse): CodeGeneratorResponse.AsObject; 101 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 102 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 103 | static serializeBinaryToWriter(message: CodeGeneratorResponse, writer: jspb.BinaryWriter): void; 104 | static deserializeBinary(bytes: Uint8Array): CodeGeneratorResponse; 105 | static deserializeBinaryFromReader(message: CodeGeneratorResponse, reader: jspb.BinaryReader): CodeGeneratorResponse; 106 | } 107 | 108 | export namespace CodeGeneratorResponse { 109 | export type AsObject = { 110 | error?: string, 111 | fileList: Array, 112 | } 113 | 114 | export class File extends jspb.Message { 115 | hasName(): boolean; 116 | clearName(): void; 117 | getName(): string | undefined; 118 | setName(value: string): void; 119 | 120 | hasInsertionPoint(): boolean; 121 | clearInsertionPoint(): void; 122 | getInsertionPoint(): string | undefined; 123 | setInsertionPoint(value: string): void; 124 | 125 | hasContent(): boolean; 126 | clearContent(): void; 127 | getContent(): string | undefined; 128 | setContent(value: string): void; 129 | 130 | serializeBinary(): Uint8Array; 131 | toObject(includeInstance?: boolean): File.AsObject; 132 | static toObject(includeInstance: boolean, msg: File): File.AsObject; 133 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 134 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 135 | static serializeBinaryToWriter(message: File, writer: jspb.BinaryWriter): void; 136 | static deserializeBinary(bytes: Uint8Array): File; 137 | static deserializeBinaryFromReader(message: File, reader: jspb.BinaryReader): File; 138 | } 139 | 140 | export namespace File { 141 | export type AsObject = { 142 | name?: string, 143 | insertionPoint?: string, 144 | content?: string, 145 | } 146 | } 147 | } 148 | 149 | -------------------------------------------------------------------------------- /dist/protoc-plugin/google/protobuf/compiler/plugin_pb.d.ts: -------------------------------------------------------------------------------- 1 | // package: google.protobuf.compiler 2 | // file: google/protobuf/compiler/plugin.proto 3 | 4 | import * as jspb from "google-protobuf"; 5 | import * as google_protobuf_descriptor_pb from "google-protobuf/google/protobuf/descriptor_pb"; 6 | 7 | export class Version extends jspb.Message { 8 | hasMajor(): boolean; 9 | clearMajor(): void; 10 | getMajor(): number | undefined; 11 | setMajor(value: number): void; 12 | 13 | hasMinor(): boolean; 14 | clearMinor(): void; 15 | getMinor(): number | undefined; 16 | setMinor(value: number): void; 17 | 18 | hasPatch(): boolean; 19 | clearPatch(): void; 20 | getPatch(): number | undefined; 21 | setPatch(value: number): void; 22 | 23 | hasSuffix(): boolean; 24 | clearSuffix(): void; 25 | getSuffix(): string | undefined; 26 | setSuffix(value: string): void; 27 | 28 | serializeBinary(): Uint8Array; 29 | toObject(includeInstance?: boolean): Version.AsObject; 30 | static toObject(includeInstance: boolean, msg: Version): Version.AsObject; 31 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 32 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 33 | static serializeBinaryToWriter(message: Version, writer: jspb.BinaryWriter): void; 34 | static deserializeBinary(bytes: Uint8Array): Version; 35 | static deserializeBinaryFromReader(message: Version, reader: jspb.BinaryReader): Version; 36 | } 37 | 38 | export namespace Version { 39 | export type AsObject = { 40 | major?: number, 41 | minor?: number, 42 | patch?: number, 43 | suffix?: string, 44 | } 45 | } 46 | 47 | export class CodeGeneratorRequest extends jspb.Message { 48 | clearFileToGenerateList(): void; 49 | getFileToGenerateList(): Array; 50 | setFileToGenerateList(value: Array): void; 51 | addFileToGenerate(value: string, index?: number): string; 52 | 53 | hasParameter(): boolean; 54 | clearParameter(): void; 55 | getParameter(): string | undefined; 56 | setParameter(value: string): void; 57 | 58 | clearProtoFileList(): void; 59 | getProtoFileList(): Array; 60 | setProtoFileList(value: Array): void; 61 | addProtoFile(value?: google_protobuf_descriptor_pb.FileDescriptorProto, index?: number): google_protobuf_descriptor_pb.FileDescriptorProto; 62 | 63 | hasCompilerVersion(): boolean; 64 | clearCompilerVersion(): void; 65 | getCompilerVersion(): Version | undefined; 66 | setCompilerVersion(value?: Version): void; 67 | 68 | serializeBinary(): Uint8Array; 69 | toObject(includeInstance?: boolean): CodeGeneratorRequest.AsObject; 70 | static toObject(includeInstance: boolean, msg: CodeGeneratorRequest): CodeGeneratorRequest.AsObject; 71 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 72 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 73 | static serializeBinaryToWriter(message: CodeGeneratorRequest, writer: jspb.BinaryWriter): void; 74 | static deserializeBinary(bytes: Uint8Array): CodeGeneratorRequest; 75 | static deserializeBinaryFromReader(message: CodeGeneratorRequest, reader: jspb.BinaryReader): CodeGeneratorRequest; 76 | } 77 | 78 | export namespace CodeGeneratorRequest { 79 | export type AsObject = { 80 | fileToGenerateList: Array, 81 | parameter?: string, 82 | protoFileList: Array, 83 | compilerVersion?: Version.AsObject, 84 | } 85 | } 86 | 87 | export class CodeGeneratorResponse extends jspb.Message { 88 | hasError(): boolean; 89 | clearError(): void; 90 | getError(): string | undefined; 91 | setError(value: string): void; 92 | 93 | clearFileList(): void; 94 | getFileList(): Array; 95 | setFileList(value: Array): void; 96 | addFile(value?: CodeGeneratorResponse.File, index?: number): CodeGeneratorResponse.File; 97 | 98 | serializeBinary(): Uint8Array; 99 | toObject(includeInstance?: boolean): CodeGeneratorResponse.AsObject; 100 | static toObject(includeInstance: boolean, msg: CodeGeneratorResponse): CodeGeneratorResponse.AsObject; 101 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 102 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 103 | static serializeBinaryToWriter(message: CodeGeneratorResponse, writer: jspb.BinaryWriter): void; 104 | static deserializeBinary(bytes: Uint8Array): CodeGeneratorResponse; 105 | static deserializeBinaryFromReader(message: CodeGeneratorResponse, reader: jspb.BinaryReader): CodeGeneratorResponse; 106 | } 107 | 108 | export namespace CodeGeneratorResponse { 109 | export type AsObject = { 110 | error?: string, 111 | fileList: Array, 112 | } 113 | 114 | export class File extends jspb.Message { 115 | hasName(): boolean; 116 | clearName(): void; 117 | getName(): string | undefined; 118 | setName(value: string): void; 119 | 120 | hasInsertionPoint(): boolean; 121 | clearInsertionPoint(): void; 122 | getInsertionPoint(): string | undefined; 123 | setInsertionPoint(value: string): void; 124 | 125 | hasContent(): boolean; 126 | clearContent(): void; 127 | getContent(): string | undefined; 128 | setContent(value: string): void; 129 | 130 | serializeBinary(): Uint8Array; 131 | toObject(includeInstance?: boolean): File.AsObject; 132 | static toObject(includeInstance: boolean, msg: File): File.AsObject; 133 | static extensions: {[key: number]: jspb.ExtensionFieldInfo}; 134 | static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; 135 | static serializeBinaryToWriter(message: File, writer: jspb.BinaryWriter): void; 136 | static deserializeBinary(bytes: Uint8Array): File; 137 | static deserializeBinaryFromReader(message: File, reader: jspb.BinaryReader): File; 138 | } 139 | 140 | export namespace File { 141 | export type AsObject = { 142 | name?: string, 143 | insertionPoint?: string, 144 | content?: string, 145 | } 146 | } 147 | } 148 | 149 | --------------------------------------------------------------------------------