diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f4fe8c2e..d9dab32a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,7 +19,6 @@ jobs: strategy: matrix: node-version: - - 20.x - 22.x os: - windows-latest diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 2bc6576e..5eb5f63a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -19,10 +19,10 @@ jobs: - name: git checkout uses: actions/checkout@v4 - - name: Use Node.js 20.x + - name: Use Node.js 22.x uses: actions/setup-node@v4 with: - node-version: '20' + node-version: '22' registry-url: 'https://registry.npmjs.org' cache: 'npm' diff --git a/package-lock.json b/package-lock.json index facc86e5..05960bd2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,6 +30,96 @@ "npm": ">=9" } }, + "node_modules/@accordproject/concerto-codegen": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@accordproject/concerto-codegen/-/concerto-codegen-4.0.1.tgz", + "integrity": "sha512-ockVPV++IDu3j4WSnXoZejjWTBZFvX/096htu1YLc4KrtsvoF4umdnpfSgibzFBuDoIhH82X3QgHt9X9bdDPLg==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@openapi-contrib/openapi-schema-to-json-schema": "4.0.0", + "ajv": "8.18.0", + "ajv-formats": "3.0.1", + "camelcase": "6.3.0", + "dayjs": "1.11.0", + "debug": "4.3.4", + "get-value": "3.0.1", + "json-schema-migrate": "2.0.0", + "pluralize": "8.0.0" + }, + "engines": { + "node": ">=18", + "npm": ">=6" + }, + "peerDependencies": { + "@accordproject/concerto-core": "^4.0.3", + "@accordproject/concerto-util": "^4.0.3", + "@accordproject/concerto-vocabulary": "^4.0.3" + } + }, + "node_modules/@accordproject/concerto-codegen/node_modules/ajv-formats": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz", + "integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ajv": "^8.0.0" + }, + "peerDependencies": { + "ajv": "^8.0.0" + }, + "peerDependenciesMeta": { + "ajv": { + "optional": true + } + } + }, + "node_modules/@accordproject/concerto-codegen/node_modules/camelcase": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", + "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@accordproject/concerto-codegen/node_modules/dayjs": { + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.0.tgz", + "integrity": "sha512-JLC809s6Y948/FuCZPm5IX8rRhQwOiyMb2TfVVQEixG7P8Lm/gt5S7yoQZmC8x1UehI9Pb7sksEt4xx14m+7Ug==", + "dev": true, + "license": "MIT" + }, + "node_modules/@accordproject/concerto-codegen/node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/@accordproject/concerto-codegen/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true, + "license": "MIT" + }, "node_modules/@accordproject/concerto-core": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/@accordproject/concerto-core/-/concerto-core-4.0.3.tgz", @@ -119,6 +209,39 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "license": "MIT" }, + "node_modules/@accordproject/concerto-vocabulary": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@accordproject/concerto-vocabulary/-/concerto-vocabulary-4.1.0.tgz", + "integrity": "sha512-5Y6C2ouX3ZCwoK/FpThnMSaYkE7KqpdjKe3pfpzEv4RTRY/fmWnsDyGfbuaA+CSzVWP7nbe2BE4TmLi6uYBS4w==", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "dependencies": { + "@accordproject/concerto-metamodel": "^3.13.0", + "yaml": "2.8.3" + }, + "engines": { + "node": ">=18", + "npm": ">=9" + } + }, + "node_modules/@accordproject/concerto-vocabulary/node_modules/yaml": { + "version": "2.8.3", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.8.3.tgz", + "integrity": "sha512-AvbaCLOO2Otw/lW5bmh9d/WEdcDFdQp2Z2ZUH3pX9U2ihyUY0nvLv7J6TrWowklRGPYbB/IuIMfYgxaCPg5Bpg==", + "dev": true, + "license": "ISC", + "peer": true, + "bin": { + "yaml": "bin.mjs" + }, + "engines": { + "node": ">= 14.6" + }, + "funding": { + "url": "https://github.com/sponsors/eemeli" + } + }, "node_modules/@accordproject/markdown-cicero": { "resolved": "packages/markdown-cicero", "link": true @@ -3130,6 +3253,16 @@ "node": ">= 8" } }, + "node_modules/@openapi-contrib/openapi-schema-to-json-schema": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@openapi-contrib/openapi-schema-to-json-schema/-/openapi-schema-to-json-schema-4.0.0.tgz", + "integrity": "sha512-HRLG6NCHbdjCv3hacJKhZe5Al3QCig90SCvcXAS+JLb85ypuwFqcVSDnGzBqaithlUibq9UyPwQH0ATitvBBTw==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3" + } + }, "node_modules/@sinclair/typebox": { "version": "0.27.10", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.10.tgz", @@ -6520,6 +6653,19 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/get-value": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/get-value/-/get-value-3.0.1.tgz", + "integrity": "sha512-mKZj9JLQrwMBtj5wxi6MH8Z5eSKaERpAwjg43dPtlGI1ZVEgH/qC7T8/6R2OBSUA+zzHBZgICsVJaEIV2tKTDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "isobject": "^3.0.1" + }, + "engines": { + "node": ">=6.0" + } + }, "node_modules/glob": { "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", @@ -8573,6 +8719,16 @@ "dev": true, "license": "MIT" }, + "node_modules/json-schema-migrate": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/json-schema-migrate/-/json-schema-migrate-2.0.0.tgz", + "integrity": "sha512-r38SVTtojDRp4eD6WsCqiE0eNDt4v1WalBXb9cyZYw9ai5cGtBwzRNWjHzJl38w6TxFkXAIA7h+fyX3tnrAFhQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ajv": "^8.0.0" + } + }, "node_modules/json-schema-traverse": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", @@ -10136,6 +10292,16 @@ "dev": true, "license": "MIT" }, + "node_modules/pluralize": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/pluralize/-/pluralize-8.0.0.tgz", + "integrity": "sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, "node_modules/possible-typed-array-names": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.1.0.tgz", @@ -12964,6 +13130,7 @@ "markdown-it": "^14.1.0" }, "devDependencies": { + "@accordproject/concerto-codegen": "^4.0.1", "@accordproject/concerto-core": "^4.0.3", "eslint": "8.57.1", "jest": "^29.7.0", diff --git a/package.json b/package.json index 8da3cb21..a534df04 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "typescript": "^5.9.3" }, "engines": { - "node": ">=18", + "node": ">=22", "npm": ">=9" }, "workspaces": [ diff --git a/packages/markdown-cicero/lib/CiceroMarkTransformer.js b/packages/markdown-cicero/lib/CiceroMarkTransformer.js index f813df1f..ef0f8c8a 100644 --- a/packages/markdown-cicero/lib/CiceroMarkTransformer.js +++ b/packages/markdown-cicero/lib/CiceroMarkTransformer.js @@ -14,6 +14,10 @@ 'use strict'; +/** @typedef {import('@accordproject/markdown-common/types/model/commonmark').IDocument} IDocument */ +/** @typedef {import('@accordproject/markdown-common/types/model/commonmark').IDocument} ICiceroDocument */ +/** @typedef {import('@accordproject/markdown-common/types/model/ciceromark').IClause} IClause */ + const { ModelManager, Factory, Serializer } = require('@accordproject/concerto-core'); const MarkdownIt = require('markdown-it'); @@ -57,8 +61,8 @@ class CiceroMarkTransformer { /** * Obtain the Clause text for a Clause node - * @param {*} input CiceroMark DOM - * @returns {*} markdown_cicero string + * @param {IClause} input CiceroMark DOM + * @returns {string} markdown_cicero string */ getClauseText(input) { if (input.$class === `${CiceroMarkModel.NAMESPACE}.Clause`) { @@ -76,7 +80,7 @@ class CiceroMarkTransformer { /** * Retrieve the serializer used by the parser * - * @returns {*} a serializer capable of dealing with the Concerto + * @returns {Serializer} a serializer capable of dealing with the Concerto * object returns by parse */ getSerializer() { @@ -85,8 +89,8 @@ class CiceroMarkTransformer { /** * Converts a CiceroEdit string to a CiceroMark DOM - * @param {*} input - ciceroedit string - * @returns {*} CiceroMark DOM + * @param {string} input - ciceroedit string + * @returns {ICiceroDocument} CiceroMark DOM */ fromCiceroEdit(input) { const commonMark = this.commonMark.fromMarkdown(input); @@ -106,10 +110,10 @@ class CiceroMarkTransformer { /** * Converts a CiceroMark DOM to a CiceroMark Unwrapped DOM - * @param {object} input - CiceroMark DOM (JSON) + * @param {ICiceroDocument} input - CiceroMark DOM (JSON) * @param {object} [options] configuration options * @param {boolean} [options.unquoteVariables] if true variable quotations are removed - * @returns {*} CiceroMark DOM + * @returns {ICiceroDocument} CiceroMark DOM */ toCiceroMarkUnwrapped(input,options) { // remove variables, e.g. {{ variable }}, {{% formula %}} @@ -130,8 +134,8 @@ class CiceroMarkTransformer { /** * Converts a CommonMark DOM to a CiceroMark DOM - * @param {*} input - CommonMark DOM (in JSON) - * @returns {*} CiceroMark DOM + * @param {IDocument} input - CommonMark DOM (in JSON) + * @returns {ICiceroDocument} CiceroMark DOM */ fromCommonMark(input) { return input; // Now the identity @@ -140,7 +144,7 @@ class CiceroMarkTransformer { /** * Converts a markdown string to a CiceroMark DOM * @param {string} markdown a markdown string - * @returns {object} ciceromark object (JSON) + * @returns {ICiceroDocument} ciceromark object (JSON) */ fromMarkdown(markdown) { const commonMarkDom = this.commonMark.fromMarkdown(markdown); @@ -149,9 +153,9 @@ class CiceroMarkTransformer { /** * Converts a CiceroMark DOM to a markdown string - * @param {*} input CiceroMark DOM + * @param {ICiceroDocument} input CiceroMark DOM * @param {object} [options] configuration options - * @returns {*} markdown string + * @returns {string} markdown string */ toMarkdown(input, options) { const commonMarkDom = this.toCommonMark(input, options); @@ -162,7 +166,7 @@ class CiceroMarkTransformer { * Converts a cicero markdown string to a CiceroMark DOM * @param {string} markdown a cicero markdown string * @param {object} [options] configuration options - * @returns {object} ciceromark object (JSON) + * @returns {ICiceroDocument} ciceromark object (JSON) */ fromMarkdownCicero(markdown, options) { const tokens = this.toTokens(markdown); @@ -171,8 +175,8 @@ class CiceroMarkTransformer { /** * Converts a CiceroMark DOM to a cicero markdown string - * @param {object} input CiceroMark DOM - * @returns {string} json commonmark object + * @param {ICiceroDocument} input CiceroMark DOM + * @returns {string} cicero markdown string */ toMarkdownCicero(input) { const visitor = new ToMarkdownCiceroVisitor(); @@ -181,11 +185,11 @@ class CiceroMarkTransformer { /** * Converts a CiceroMark DOM to a CommonMark DOM - * @param {*} input CiceroMark DOM + * @param {ICiceroDocument} input CiceroMark DOM * @param {object} [options] configuration options * @param {boolean} [options.removeFormatting] if true the formatting nodes are removed * @param {boolean} [options.unquoteVariables] if true variable quotations are removed - * @returns {*} json commonmark object + * @returns {IDocument} CommonMark DOM */ toCommonMark(input, options) { let json = this.toCiceroMarkUnwrapped(input,options); @@ -211,8 +215,8 @@ class CiceroMarkTransformer { /** * Unquotes a CiceroMark DOM - * @param {object} input CiceroMark DOM - * @returns {object} unquoted CiceroMark DOM + * @param {ICiceroDocument} input CiceroMark DOM + * @returns {ICiceroDocument} unquoted CiceroMark DOM */ unquote(input) { return unquoteVariables(input); @@ -222,7 +226,7 @@ class CiceroMarkTransformer { * Converts a ciceromark string into a token stream * * @param {string} input the string to parse - * @returns {*} a markdown-it token stream + * @returns {object[]} a markdown-it token stream */ toTokens(input) { const parser = new MarkdownIt({html:true}).use(MarkdownItCicero); // XXX HTML inlines and code blocks true @@ -233,8 +237,8 @@ class CiceroMarkTransformer { /** * Converts a token stream into a CiceroMark DOM object. * - * @param {object} tokenStream the token stream - * @returns {*} the CiceroMark DOM (JSON) + * @param {object[]} tokenStream the token stream + * @returns {ICiceroDocument} the CiceroMark DOM (JSON) */ fromTokens(tokenStream) { const fromMarkdownIt = new FromMarkdownIt(cicerorules); diff --git a/packages/markdown-cicero/package.json b/packages/markdown-cicero/package.json index 1b7dc4ac..14334323 100644 --- a/packages/markdown-cicero/package.json +++ b/packages/markdown-cicero/package.json @@ -3,7 +3,7 @@ "version": "0.16.25", "description": "A framework for transforming markdown", "engines": { - "node": ">=18", + "node": ">=22", "npm": ">=9" }, "publishConfig": { diff --git a/packages/markdown-cicero/types/lib/CiceroMarkTransformer.d.ts b/packages/markdown-cicero/types/lib/CiceroMarkTransformer.d.ts index ca9e5dc9..8dd08d0d 100644 --- a/packages/markdown-cicero/types/lib/CiceroMarkTransformer.d.ts +++ b/packages/markdown-cicero/types/lib/CiceroMarkTransformer.d.ts @@ -11,97 +11,103 @@ declare class CiceroMarkTransformer { serializer: Serializer; /** * Obtain the Clause text for a Clause node - * @param {*} input CiceroMark DOM - * @returns {*} markdown_cicero string + * @param {IClause} input CiceroMark DOM + * @returns {string} markdown_cicero string */ - getClauseText(input: any): any; + getClauseText(input: IClause): string; /** * Retrieve the serializer used by the parser * - * @returns {*} a serializer capable of dealing with the Concerto + * @returns {Serializer} a serializer capable of dealing with the Concerto * object returns by parse */ - getSerializer(): any; + getSerializer(): Serializer; /** * Converts a CiceroEdit string to a CiceroMark DOM - * @param {*} input - ciceroedit string - * @returns {*} CiceroMark DOM + * @param {string} input - ciceroedit string + * @returns {ICiceroDocument} CiceroMark DOM */ - fromCiceroEdit(input: any): any; + fromCiceroEdit(input: string): ICiceroDocument; /** * Converts a CiceroMark DOM to a CiceroMark Unwrapped DOM - * @param {object} input - CiceroMark DOM (JSON) + * @param {ICiceroDocument} input - CiceroMark DOM (JSON) * @param {object} [options] configuration options * @param {boolean} [options.unquoteVariables] if true variable quotations are removed - * @returns {*} CiceroMark DOM + * @returns {ICiceroDocument} CiceroMark DOM */ - toCiceroMarkUnwrapped(input: object, options?: { + toCiceroMarkUnwrapped(input: ICiceroDocument, options?: { unquoteVariables?: boolean; - }): any; + }): ICiceroDocument; /** * Converts a CommonMark DOM to a CiceroMark DOM - * @param {*} input - CommonMark DOM (in JSON) - * @returns {*} CiceroMark DOM + * @param {IDocument} input - CommonMark DOM (in JSON) + * @returns {ICiceroDocument} CiceroMark DOM */ - fromCommonMark(input: any): any; + fromCommonMark(input: IDocument): ICiceroDocument; /** * Converts a markdown string to a CiceroMark DOM * @param {string} markdown a markdown string - * @returns {object} ciceromark object (JSON) + * @returns {ICiceroDocument} ciceromark object (JSON) */ - fromMarkdown(markdown: string): object; + fromMarkdown(markdown: string): ICiceroDocument; /** * Converts a CiceroMark DOM to a markdown string - * @param {*} input CiceroMark DOM + * @param {ICiceroDocument} input CiceroMark DOM * @param {object} [options] configuration options - * @returns {*} markdown string + * @returns {string} markdown string */ - toMarkdown(input: any, options?: object): any; + toMarkdown(input: ICiceroDocument, options?: object): string; /** * Converts a cicero markdown string to a CiceroMark DOM * @param {string} markdown a cicero markdown string * @param {object} [options] configuration options - * @returns {object} ciceromark object (JSON) + * @returns {ICiceroDocument} ciceromark object (JSON) */ - fromMarkdownCicero(markdown: string, options?: object): object; + fromMarkdownCicero(markdown: string, options?: object): ICiceroDocument; /** * Converts a CiceroMark DOM to a cicero markdown string - * @param {object} input CiceroMark DOM - * @returns {string} json commonmark object + * @param {ICiceroDocument} input CiceroMark DOM + * @returns {string} cicero markdown string */ - toMarkdownCicero(input: object): string; + toMarkdownCicero(input: ICiceroDocument): string; /** * Converts a CiceroMark DOM to a CommonMark DOM - * @param {*} input CiceroMark DOM + * @param {ICiceroDocument} input CiceroMark DOM * @param {object} [options] configuration options * @param {boolean} [options.removeFormatting] if true the formatting nodes are removed * @param {boolean} [options.unquoteVariables] if true variable quotations are removed - * @returns {*} json commonmark object + * @returns {IDocument} CommonMark DOM */ - toCommonMark(input: any, options?: { + toCommonMark(input: ICiceroDocument, options?: { removeFormatting?: boolean; unquoteVariables?: boolean; - }): any; + }): IDocument; /** * Unquotes a CiceroMark DOM - * @param {object} input CiceroMark DOM - * @returns {object} unquoted CiceroMark DOM + * @param {ICiceroDocument} input CiceroMark DOM + * @returns {ICiceroDocument} unquoted CiceroMark DOM */ - unquote(input: object): object; + unquote(input: ICiceroDocument): ICiceroDocument; /** * Converts a ciceromark string into a token stream * * @param {string} input the string to parse - * @returns {*} a markdown-it token stream + * @returns {object[]} a markdown-it token stream */ - toTokens(input: string): any; + toTokens(input: string): object[]; /** * Converts a token stream into a CiceroMark DOM object. * - * @param {object} tokenStream the token stream - * @returns {*} the CiceroMark DOM (JSON) + * @param {object[]} tokenStream the token stream + * @returns {ICiceroDocument} the CiceroMark DOM (JSON) */ - fromTokens(tokenStream: object): any; + fromTokens(tokenStream: object[]): ICiceroDocument; +} +declare namespace CiceroMarkTransformer { + export { IDocument, ICiceroDocument, IClause }; } import { ModelManager } from "@accordproject/concerto-core"; import { Serializer } from "@accordproject/concerto-core"; +type IDocument = import("@accordproject/markdown-common/types/model/commonmark").IDocument; +type ICiceroDocument = import("@accordproject/markdown-common/types/model/commonmark").IDocument; +type IClause = import("@accordproject/markdown-common/types/model/ciceromark").IClause; diff --git a/packages/markdown-cli/package.json b/packages/markdown-cli/package.json index 2c62cde7..4a5738a1 100644 --- a/packages/markdown-cli/package.json +++ b/packages/markdown-cli/package.json @@ -3,7 +3,7 @@ "version": "0.16.25", "description": "A framework for transforming markdown", "engines": { - "node": ">=18", + "node": ">=22", "npm": ">=9" }, "publishConfig": { diff --git a/packages/markdown-common/lib/CommonMarkTransformer.js b/packages/markdown-common/lib/CommonMarkTransformer.js index 8ab305c2..d916acba 100644 --- a/packages/markdown-common/lib/CommonMarkTransformer.js +++ b/packages/markdown-common/lib/CommonMarkTransformer.js @@ -14,6 +14,9 @@ 'use strict'; +/** @typedef {import('@accordproject/markdown-common/types/model/commonmark').IDocument} IDocument */ +/** @typedef {import('@accordproject/markdown-common/types/model/commonmark').INode} INode */ + const MarkdownIt = require('markdown-it'); const FromMarkdownIt = require('./FromMarkdownIt'); @@ -41,7 +44,7 @@ class CommonMarkTransformer { /** * Converts a CommonMark DOM to a markdown string - * @param {*} input - CommonMark DOM (in JSON) + * @param {INode} input - CommonMark DOM (in JSON) * @returns {string} the markdown string */ toMarkdown(input) { @@ -51,8 +54,8 @@ class CommonMarkTransformer { /** * Converts a CommonMark DOM to a CommonMark DOM with formatting removed - * @param {*} input - CommonMark DOM (in JSON) - * @returns {string} the CommonMark DOM with formatting nodes removed + * @param {IDocument} input - CommonMark DOM (in JSON) + * @returns {IDocument} the CommonMark DOM with formatting nodes removed */ removeFormatting(input) { return removeFormatting(input); @@ -62,7 +65,7 @@ class CommonMarkTransformer { * Converts a markdown string into a token stream * * @param {string} markdown the string to parse - * @returns {*} a markdown-it token stream + * @returns {object[]} a markdown-it token stream */ toTokens(markdown) { const parser = new MarkdownIt({html:true}); // XXX HTML inlines and code blocks true @@ -73,8 +76,8 @@ class CommonMarkTransformer { /** * Converts a token stream into a CommonMark DOM object. * - * @param {object} tokenStream the token stream - * @returns {*} a Concerto object (DOM) for the markdown content + * @param {object[]} tokenStream the token stream + * @returns {IDocument} a Concerto object (DOM) for the markdown content */ fromTokens(tokenStream) { const fromMarkdownIt = new FromMarkdownIt(); @@ -89,7 +92,7 @@ class CommonMarkTransformer { * Converts a markdown string into a CommonMark DOM object. * * @param {string} markdown the string to parse - * @returns {object} a CommonMark DOM (JSON) for the markdown content + * @returns {IDocument} a CommonMark DOM (JSON) for the markdown content */ fromMarkdown(markdown) { const tokenStream = this.toTokens(markdown); @@ -99,7 +102,7 @@ class CommonMarkTransformer { /** * Retrieve the serializer used by the parser * - * @returns {*} a serializer capable of dealing with the Concerto + * @returns {Serializer} a serializer capable of dealing with the Concerto */ getSerializer() { return this.serializer; diff --git a/packages/markdown-common/lib/ToMarkdownVisitor.js b/packages/markdown-common/lib/ToMarkdownVisitor.js index 31c76ae7..1bdc51c7 100644 --- a/packages/markdown-common/lib/ToMarkdownVisitor.js +++ b/packages/markdown-common/lib/ToMarkdownVisitor.js @@ -50,7 +50,7 @@ class ToMarkdownVisitor extends FromCommonMarkVisitor { /** * Converts a CommonMark DOM to a markdown string - * @param {*} input - CommonMark DOM (as a Concerto object) + * @param {object} input - CommonMark DOM (as a Concerto object) * @returns {string} the markdown string */ toMarkdown(input) { diff --git a/packages/markdown-common/package.json b/packages/markdown-common/package.json index 917f0180..c9e971d1 100644 --- a/packages/markdown-common/package.json +++ b/packages/markdown-common/package.json @@ -3,7 +3,7 @@ "version": "0.16.25", "description": "A framework for transforming markdown", "engines": { - "node": ">=15", + "node": ">=22", "npm": ">=9" }, "publishConfig": { @@ -25,7 +25,8 @@ "test:cov": "npm run lint && jest --timeOut=10000 --coverage --silent", "jsdoc": "jsdoc -c jsdoc.json package.json", "build": "npm run build:types", - "build:types": "tsc" + "build:model-types": "node scripts/generate-model-types.js", + "build:types": "npm run build:model-types && tsc" }, "typings": "types/index.d.ts", "repository": { @@ -45,6 +46,7 @@ }, "homepage": "https://github.com/accordproject/markdown-transform", "devDependencies": { + "@accordproject/concerto-codegen": "^4.0.1", "@accordproject/concerto-core": "^4.0.3", "eslint": "8.57.1", "jest": "^29.7.0", diff --git a/packages/markdown-common/scripts/generate-model-types.js b/packages/markdown-common/scripts/generate-model-types.js new file mode 100644 index 00000000..3771f9e2 --- /dev/null +++ b/packages/markdown-common/scripts/generate-model-types.js @@ -0,0 +1,72 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +const { CodeGen } = require('@accordproject/concerto-codegen'); +const { ModelManager } = require('@accordproject/concerto-core'); +const fs = require('fs'); +const path = require('path'); + +const { CommonMarkModel, CiceroMarkModel, ConcertoMetaModel, TemplateMarkModel } = require('../index'); + +// Map raw namespace filename → clean output name. +// Update this map if any CTO namespace version bumps. +const NAME_MAP = { + 'concerto@1.0.0': 'concerto-base', + 'concerto.metamodel@1.0.0': 'concerto-metamodel', + 'org.accordproject.commonmark@0.5.0': 'commonmark', + 'org.accordproject.ciceromark@0.6.0': 'ciceromark', + 'org.accordproject.templatemark@0.5.0': 'templatemark', +}; + +// Namespaces auto-generated but not useful in the public API +const SKIP = new Set(['concerto.decorator@1.0.0']); + +const mm = new ModelManager(); +mm.addCTOModel(ConcertoMetaModel.MODEL, 'metamodel.cto'); +mm.addCTOModel(CommonMarkModel.MODEL, 'commonmark.cto'); +mm.addCTOModel(CiceroMarkModel.MODEL, 'ciceromark.cto'); +mm.addCTOModel(TemplateMarkModel.MODEL, 'templatemark.cto'); + +const outDir = path.resolve(__dirname, '../types/model'); +fs.mkdirSync(outDir, { recursive: true }); + +const files = {}; +mm.accept(new CodeGen.TypescriptVisitor(), { + fileWriter: { + openFile: (f) => { files[f] = ''; }, + writeLine: (i, l) => { files[Object.keys(files).at(-1)] += ' '.repeat(i) + l + '\n'; }, + closeFile: () => {} + } +}); + +for (const [rawFile, content] of Object.entries(files)) { + const ns = rawFile.replace(/\.ts$/, ''); + if (SKIP.has(ns)) continue; + const cleanName = NAME_MAP[ns]; + if (!cleanName) { console.warn('unmapped namespace:', ns); continue; } + + // Rewrite cross-file import paths to clean names + let out = content; + for (const [rawNs, clean] of Object.entries(NAME_MAP)) { + out = out.replaceAll(`'./${rawNs}'`, `'./${clean}'`); + } + // Strip generated eslint-disable comment + out = out.replace(/\/\* eslint-disable.*?\*\/\n/, ''); + + const outPath = path.join(outDir, `${cleanName}.d.ts`); + fs.writeFileSync(outPath, out); + console.log(`wrote types/model/${cleanName}.d.ts`); +} diff --git a/packages/markdown-common/types/lib/CommonMarkTransformer.d.ts b/packages/markdown-common/types/lib/CommonMarkTransformer.d.ts index 3788fca9..4b50c4fd 100644 --- a/packages/markdown-common/types/lib/CommonMarkTransformer.d.ts +++ b/packages/markdown-common/types/lib/CommonMarkTransformer.d.ts @@ -8,42 +8,47 @@ declare class CommonMarkTransformer { serializer: Serializer; /** * Converts a CommonMark DOM to a markdown string - * @param {*} input - CommonMark DOM (in JSON) + * @param {INode} input - CommonMark DOM (in JSON) * @returns {string} the markdown string */ - toMarkdown(input: any): string; + toMarkdown(input: INode): string; /** * Converts a CommonMark DOM to a CommonMark DOM with formatting removed - * @param {*} input - CommonMark DOM (in JSON) - * @returns {string} the CommonMark DOM with formatting nodes removed + * @param {IDocument} input - CommonMark DOM (in JSON) + * @returns {IDocument} the CommonMark DOM with formatting nodes removed */ - removeFormatting(input: any): string; + removeFormatting(input: IDocument): IDocument; /** * Converts a markdown string into a token stream * * @param {string} markdown the string to parse - * @returns {*} a markdown-it token stream + * @returns {object[]} a markdown-it token stream */ - toTokens(markdown: string): any; + toTokens(markdown: string): object[]; /** * Converts a token stream into a CommonMark DOM object. * - * @param {object} tokenStream the token stream - * @returns {*} a Concerto object (DOM) for the markdown content + * @param {object[]} tokenStream the token stream + * @returns {IDocument} a Concerto object (DOM) for the markdown content */ - fromTokens(tokenStream: object): any; + fromTokens(tokenStream: object[]): IDocument; /** * Converts a markdown string into a CommonMark DOM object. * * @param {string} markdown the string to parse - * @returns {object} a CommonMark DOM (JSON) for the markdown content + * @returns {IDocument} a CommonMark DOM (JSON) for the markdown content */ - fromMarkdown(markdown: string): object; + fromMarkdown(markdown: string): IDocument; /** * Retrieve the serializer used by the parser * - * @returns {*} a serializer capable of dealing with the Concerto + * @returns {Serializer} a serializer capable of dealing with the Concerto */ - getSerializer(): any; + getSerializer(): Serializer; +} +declare namespace CommonMarkTransformer { + export { IDocument, INode }; } import { Serializer } from "@accordproject/concerto-core"; +type IDocument = import("@accordproject/markdown-common/types/model/commonmark").IDocument; +type INode = import("@accordproject/markdown-common/types/model/commonmark").INode; diff --git a/packages/markdown-common/types/lib/ToMarkdownVisitor.d.ts b/packages/markdown-common/types/lib/ToMarkdownVisitor.d.ts index e57beb3c..0982b97d 100644 --- a/packages/markdown-common/types/lib/ToMarkdownVisitor.d.ts +++ b/packages/markdown-common/types/lib/ToMarkdownVisitor.d.ts @@ -16,9 +16,9 @@ declare class ToMarkdownVisitor extends FromCommonMarkVisitor { constructor(); /** * Converts a CommonMark DOM to a markdown string - * @param {*} input - CommonMark DOM (as a Concerto object) + * @param {object} input - CommonMark DOM (as a Concerto object) * @returns {string} the markdown string */ - toMarkdown(input: any): string; + toMarkdown(input: object): string; } import FromCommonMarkVisitor = require("./FromCommonMarkVisitor"); diff --git a/packages/markdown-common/types/model/ciceromark.d.ts b/packages/markdown-common/types/model/ciceromark.d.ts new file mode 100644 index 00000000..85c9bf2b --- /dev/null +++ b/packages/markdown-common/types/model/ciceromark.d.ts @@ -0,0 +1,81 @@ +// Generated code for namespace: org.accordproject.ciceromark@0.6.0 + +// imports + +// Warning: Beware of circular dependencies when modifying these imports + +// Warning: Beware of circular dependencies when modifying these imports + +// Warning: Beware of circular dependencies when modifying these imports +import {IChild,INode} from './commonmark'; +import {IDecorator} from './concerto-metamodel'; + +// interfaces +export interface IElement extends IChild { + name: string; + elementType?: string; + decorators?: IDecorator[]; +} + +export type ElementUnion = IVariable | +IFormula | +IBlock; + +export interface IVariable extends IElement { + value: string; + identifiedBy?: string; +} + +export type VariableUnion = IFormattedVariable | +IEnumVariable; + +export interface IFormattedVariable extends IVariable { + format: string; +} + +export interface IEnumVariable extends IVariable { + enumValues: string[]; +} + +export interface IFormula extends IElement { + value: string; + dependencies?: string[]; + code?: string; +} + +export interface IBlock extends IElement { +} + +export type BlockUnion = IClause | +IContract | +IConditional | +IOptional | +IListBlock; + +export interface IClause extends IBlock { + src?: string; +} + +export interface IContract extends IBlock { + src?: string; +} + +export interface IConditional extends IBlock { + isTrue: boolean; + whenTrue: IChild[]; + whenFalse: IChild[]; +} + +export interface IOptional extends IBlock { + hasSome: boolean; + whenSome: IChild[]; + whenNone: IChild[]; +} + +export interface IListBlock extends IBlock { + type: string; + tight: string; + start?: string; + delimiter?: string; +} + diff --git a/packages/markdown-common/types/model/commonmark.d.ts b/packages/markdown-common/types/model/commonmark.d.ts new file mode 100644 index 00000000..45c32a4f --- /dev/null +++ b/packages/markdown-common/types/model/commonmark.d.ts @@ -0,0 +1,162 @@ +// Generated code for namespace: org.accordproject.commonmark@0.5.0 + +// imports + +// Warning: Beware of circular dependencies when modifying these imports + +// Warning: Beware of circular dependencies when modifying these imports + +// Warning: Beware of circular dependencies when modifying these imports +import type { + IElement +} from './ciceromark'; +import type { + IElementDefinition +} from './templatemark'; +import {IConcept} from './concerto-base'; + +// interfaces +export interface INode extends IConcept { + text?: string; + nodes?: INode[]; + startLine?: number; + endLine?: number; +} + +export type NodeUnion = IRoot | +IChild; + +export interface IRoot extends INode { +} + +export type RootUnion = IDocument; + +export interface IChild extends INode { +} + +export type ChildUnion = IText | +ICodeBlock | +ICode | +IHtmlInline | +IHtmlBlock | +IEmph | +IStrong | +IBlockQuote | +IHeading | +IThematicBreak | +ISoftbreak | +ILinebreak | +ILink | +IImage | +IParagraph | +IList | +IItem | +ITable | +ITableHead | +ITableBody | +ITableRow | +IHeaderCell | +ITableCell | +IElement | +IElementDefinition; + +export interface IText extends IChild { +} + +export interface IAttribute extends IConcept { + name: string; + value: string; +} + +export interface ITagInfo extends IConcept { + tagName: string; + attributeString: string; + attributes: IAttribute[]; + content: string; + closed: boolean; +} + +export interface ICodeBlock extends IChild { + info?: string; + tag?: ITagInfo; +} + +export interface ICode extends IChild { + info?: string; +} + +export interface IHtmlInline extends IChild { + tag?: ITagInfo; +} + +export interface IHtmlBlock extends IChild { + tag?: ITagInfo; +} + +export interface IEmph extends IChild { +} + +export interface IStrong extends IChild { +} + +export interface IBlockQuote extends IChild { +} + +export interface IHeading extends IChild { + level: string; +} + +export interface IThematicBreak extends IChild { +} + +export interface ISoftbreak extends IChild { +} + +export interface ILinebreak extends IChild { +} + +export interface ILink extends IChild { + destination: string; + title: string; +} + +export interface IImage extends IChild { + destination: string; + title: string; +} + +export interface IParagraph extends IChild { +} + +export interface IList extends IChild { + type: string; + start?: string; + tight: string; + delimiter?: string; +} + +export interface IItem extends IChild { +} + +export interface IDocument extends IRoot { + xmlns: string; +} + +export interface ITable extends IChild { +} + +export interface ITableHead extends IChild { +} + +export interface ITableBody extends IChild { +} + +export interface ITableRow extends IChild { +} + +export interface IHeaderCell extends IChild { +} + +export interface ITableCell extends IChild { +} + diff --git a/packages/markdown-common/types/model/concerto-base.d.ts b/packages/markdown-common/types/model/concerto-base.d.ts new file mode 100644 index 00000000..469820cd --- /dev/null +++ b/packages/markdown-common/types/model/concerto-base.d.ts @@ -0,0 +1,83 @@ +// Generated code for namespace: concerto@1.0.0 + +// imports + +// Warning: Beware of circular dependencies when modifying these imports +import type { + IPosition, + IRange, + ITypeIdentifier, + IDecoratorLiteral, + IDecorator, + IIdentified, + IDeclaration, + IMapKeyType, + IMapValueType, + IEnumProperty, + IProperty, + IStringRegexValidator, + IStringLengthValidator, + IDoubleDomainValidator, + IIntegerDomainValidator, + ILongDomainValidator, + IAliasedType, + IImport, + IModel, + IModels +} from './concerto-metamodel'; +import type { + INode, + IAttribute, + ITagInfo +} from './commonmark'; +import type { + CodeType, + ICode +} from './templatemark'; + +// interfaces +export interface IConcept { + $class: string; +} + +export type ConceptUnion = IPosition | +IRange | +ITypeIdentifier | +IDecoratorLiteral | +IDecorator | +IIdentified | +IDeclaration | +IMapKeyType | +IMapValueType | +IEnumProperty | +IProperty | +IStringRegexValidator | +IStringLengthValidator | +IDoubleDomainValidator | +IIntegerDomainValidator | +ILongDomainValidator | +IAliasedType | +IImport | +IModel | +IModels | +INode | +IAttribute | +ITagInfo | +ICode; + +export interface IAsset extends IConcept { + $identifier: string; +} + +export interface IParticipant extends IConcept { + $identifier: string; +} + +export interface ITransaction extends IConcept { + $timestamp: Date; +} + +export interface IEvent extends IConcept { + $timestamp: Date; +} + diff --git a/packages/markdown-common/types/model/concerto-metamodel.d.ts b/packages/markdown-common/types/model/concerto-metamodel.d.ts new file mode 100644 index 00000000..cf4392af --- /dev/null +++ b/packages/markdown-common/types/model/concerto-metamodel.d.ts @@ -0,0 +1,348 @@ +// Generated code for namespace: concerto.metamodel@1.0.0 + +// imports + +// Warning: Beware of circular dependencies when modifying these imports + +// Warning: Beware of circular dependencies when modifying these imports + +// Warning: Beware of circular dependencies when modifying these imports + +// Warning: Beware of circular dependencies when modifying these imports + +// Warning: Beware of circular dependencies when modifying these imports + +// Warning: Beware of circular dependencies when modifying these imports + +// Warning: Beware of circular dependencies when modifying these imports + +// Warning: Beware of circular dependencies when modifying these imports + +// Warning: Beware of circular dependencies when modifying these imports +import {IConcept} from './concerto-base'; + +// interfaces +export interface IPosition extends IConcept { + line: number; + column: number; + offset: number; +} + +export interface IRange extends IConcept { + start: IPosition; + end: IPosition; + source?: string; +} + +export interface ITypeIdentifier extends IConcept { + name: string; + namespace?: string; +} + +export interface IDecoratorLiteral extends IConcept { + location?: IRange; +} + +export type DecoratorLiteralUnion = IDecoratorString | +IDecoratorNumber | +IDecoratorBoolean | +IDecoratorTypeReference; + +export interface IDecoratorString extends IDecoratorLiteral { + value: string; +} + +export interface IDecoratorNumber extends IDecoratorLiteral { + value: number; +} + +export interface IDecoratorBoolean extends IDecoratorLiteral { + value: boolean; +} + +export interface IDecoratorTypeReference extends IDecoratorLiteral { + type: ITypeIdentifier; + isArray: boolean; +} + +export interface IDecorator extends IConcept { + name: string; + arguments?: IDecoratorLiteral[]; + location?: IRange; +} + +export interface IIdentified extends IConcept { +} + +export type IdentifiedUnion = IIdentifiedBy; + +export interface IIdentifiedBy extends IIdentified { + name: string; +} + +export interface IDeclaration extends IConcept { + name: string; + decorators?: IDecorator[]; + location?: IRange; +} + +export type DeclarationUnion = IMapDeclaration | +IEnumDeclaration | +IConceptDeclaration | +IScalarDeclaration; + +export interface IMapKeyType extends IConcept { + decorators?: IDecorator[]; + location?: IRange; +} + +export type MapKeyTypeUnion = IStringMapKeyType | +IDateTimeMapKeyType | +IObjectMapKeyType; + +export interface IMapValueType extends IConcept { + decorators?: IDecorator[]; + location?: IRange; +} + +export type MapValueTypeUnion = IBooleanMapValueType | +IDateTimeMapValueType | +IStringMapValueType | +IIntegerMapValueType | +ILongMapValueType | +IDoubleMapValueType | +IObjectMapValueType | +IRelationshipMapValueType; + +export interface IMapDeclaration extends IDeclaration { + key: IMapKeyType; + value: IMapValueType; +} + +export interface IStringMapKeyType extends IMapKeyType { +} + +export interface IDateTimeMapKeyType extends IMapKeyType { +} + +export interface IObjectMapKeyType extends IMapKeyType { + type: ITypeIdentifier; +} + +export interface IBooleanMapValueType extends IMapValueType { +} + +export interface IDateTimeMapValueType extends IMapValueType { +} + +export interface IStringMapValueType extends IMapValueType { +} + +export interface IIntegerMapValueType extends IMapValueType { +} + +export interface ILongMapValueType extends IMapValueType { +} + +export interface IDoubleMapValueType extends IMapValueType { +} + +export interface IObjectMapValueType extends IMapValueType { + type: ITypeIdentifier; +} + +export interface IRelationshipMapValueType extends IMapValueType { + type: ITypeIdentifier; +} + +export interface IEnumDeclaration extends IDeclaration { + properties: IEnumProperty[]; +} + +export interface IEnumProperty extends IConcept { + name: string; + decorators?: IDecorator[]; + location?: IRange; +} + +export interface IConceptDeclaration extends IDeclaration { + isAbstract: boolean; + identified?: IIdentified; + superType?: ITypeIdentifier; + properties: IProperty[]; +} + +export type ConceptDeclarationUnion = IAssetDeclaration | +IParticipantDeclaration | +ITransactionDeclaration | +IEventDeclaration; + +export interface IAssetDeclaration extends IConceptDeclaration { +} + +export interface IParticipantDeclaration extends IConceptDeclaration { +} + +export interface ITransactionDeclaration extends IConceptDeclaration { +} + +export interface IEventDeclaration extends IConceptDeclaration { +} + +export interface IProperty extends IConcept { + name: string; + isArray: boolean; + isOptional: boolean; + decorators?: IDecorator[]; + location?: IRange; +} + +export type PropertyUnion = IRelationshipProperty | +IObjectProperty | +IBooleanProperty | +IDateTimeProperty | +IStringProperty | +IDoubleProperty | +IIntegerProperty | +ILongProperty; + +export interface IRelationshipProperty extends IProperty { + type: ITypeIdentifier; +} + +export interface IObjectProperty extends IProperty { + defaultValue?: string; + type: ITypeIdentifier; +} + +export interface IBooleanProperty extends IProperty { + defaultValue?: boolean; +} + +export interface IDateTimeProperty extends IProperty { +} + +export interface IStringProperty extends IProperty { + defaultValue?: string; + validator?: IStringRegexValidator; + lengthValidator?: IStringLengthValidator; +} + +export interface IStringRegexValidator extends IConcept { + pattern: string; + flags: string; +} + +export interface IStringLengthValidator extends IConcept { + minLength?: number; + maxLength?: number; +} + +export interface IDoubleProperty extends IProperty { + defaultValue?: number; + validator?: IDoubleDomainValidator; +} + +export interface IDoubleDomainValidator extends IConcept { + lower?: number; + upper?: number; +} + +export interface IIntegerProperty extends IProperty { + defaultValue?: number; + validator?: IIntegerDomainValidator; +} + +export interface IIntegerDomainValidator extends IConcept { + lower?: number; + upper?: number; +} + +export interface ILongProperty extends IProperty { + defaultValue?: number; + validator?: ILongDomainValidator; +} + +export interface ILongDomainValidator extends IConcept { + lower?: number; + upper?: number; +} + +export interface IAliasedType extends IConcept { + name: string; + aliasedName: string; +} + +export interface IImport extends IConcept { + namespace: string; + uri?: string; +} + +export type ImportUnion = IImportAll | +IImportType | +IImportTypes; + +export interface IImportAll extends IImport { +} + +export interface IImportType extends IImport { + name: string; +} + +export interface IImportTypes extends IImport { + types: string[]; + aliasedTypes?: IAliasedType[]; +} + +export interface IModel extends IConcept { + namespace: string; + sourceUri?: string; + concertoVersion?: string; + imports?: IImport[]; + declarations?: IDeclaration[]; + decorators?: IDecorator[]; +} + +export interface IModels extends IConcept { + models: IModel[]; +} + +export interface IScalarDeclaration extends IDeclaration { +} + +export type ScalarDeclarationUnion = IBooleanScalar | +IIntegerScalar | +ILongScalar | +IDoubleScalar | +IStringScalar | +IDateTimeScalar; + +export interface IBooleanScalar extends IScalarDeclaration { + defaultValue?: boolean; +} + +export interface IIntegerScalar extends IScalarDeclaration { + defaultValue?: number; + validator?: IIntegerDomainValidator; +} + +export interface ILongScalar extends IScalarDeclaration { + defaultValue?: number; + validator?: ILongDomainValidator; +} + +export interface IDoubleScalar extends IScalarDeclaration { + defaultValue?: number; + validator?: IDoubleDomainValidator; +} + +export interface IStringScalar extends IScalarDeclaration { + defaultValue?: string; + validator?: IStringRegexValidator; + lengthValidator?: IStringLengthValidator; +} + +export interface IDateTimeScalar extends IScalarDeclaration { + defaultValue?: string; +} + diff --git a/packages/markdown-common/types/model/index.d.ts b/packages/markdown-common/types/model/index.d.ts new file mode 100644 index 00000000..f5d48bff --- /dev/null +++ b/packages/markdown-common/types/model/index.d.ts @@ -0,0 +1,5 @@ +export * from './concerto-base'; +export * from './concerto-metamodel'; +export * from './commonmark'; +export * from './ciceromark'; +export * from './templatemark'; diff --git a/packages/markdown-common/types/model/templatemark.d.ts b/packages/markdown-common/types/model/templatemark.d.ts new file mode 100644 index 00000000..f8c77352 --- /dev/null +++ b/packages/markdown-common/types/model/templatemark.d.ts @@ -0,0 +1,122 @@ +// Generated code for namespace: org.accordproject.templatemark@0.5.0 + +// imports + +// Warning: Beware of circular dependencies when modifying these imports + +// Warning: Beware of circular dependencies when modifying these imports + +// Warning: Beware of circular dependencies when modifying these imports +import {IChild,INode} from './commonmark'; +import {IDecorator} from './concerto-metamodel'; +import {IConcept} from './concerto-base'; + +// interfaces +export enum CodeType { + TYPESCRIPT = 'TYPESCRIPT', + ES_2020 = 'ES_2020', +} + +export interface ICode extends IConcept { + type: CodeType; + contents: string; +} + +export interface IElementDefinition extends IChild { + name: string; + elementType?: string; + decorators?: IDecorator[]; +} + +export type ElementDefinitionUnion = IVariableDefinition | +IFormulaDefinition | +IBlockDefinition; + +export interface IVariableDefinition extends IElementDefinition { + identifiedBy?: string; +} + +export type VariableDefinitionUnion = IFormattedVariableDefinition | +IEnumVariableDefinition; + +export interface IFormattedVariableDefinition extends IVariableDefinition { + format: string; +} + +export interface IEnumVariableDefinition extends IVariableDefinition { + enumValues: string[]; +} + +export interface IFormulaDefinition extends IElementDefinition { + dependencies?: string[]; + code: ICode; +} + +export interface IBlockDefinition extends IElementDefinition { +} + +export type BlockDefinitionUnion = IClauseDefinition | +IContractDefinition | +IWithDefinition | +IConditionalDefinition | +IOptionalDefinition | +IJoinDefinition | +IListBlockDefinition | +IForeachBlockDefinition | +IWithBlockDefinition | +IConditionalBlockDefinition | +IOptionalBlockDefinition; + +export interface IClauseDefinition extends IBlockDefinition { + condition?: ICode; +} + +export interface IContractDefinition extends IBlockDefinition { +} + +export interface IWithDefinition extends IBlockDefinition { +} + +export interface IConditionalDefinition extends IBlockDefinition { + whenTrue: IChild[]; + whenFalse: IChild[]; + condition?: ICode; + dependencies?: string[]; +} + +export interface IOptionalDefinition extends IBlockDefinition { + whenSome: IChild[]; + whenNone: IChild[]; +} + +export interface IJoinDefinition extends IBlockDefinition { + separator?: string; + locale?: string; + type?: string; + style?: string; +} + +export interface IListBlockDefinition extends IBlockDefinition { + type: string; + tight: string; + start?: string; + delimiter?: string; +} + +export interface IForeachBlockDefinition extends IBlockDefinition { +} + +export interface IWithBlockDefinition extends IBlockDefinition { +} + +export interface IConditionalBlockDefinition extends IBlockDefinition { + whenTrue: IChild[]; + whenFalse: IChild[]; + condition?: ICode; +} + +export interface IOptionalBlockDefinition extends IBlockDefinition { + whenSome: IChild[]; + whenNone: IChild[]; +} + diff --git a/packages/markdown-html/package.json b/packages/markdown-html/package.json index dc07d6ad..b847fd65 100644 --- a/packages/markdown-html/package.json +++ b/packages/markdown-html/package.json @@ -3,7 +3,7 @@ "version": "0.16.25", "description": "Transform CiceroDOM to HTML", "engines": { - "node": ">=18", + "node": ">=22", "npm": ">=9" }, "publishConfig": { diff --git a/packages/markdown-html/src/HtmlTransformer.js b/packages/markdown-html/src/HtmlTransformer.js index e0231bb8..56681de7 100644 --- a/packages/markdown-html/src/HtmlTransformer.js +++ b/packages/markdown-html/src/HtmlTransformer.js @@ -14,6 +14,10 @@ 'use strict'; +/** @typedef {import('@accordproject/markdown-common/types/model/commonmark').IDocument} IDocument */ +/** @typedef {import('@accordproject/concerto-core').Typed} Typed */ +/** @typedef {IDocument|Typed} HtmlInput */ + const ToHtmlStringVisitor = require('./ToHtmlStringVisitor'); const ToCiceroMarkVisitor = require('./ToCiceroMarkVisitor'); const CiceroMarkTransformer = require('@accordproject/markdown-cicero').CiceroMarkTransformer; @@ -34,7 +38,7 @@ class HtmlTransformer { /** * Converts a CiceroMark DOM to an html string - * @param {*} input - CiceroMark DOM object + * @param {HtmlInput} input - CiceroMark DOM object * @returns {string} the html string */ toHtml(input) { @@ -55,7 +59,7 @@ class HtmlTransformer { /** * Converts an html string to a CiceroMark DOM * @param {string} input - html string - * @returns {*} CiceroMark DOM + * @returns {IDocument} CiceroMark DOM */ toCiceroMark(input) { const visitor = new ToCiceroMarkVisitor(this.options); @@ -63,4 +67,4 @@ class HtmlTransformer { } } -module.exports = HtmlTransformer; \ No newline at end of file +module.exports = HtmlTransformer; diff --git a/packages/markdown-html/types/lib/HtmlTransformer.d.ts b/packages/markdown-html/types/lib/HtmlTransformer.d.ts index 49e4c0a1..e19d5f2d 100644 --- a/packages/markdown-html/types/lib/HtmlTransformer.d.ts +++ b/packages/markdown-html/types/lib/HtmlTransformer.d.ts @@ -12,14 +12,20 @@ declare class HtmlTransformer { ciceroMarkTransformer: import("@accordproject/markdown-cicero/types/lib/CiceroMarkTransformer"); /** * Converts a CiceroMark DOM to an html string - * @param {*} input - CiceroMark DOM object + * @param {HtmlInput} input - CiceroMark DOM object * @returns {string} the html string */ - toHtml(input: any): string; + toHtml(input: HtmlInput): string; /** * Converts an html string to a CiceroMark DOM * @param {string} input - html string - * @returns {*} CiceroMark DOM + * @returns {IDocument} CiceroMark DOM */ - toCiceroMark(input: string): any; + toCiceroMark(input: string): IDocument; } +declare namespace HtmlTransformer { + export { IDocument, Typed, HtmlInput }; +} +type IDocument = import("@accordproject/markdown-common/types/model/commonmark").IDocument; +type Typed = import("@accordproject/concerto-core").Typed; +type HtmlInput = IDocument | Typed; diff --git a/packages/markdown-it-cicero/package.json b/packages/markdown-it-cicero/package.json index f62ece78..77da336e 100644 --- a/packages/markdown-it-cicero/package.json +++ b/packages/markdown-it-cicero/package.json @@ -3,7 +3,7 @@ "version": "0.16.25", "description": "Plugin to introduce cicero blocks and inlines for the markdown-it markdown parser", "engines": { - "node": ">=18", + "node": ">=22", "npm": ">=9" }, "publishConfig": { diff --git a/packages/markdown-it-template/package.json b/packages/markdown-it-template/package.json index 16963790..297cffc4 100644 --- a/packages/markdown-it-template/package.json +++ b/packages/markdown-it-template/package.json @@ -3,7 +3,7 @@ "version": "0.16.25", "description": "Plugin to introduce template blocks and inlines for the markdown-it markdown parser", "engines": { - "node": ">=18", + "node": ">=22", "npm": ">=9" }, "publishConfig": { diff --git a/packages/markdown-template/lib/TemplateMarkTransformer.js b/packages/markdown-template/lib/TemplateMarkTransformer.js index 675d27ef..5dda0419 100644 --- a/packages/markdown-template/lib/TemplateMarkTransformer.js +++ b/packages/markdown-template/lib/TemplateMarkTransformer.js @@ -14,6 +14,7 @@ 'use strict'; +/** @typedef {import('@accordproject/concerto-core').Serializer} Serializer */ var { templateMarkManager, templateToTokens, @@ -93,7 +94,7 @@ class TemplateMarkTransformer { /** * Get TemplateMark serializer - * @return {*} templatemark serializer + * @return {Serializer} templatemark serializer */ getSerializer() { return templateMarkManager.serializer; diff --git a/packages/markdown-template/package.json b/packages/markdown-template/package.json index d4847910..5d7ab7f6 100644 --- a/packages/markdown-template/package.json +++ b/packages/markdown-template/package.json @@ -3,7 +3,7 @@ "version": "0.16.25", "description": "A framework for transforming markdown", "engines": { - "node": ">=18", + "node": ">=22", "npm": ">=9" }, "publishConfig": { diff --git a/packages/markdown-template/src/TemplateMarkTransformer.js b/packages/markdown-template/src/TemplateMarkTransformer.js index f42b1c82..e7cbc35f 100644 --- a/packages/markdown-template/src/TemplateMarkTransformer.js +++ b/packages/markdown-template/src/TemplateMarkTransformer.js @@ -14,6 +14,8 @@ 'use strict'; +/** @typedef {import('@accordproject/concerto-core').Serializer} Serializer */ + const { templateMarkManager, templateToTokens, @@ -95,11 +97,11 @@ class TemplateMarkTransformer { /** * Get TemplateMark serializer - * @return {*} templatemark serializer + * @return {Serializer} templatemark serializer */ getSerializer() { return templateMarkManager.serializer; } } -module.exports = TemplateMarkTransformer; \ No newline at end of file +module.exports = TemplateMarkTransformer; diff --git a/packages/markdown-template/types/lib/TemplateMarkTransformer.d.ts b/packages/markdown-template/types/lib/TemplateMarkTransformer.d.ts index 6f7ade3c..d2409c8c 100644 --- a/packages/markdown-template/types/lib/TemplateMarkTransformer.d.ts +++ b/packages/markdown-template/types/lib/TemplateMarkTransformer.d.ts @@ -46,7 +46,11 @@ declare class TemplateMarkTransformer { toMarkdownTemplate(input: object): string; /** * Get TemplateMark serializer - * @return {*} templatemark serializer + * @return {Serializer} templatemark serializer */ - getSerializer(): any; + getSerializer(): Serializer; } +declare namespace TemplateMarkTransformer { + export { Serializer }; +} +type Serializer = import("@accordproject/concerto-core").Serializer; diff --git a/packages/markdown-transform/lib/transform.js b/packages/markdown-transform/lib/transform.js index 3d741926..b17cf423 100644 --- a/packages/markdown-transform/lib/transform.js +++ b/packages/markdown-transform/lib/transform.js @@ -21,7 +21,7 @@ const builtinTransformationGraph = require('./builtinTransforms'); * Create a new transformation engine * * @param {object} transformationGraph - initial transformation graph - * @return {*} the transformation engine + * @return {TransformEngine} the transformation engine */ function createTransformationEngine(transformationGraph) { return new TransformEngine(transformationGraph); @@ -30,9 +30,31 @@ module.exports.createTransformationEngine; /** * This is instantiated here for backward compatibility + * @type {TransformEngine} */ const builtinEngine = createTransformationEngine(builtinTransformationGraph); module.exports.builtinEngine = builtinEngine; + +/** + * Return the format descriptor for a given format + * @param {string} format the format + * @returns {object} the descriptor for that format + */ module.exports.formatDescriptor = format => builtinEngine.formatDescriptor(format); + +/** + * Transforms from a source format to a list of destination formats. + * @param {object|string} source the input for the transformation + * @param {string} sourceFormat the input format + * @param {string[]} destinationFormat the destination format as an array + * @param {object} [parameters] the transform parameters + * @param {object} [options] the transform options + * @returns {Promise} result of the transformation + */ module.exports.transform = (source, sourceFormat, destinationFormat, parameters, options) => builtinEngine.transform(source, sourceFormat, destinationFormat, parameters, options); + +/** + * Converts the transformation graph into a PlantUML diagram string + * @returns {string} the PlantUML string + */ module.exports.generateTransformationDiagram = () => builtinEngine.generateTransformationDiagram(); \ No newline at end of file diff --git a/packages/markdown-transform/lib/transformEngine.js b/packages/markdown-transform/lib/transformEngine.js index 94821f1d..8b293b15 100644 --- a/packages/markdown-transform/lib/transformEngine.js +++ b/packages/markdown-transform/lib/transformEngine.js @@ -93,13 +93,13 @@ hide empty description * Transforms from a source format to a single destination format or * throws an exception if the transformation is not possible. * - * @param {*} source the input for the transformation + * @param {object|string} source the input for the transformation * @param {string} sourceFormat the input format * @param {string} destinationFormat the destination format - * @param {object} parameters the transform parameters + * @param {object} [parameters] the transform parameters * @param {object} [options] the transform options * @param {boolean} [options.verbose] output verbose console logs - * @returns {*} result of the transformation + * @returns {Promise} result of the transformation */ async transformToDestination(source, sourceFormat, destinationFormat, parameters, options) { let result = source; @@ -131,14 +131,14 @@ hide empty description * Transforms from a source format to a list of destination formats, or * throws an exception if the transformation is not possible. * - * @param {*} source the input for the transformation + * @param {object|string} source the input for the transformation * @param {string} sourceFormat the input format * @param {string[]} destinationFormat the destination format as an array, * the transformation are applied in order to reach all formats in the array - * @param {object} parameters the transform parameters + * @param {object} [parameters] the transform parameters * @param {object} [options] the transform options * @param {boolean} [options.verbose] output verbose console logs - * @returns {Promise} result of the transformation + * @returns {Promise} result of the transformation */ async transform(source, sourceFormat, destinationFormat, parameters, options) { let result = source; @@ -233,7 +233,7 @@ hide empty description * * @param {string} sourceFormat - the name of the source format * @param {string} targetFormat - the name of the targetFormat format - * @param {*} transform - the transform (an async function to transform from sourceFormat to targetFormat) + * @param {Function} transform - the transform (an async function to transform from sourceFormat to targetFormat) */ registerTransformation(sourceFormat, targetFormat, transform) { const transformationGraph = this.getTransformationGraph(); @@ -250,7 +250,7 @@ hide empty description /** * Register a transform extension - * @param {*} extension - the transform extension, including format and transforms + * @param {object} extension - the transform extension, including format and transforms */ registerExtension(extension) { if (extension.format) { diff --git a/packages/markdown-transform/package.json b/packages/markdown-transform/package.json index 4036ce4a..423c4a2c 100644 --- a/packages/markdown-transform/package.json +++ b/packages/markdown-transform/package.json @@ -3,7 +3,7 @@ "version": "0.16.25", "description": "API for transforming markdown data", "engines": { - "node": ">=18", + "node": ">=22", "npm": ">=9" }, "publishConfig": { diff --git a/packages/markdown-transform/src/transform.js b/packages/markdown-transform/src/transform.js index 175873e1..1e5d8f16 100644 --- a/packages/markdown-transform/src/transform.js +++ b/packages/markdown-transform/src/transform.js @@ -21,7 +21,7 @@ const builtinTransformationGraph = require('./builtinTransforms'); * Create a new transformation engine * * @param {object} transformationGraph - initial transformation graph - * @return {*} the transformation engine + * @return {TransformEngine} the transformation engine */ function createTransformationEngine(transformationGraph) { return new TransformEngine(transformationGraph); @@ -31,11 +31,28 @@ module.exports.createTransformationEngine; /** * This is instantiated here for backward compatibility + * @type {TransformEngine} */ const builtinEngine = createTransformationEngine(builtinTransformationGraph); module.exports.builtinEngine = builtinEngine; + +/** + * Return the format descriptor for a given format + * @param {string} format the format + * @returns {object} the descriptor for that format + */ module.exports.formatDescriptor = (format) => builtinEngine.formatDescriptor(format); + +/** + * Transforms from a source format to a list of destination formats. + * @param {object|string} source the input for the transformation + * @param {string} sourceFormat the input format + * @param {string[]} destinationFormat the destination format as an array + * @param {object} [parameters] the transform parameters + * @param {object} [options] the transform options + * @returns {Promise} result of the transformation + */ module.exports.transform = ( source, sourceFormat, @@ -43,4 +60,9 @@ module.exports.transform = ( parameters, options ) => builtinEngine.transform(source, sourceFormat, destinationFormat, parameters, options); + +/** + * Converts the transformation graph into a PlantUML diagram string + * @returns {string} the PlantUML string + */ module.exports.generateTransformationDiagram = () => builtinEngine.generateTransformationDiagram(); diff --git a/packages/markdown-transform/src/transformEngine.js b/packages/markdown-transform/src/transformEngine.js index f593bd57..405a58b3 100644 --- a/packages/markdown-transform/src/transformEngine.js +++ b/packages/markdown-transform/src/transformEngine.js @@ -92,13 +92,13 @@ hide empty description * Transforms from a source format to a single destination format or * throws an exception if the transformation is not possible. * - * @param {*} source the input for the transformation + * @param {object|string} source the input for the transformation * @param {string} sourceFormat the input format * @param {string} destinationFormat the destination format - * @param {object} parameters the transform parameters + * @param {object} [parameters] the transform parameters * @param {object} [options] the transform options * @param {boolean} [options.verbose] output verbose console logs - * @returns {*} result of the transformation + * @returns {Promise} result of the transformation */ async transformToDestination(source, sourceFormat, destinationFormat, parameters, options) { let result = source; @@ -133,14 +133,14 @@ hide empty description * Transforms from a source format to a list of destination formats, or * throws an exception if the transformation is not possible. * - * @param {*} source the input for the transformation + * @param {object|string} source the input for the transformation * @param {string} sourceFormat the input format * @param {string[]} destinationFormat the destination format as an array, * the transformation are applied in order to reach all formats in the array - * @param {object} parameters the transform parameters + * @param {object} [parameters] the transform parameters * @param {object} [options] the transform options * @param {boolean} [options.verbose] output verbose console logs - * @returns {Promise} result of the transformation + * @returns {Promise} result of the transformation */ async transform(source, sourceFormat, destinationFormat, parameters, options) { let result = source; @@ -233,7 +233,7 @@ hide empty description * * @param {string} sourceFormat - the name of the source format * @param {string} targetFormat - the name of the targetFormat format - * @param {*} transform - the transform (an async function to transform from sourceFormat to targetFormat) + * @param {Function} transform - the transform (an async function to transform from sourceFormat to targetFormat) */ registerTransformation(sourceFormat, targetFormat, transform) { const transformationGraph = this.getTransformationGraph(); @@ -250,7 +250,7 @@ hide empty description /** * Register a transform extension - * @param {*} extension - the transform extension, including format and transforms + * @param {object} extension - the transform extension, including format and transforms */ registerExtension(extension) { if (extension.format) { diff --git a/packages/markdown-transform/types/index.d.ts b/packages/markdown-transform/types/index.d.ts index fc8c5bcf..562550ef 100644 --- a/packages/markdown-transform/types/index.d.ts +++ b/packages/markdown-transform/types/index.d.ts @@ -1,5 +1,5 @@ -export const formatDescriptor: (format: any) => any; -export const transform: (source: any, sourceFormat: any, destinationFormat: any, parameters: any, options: any) => any; +export const formatDescriptor: (format: string) => object; +export const transform: (source: object | string, sourceFormat: string, destinationFormat: string[], parameters?: object, options?: object) => Promise; export const TransformEngine: typeof import("./lib/transformEngine"); export const builtinTransformationGraph: { markdown_template: { @@ -20,43 +20,43 @@ export const builtinTransformationGraph: { markdown: { docs: string; fileFormat: string; - commonmark_tokens: (input: any, parameters: any, options: any) => any; + commonmark_tokens: (input: any, parameters: any, options: any) => object[]; }; commonmark_tokens: { docs: string; fileFormat: string; - commonmark: (input: any, parameters: any, options: any) => Promise; + commonmark: (input: any, parameters: any, options: any) => Promise; }; markdown_cicero: { docs: string; fileFormat: string; - ciceromark_tokens: (input: any, parameters: any, options: any) => any; + ciceromark_tokens: (input: any, parameters: any, options: any) => object[]; }; ciceromark_tokens: { docs: string; fileFormat: string; - ciceromark: (input: any, parameters: any, options: any) => Promise; + ciceromark: (input: any, parameters: any, options: any) => Promise; }; commonmark: { docs: string; fileFormat: string; markdown: (input: any, parameters: any, options: any) => string; - ciceromark: (input: any, parameters: any, options: any) => any; + ciceromark: (input: any, parameters: any, options: any) => import("@accordproject/markdown-common/types/model/commonmark").IDocument; plaintext: (input: any, parameters: any, options: any) => string; }; ciceromark: { docs: string; fileFormat: string; markdown_cicero: (input: any, parameters: any, options: any) => string; - commonmark: (input: any, parameters: any, options: any) => any; + commonmark: (input: any, parameters: any, options: any) => import("@accordproject/markdown-common/types/model/commonmark").IDocument; ciceromark_parsed: (input: any, parameters: any, options: any) => any; }; ciceromark_parsed: { docs: string; fileFormat: string; html: (input: any, parameters: any, options: any) => string; - ciceromark: (input: any, parameters: any, options: any) => any; - ciceromark_unquoted: (input: any, parameters: any, options: any) => object; + ciceromark: (input: any, parameters: any, options: any) => import("@accordproject/markdown-common/types/model/commonmark").IDocument; + ciceromark_unquoted: (input: any, parameters: any, options: any) => import("@accordproject/markdown-common/types/model/commonmark").IDocument; }; plaintext: { docs: string; @@ -66,7 +66,7 @@ export const builtinTransformationGraph: { ciceroedit: { docs: string; fileFormat: string; - ciceromark_parsed: (input: any, parameters: any, options: any) => any; + ciceromark_parsed: (input: any, parameters: any, options: any) => import("@accordproject/markdown-common/types/model/commonmark").IDocument; }; ciceromark_unquoted: { docs: string; @@ -76,6 +76,6 @@ export const builtinTransformationGraph: { html: { docs: string; fileFormat: string; - ciceromark_parsed: (input: any, parameters: any, options: any) => any; + ciceromark_parsed: (input: any, parameters: any, options: any) => object; }; }; diff --git a/packages/markdown-transform/types/lib/builtinTransforms.d.ts b/packages/markdown-transform/types/lib/builtinTransforms.d.ts index eee1b36c..4c09c76e 100644 --- a/packages/markdown-transform/types/lib/builtinTransforms.d.ts +++ b/packages/markdown-transform/types/lib/builtinTransforms.d.ts @@ -23,28 +23,28 @@ export declare namespace markdown { export { docs_3 as docs }; let fileFormat_3: string; export { fileFormat_3 as fileFormat }; - export function commonmark_tokens(input: any, parameters: any, options: any): any; + export function commonmark_tokens(input: any, parameters: any, options: any): object[]; } export declare namespace commonmark_tokens_1 { let docs_4: string; export { docs_4 as docs }; let fileFormat_4: string; export { fileFormat_4 as fileFormat }; - export function commonmark(input: any, parameters: any, options: any): Promise; + export function commonmark(input: any, parameters: any, options: any): Promise; } export declare namespace markdown_cicero { let docs_5: string; export { docs_5 as docs }; let fileFormat_5: string; export { fileFormat_5 as fileFormat }; - export function ciceromark_tokens(input: any, parameters: any, options: any): any; + export function ciceromark_tokens(input: any, parameters: any, options: any): object[]; } export declare namespace ciceromark_tokens_1 { let docs_6: string; export { docs_6 as docs }; let fileFormat_6: string; export { fileFormat_6 as fileFormat }; - export function ciceromark(input: any, parameters: any, options: any): Promise; + export function ciceromark(input: any, parameters: any, options: any): Promise; } export declare namespace commonmark_1 { let docs_7: string; @@ -53,7 +53,7 @@ export declare namespace commonmark_1 { export { fileFormat_7 as fileFormat }; export function markdown_1(input: any, parameters: any, options: any): string; export { markdown_1 as markdown }; - export function ciceromark_1(input: any, parameters: any, options: any): any; + export function ciceromark_1(input: any, parameters: any, options: any): import("@accordproject/markdown-common/types/model/commonmark").IDocument; export { ciceromark_1 as ciceromark }; export function plaintext(input: any, parameters: any, options: any): string; } @@ -64,7 +64,7 @@ export declare namespace ciceromark_2 { export { fileFormat_8 as fileFormat }; export function markdown_cicero_1(input: any, parameters: any, options: any): string; export { markdown_cicero_1 as markdown_cicero }; - export function commonmark_2(input: any, parameters: any, options: any): any; + export function commonmark_2(input: any, parameters: any, options: any): import("@accordproject/markdown-common/types/model/commonmark").IDocument; export { commonmark_2 as commonmark }; export function ciceromark_parsed(input: any, parameters: any, options: any): any; } @@ -74,9 +74,9 @@ export declare namespace ciceromark_parsed_1 { let fileFormat_9: string; export { fileFormat_9 as fileFormat }; export function html(input: any, parameters: any, options: any): string; - export function ciceromark_3(input: any, parameters: any, options: any): any; + export function ciceromark_3(input: any, parameters: any, options: any): import("@accordproject/markdown-common/types/model/commonmark").IDocument; export { ciceromark_3 as ciceromark }; - export function ciceromark_unquoted(input: any, parameters: any, options: any): object; + export function ciceromark_unquoted(input: any, parameters: any, options: any): import("@accordproject/markdown-common/types/model/commonmark").IDocument; } export declare namespace plaintext_1 { let docs_10: string; @@ -91,7 +91,7 @@ export declare namespace ciceroedit { export { docs_11 as docs }; let fileFormat_11: string; export { fileFormat_11 as fileFormat }; - export function ciceromark_parsed_2(input: any, parameters: any, options: any): any; + export function ciceromark_parsed_2(input: any, parameters: any, options: any): import("@accordproject/markdown-common/types/model/commonmark").IDocument; export { ciceromark_parsed_2 as ciceromark_parsed }; } export declare namespace ciceromark_unquoted_1 { @@ -107,7 +107,7 @@ export declare namespace html_1 { export { docs_13 as docs }; let fileFormat_13: string; export { fileFormat_13 as fileFormat }; - export function ciceromark_parsed_4(input: any, parameters: any, options: any): any; + export function ciceromark_parsed_4(input: any, parameters: any, options: any): object; export { ciceromark_parsed_4 as ciceromark_parsed }; } export { templatemark_tokens_1 as templatemark_tokens, templatemark_1 as templatemark, commonmark_tokens_1 as commonmark_tokens, ciceromark_tokens_1 as ciceromark_tokens, commonmark_1 as commonmark, ciceromark_2 as ciceromark, ciceromark_parsed_1 as ciceromark_parsed, plaintext_1 as plaintext, ciceromark_unquoted_1 as ciceromark_unquoted, html_1 as html }; diff --git a/packages/markdown-transform/types/lib/transform.d.ts b/packages/markdown-transform/types/lib/transform.d.ts index c8f46a77..5ab0d696 100644 --- a/packages/markdown-transform/types/lib/transform.d.ts +++ b/packages/markdown-transform/types/lib/transform.d.ts @@ -1,7 +1,9 @@ -export function formatDescriptor(format: any): any; -export function transform(source: any, sourceFormat: any, destinationFormat: any, parameters: any, options: any): any; -export function generateTransformationDiagram(): any; +export function formatDescriptor(format: string): object; +export function transform(source: object | string, sourceFormat: string, destinationFormat: string[], parameters?: object, options?: object): Promise; +export function generateTransformationDiagram(): string; /** * This is instantiated here for backward compatibility + * @type {TransformEngine} */ -export const builtinEngine: any; +export const builtinEngine: TransformEngine; +import TransformEngine = require("./transformEngine"); diff --git a/packages/markdown-transform/types/lib/transformEngine.d.ts b/packages/markdown-transform/types/lib/transformEngine.d.ts index 446fd11e..232566c8 100644 --- a/packages/markdown-transform/types/lib/transformEngine.d.ts +++ b/packages/markdown-transform/types/lib/transformEngine.d.ts @@ -30,33 +30,33 @@ declare class TransformEngine { * Transforms from a source format to a single destination format or * throws an exception if the transformation is not possible. * - * @param {*} source the input for the transformation + * @param {object|string} source the input for the transformation * @param {string} sourceFormat the input format * @param {string} destinationFormat the destination format - * @param {object} parameters the transform parameters + * @param {object} [parameters] the transform parameters * @param {object} [options] the transform options * @param {boolean} [options.verbose] output verbose console logs - * @returns {*} result of the transformation + * @returns {Promise} result of the transformation */ - transformToDestination(source: any, sourceFormat: string, destinationFormat: string, parameters: object, options?: { + transformToDestination(source: object | string, sourceFormat: string, destinationFormat: string, parameters?: object, options?: { verbose?: boolean; - }): any; + }): Promise; /** * Transforms from a source format to a list of destination formats, or * throws an exception if the transformation is not possible. * - * @param {*} source the input for the transformation + * @param {object|string} source the input for the transformation * @param {string} sourceFormat the input format * @param {string[]} destinationFormat the destination format as an array, * the transformation are applied in order to reach all formats in the array - * @param {object} parameters the transform parameters + * @param {object} [parameters] the transform parameters * @param {object} [options] the transform options * @param {boolean} [options.verbose] output verbose console logs - * @returns {Promise} result of the transformation + * @returns {Promise} result of the transformation */ - transform(source: any, sourceFormat: string, destinationFormat: string[], parameters: object, options?: { + transform(source: object | string, sourceFormat: string, destinationFormat: string[], parameters?: object, options?: { verbose?: boolean; - }): Promise; + }): Promise; /** * Return the format descriptor for a given format * @@ -96,14 +96,14 @@ declare class TransformEngine { * * @param {string} sourceFormat - the name of the source format * @param {string} targetFormat - the name of the targetFormat format - * @param {*} transform - the transform (an async function to transform from sourceFormat to targetFormat) + * @param {Function} transform - the transform (an async function to transform from sourceFormat to targetFormat) */ - registerTransformation(sourceFormat: string, targetFormat: string, transform: any): void; + registerTransformation(sourceFormat: string, targetFormat: string, transform: Function): void; /** * Register a transform extension - * @param {*} extension - the transform extension, including format and transforms + * @param {object} extension - the transform extension, including format and transforms */ - registerExtension(extension: any): void; + registerExtension(extension: object): void; /** * Refresh raw graph * @private