diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4232056..5ee3f7c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,27 +15,23 @@ on: jobs: build: runs-on: ubuntu-latest + permissions: + contents: read + id-token: write # The OIDC ID token is used for authentication with JSR. steps: - - uses: actions/checkout@v1 - - uses: actions/setup-node@v1 + - uses: actions/checkout@v4 + - uses: denoland/setup-deno@v2 with: - node-version: 16 - registry-url: https://registry.npmjs.org/ - - uses: denoland/setup-deno@v1 - with: - deno-version: v1.40 + deno-version: v2.x - name: Run tests run: deno test test/**/*.test.ts - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v5 with: - go-version: "1.21" - - - name: Bundle module and dependencies - run: deno bundle src/mod.ts bundle.js + go-version: "1.24" - name: Install Apex CLI - run: deno install -A -f -n apex https://deno.land/x/apex_cli@v0.1.2/apex.ts + run: deno install -g -A --unstable-worker-options -f -n apex jsr:@apexlang/apex - name: Install Protoc run: | @@ -59,3 +55,11 @@ jobs: - name: Validate generated OpenAPI run: find . -name 'openapi.yaml' -exec swagger-cli validate {} \; working-directory: ./testdata + + - name: Is Release? + if: startswith(github.ref, 'refs/tags/v') + run: echo "DEPLOY_PACKAGE=true" >> $GITHUB_ENV + + - name: Publish to npm + if: env.DEPLOY_PACKAGE == 'true' + run: npx jsr publish diff --git a/.github/workflows/release.ts b/.github/workflows/release.ts new file mode 100644 index 0000000..3a8da48 --- /dev/null +++ b/.github/workflows/release.ts @@ -0,0 +1,20 @@ +function env(name: string): string { + const val = Deno.env.get(name); + if (!val) throw new Error(`$${name} is required`); + return val; +} + +const version = env("VERSION"); + +if (!version.match(/^v\d+\.\d+\.\d+$/)) { + throw new Error("VERSION must be in the form v1.2.3"); +} + +console.log("Updating versions in files"); + +for (const file of ["jsr.json", "deno.json"]) { + console.log(`Updating ${file} for ${version}...`); + const orig = Deno.readTextFileSync(file); + const updated = orig.replace(/\d+\.\d+\.\d+/, version.substring(1)); + Deno.writeFileSync(file, new TextEncoder().encode(updated)); +} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..066d909 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,37 @@ +name: Release apex version + +on: + workflow_dispatch: + inputs: + version: + description: "Version to release" + required: true + +jobs: + release: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.RELEASE_TOKEN }} + - uses: denoland/setup-deno@v2 + with: + deno-version: v2.x + - name: Update version and README.md + env: + VERSION: ${{ inputs.version }} + run: | + deno run --allow-run --allow-env --allow-write --allow-read ./.github/workflows/release.ts + - name: Commit and tag release + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: ${{ inputs.version }} release + tagging_message: ${{ inputs.version }} + - name: Create Release + uses: ncipollo/release-action@v1.12.0 + with: + generateReleaseNotes: true + makeLatest: true + tag: ${{ inputs.version }} diff --git a/deno.json b/deno.json new file mode 100644 index 0000000..d02224d --- /dev/null +++ b/deno.json @@ -0,0 +1,37 @@ +{ + "name": "@apexlang/codegen", + "version": "0.1.10", + "description": "Code generators for Apex.", + "keywords": ["apex", "idl", "codegen"], + "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://www.github.com/apexlang/codegen" + }, + "bugs": { + "url": "https://www.github.com/apexlang/codegen/issues" + }, + "imports": { + "@apexlang/apex": "jsr:@apexlang/apex@^0.2.0", + "@apexlang/core": "jsr:@apexlang/core@^0.2.0", + "@std/assert": "jsr:@std/assert@^1.0.11", + "@std/yaml": "jsr:@std/yaml@^1.0.5" + }, + "exports": { + "./cs": "./src/cs/mod.ts", + "./go": "./src/go/mod.ts", + "./json-schema": "./src/json-schema/mod.ts", + "./markdown": "./src/markdown/mod.ts", + "./openapiv3": "./src/openapiv3/mod.ts", + "./proto": "./src/proto/mod.ts", + "./python": "./src/python/mod.ts", + "./rest": "./src/rest/mod.ts", + "./rust": "./src/rust/mod.ts", + "./typescript": "./src/typescript/mod.ts", + "./utils": "./src/utils/mod.ts" + }, + "publish": { + "include": ["LICENSE", "README.md", "templates", "src/**/*.ts"], + "exclude": ["src/tests"] + } +} diff --git a/deno.lock b/deno.lock new file mode 100644 index 0000000..48504be --- /dev/null +++ b/deno.lock @@ -0,0 +1,242 @@ +{ + "version": "4", + "specifiers": { + "jsr:@apexlang/apex@0.2": "0.2.0", + "jsr:@apexlang/core@0.2": "0.2.0", + "jsr:@cliffy/ansi@1.0.0-rc.7": "1.0.0-rc.7", + "jsr:@cliffy/ansi@^1.0.0-rc.7": "1.0.0-rc.7", + "jsr:@cliffy/command@^1.0.0-rc.7": "1.0.0-rc.7", + "jsr:@cliffy/flags@1.0.0-rc.7": "1.0.0-rc.7", + "jsr:@cliffy/internal@1.0.0-rc.7": "1.0.0-rc.7", + "jsr:@cliffy/keycode@1.0.0-rc.7": "1.0.0-rc.7", + "jsr:@cliffy/prompt@^1.0.0-rc.7": "1.0.0-rc.7", + "jsr:@cliffy/table@1.0.0-rc.7": "1.0.0-rc.7", + "jsr:@cliffy/table@^1.0.0-rc.7": "1.0.0-rc.7", + "jsr:@david/dax@0.42": "0.42.0", + "jsr:@david/path@0.2": "0.2.0", + "jsr:@david/which@~0.4.1": "0.4.1", + "jsr:@eta-dev/eta@^3.5.0": "3.5.0", + "jsr:@fmt/biome-fmt@~0.1.13": "0.1.13", + "jsr:@fmt/clang-format@^19.1.7": "19.1.7", + "jsr:@fmt/gofmt@~0.4.9": "0.4.9", + "jsr:@fmt/json-fmt@~0.1.13": "0.1.13", + "jsr:@fmt/ruff-fmt@~0.9.4": "0.9.4", + "jsr:@std/assert@0.221": "0.221.0", + "jsr:@std/assert@^1.0.11": "1.0.11", + "jsr:@std/assert@~1.0.6": "1.0.11", + "jsr:@std/bytes@0.221": "0.221.0", + "jsr:@std/bytes@^1.0.5": "1.0.5", + "jsr:@std/encoding@~1.0.5": "1.0.7", + "jsr:@std/fmt@1": "1.0.5", + "jsr:@std/fmt@^1.0.5": "1.0.5", + "jsr:@std/fmt@~1.0.2": "1.0.5", + "jsr:@std/fs@1": "1.0.13", + "jsr:@std/fs@^1.0.11": "1.0.13", + "jsr:@std/fs@^1.0.13": "1.0.13", + "jsr:@std/internal@^1.0.5": "1.0.5", + "jsr:@std/io@0.221": "0.221.0", + "jsr:@std/io@~0.224.9": "0.224.9", + "jsr:@std/io@~0.225.2": "0.225.2", + "jsr:@std/log@~0.224.14": "0.224.14", + "jsr:@std/path@1": "1.0.8", + "jsr:@std/path@^1.0.8": "1.0.8", + "jsr:@std/path@~1.0.6": "1.0.8", + "jsr:@std/streams@0.221": "0.221.0", + "jsr:@std/text@~1.0.7": "1.0.10", + "jsr:@std/yaml@^1.0.5": "1.0.5" + }, + "jsr": { + "@apexlang/apex@0.2.0": { + "integrity": "bca06465727e5241b293d427a29115bb61dabba1970188acdc65cfe96750172e", + "dependencies": [ + "jsr:@apexlang/core", + "jsr:@cliffy/ansi@^1.0.0-rc.7", + "jsr:@cliffy/command", + "jsr:@cliffy/prompt", + "jsr:@cliffy/table@^1.0.0-rc.7", + "jsr:@david/dax", + "jsr:@eta-dev/eta", + "jsr:@fmt/biome-fmt", + "jsr:@fmt/clang-format", + "jsr:@fmt/gofmt", + "jsr:@fmt/json-fmt", + "jsr:@fmt/ruff-fmt", + "jsr:@std/fs@^1.0.13", + "jsr:@std/io@~0.225.2", + "jsr:@std/log", + "jsr:@std/path@^1.0.8", + "jsr:@std/yaml" + ] + }, + "@apexlang/core@0.2.0": { + "integrity": "f4b8f0721c71b665b6a413d4ea9ece3b9d67843f9d8eca1fe4290c786c8f3247" + }, + "@cliffy/ansi@1.0.0-rc.7": { + "integrity": "f71c921cce224c13d322e5cedba4f38e8f7354c7d855c9cb22729362a53f25aa", + "dependencies": [ + "jsr:@cliffy/internal", + "jsr:@std/encoding", + "jsr:@std/fmt@~1.0.2", + "jsr:@std/io@~0.224.9" + ] + }, + "@cliffy/command@1.0.0-rc.7": { + "integrity": "1288808d7a3cd18b86c24c2f920e47a6d954b7e23cadc35c8cbd78f8be41f0cd", + "dependencies": [ + "jsr:@cliffy/flags", + "jsr:@cliffy/internal", + "jsr:@cliffy/table@1.0.0-rc.7", + "jsr:@std/fmt@~1.0.2", + "jsr:@std/text" + ] + }, + "@cliffy/flags@1.0.0-rc.7": { + "integrity": "318d9be98f6a6417b108e03dec427dea96cdd41a15beb21d2554ae6da450a781", + "dependencies": [ + "jsr:@std/text" + ] + }, + "@cliffy/internal@1.0.0-rc.7": { + "integrity": "10412636ab3e67517d448be9eaab1b70c88eba9be22617b5d146257a11cc9b17" + }, + "@cliffy/keycode@1.0.0-rc.7": { + "integrity": "5b3f6c33994e81a76b79f108b1989642ac22705840da33781f7972d7dff05503" + }, + "@cliffy/prompt@1.0.0-rc.7": { + "integrity": "a9cbd13acd8073558447cae8ca4cf593c09d23bcbe429cc63346920c21187b83", + "dependencies": [ + "jsr:@cliffy/ansi@1.0.0-rc.7", + "jsr:@cliffy/internal", + "jsr:@cliffy/keycode", + "jsr:@std/assert@~1.0.6", + "jsr:@std/fmt@~1.0.2", + "jsr:@std/io@~0.224.9", + "jsr:@std/path@~1.0.6", + "jsr:@std/text" + ] + }, + "@cliffy/table@1.0.0-rc.7": { + "integrity": "9fdd9776eda28a0b397981c400eeb1aa36da2371b43eefe12e6ff555290e3180", + "dependencies": [ + "jsr:@std/fmt@~1.0.2" + ] + }, + "@david/dax@0.42.0": { + "integrity": "0c547c9a20577a6072b90def194c159c9ddab82280285ebfd8268a4ebefbd80b", + "dependencies": [ + "jsr:@david/path", + "jsr:@david/which", + "jsr:@std/fmt@1", + "jsr:@std/fs@1", + "jsr:@std/io@0.221", + "jsr:@std/path@1", + "jsr:@std/streams" + ] + }, + "@david/path@0.2.0": { + "integrity": "f2d7aa7f02ce5a55e27c09f9f1381794acb09d328f8d3c8a2e3ab3ffc294dccd", + "dependencies": [ + "jsr:@std/fs@1", + "jsr:@std/path@1" + ] + }, + "@david/which@0.4.1": { + "integrity": "896a682b111f92ab866cc70c5b4afab2f5899d2f9bde31ed00203b9c250f225e" + }, + "@eta-dev/eta@3.5.0": { + "integrity": "6b70827efc14c7cbf08498ac7a922ecab003641caf3852a6cb5b1b12ee58fb37" + }, + "@fmt/biome-fmt@0.1.13": { + "integrity": "a61e4a2b211876b6ca0070c68222e6b2f3f91d2988b57c7b6c9f89e8c575b050" + }, + "@fmt/clang-format@19.1.7": { + "integrity": "b5c854317057bb0f20fad57f3f7c7ef8aa02ecd4680b615caa9fce67c3cb9cc6" + }, + "@fmt/gofmt@0.4.9": { + "integrity": "3dedec5d3d51795cc7dad8cedef1d56c8e18c96b7c12f08b0394c1d699f344d3" + }, + "@fmt/json-fmt@0.1.13": { + "integrity": "49df80a2dfb2e214edbc9717b6ca1e99b50e4bcf47aa9729891ebe35f72ce41e" + }, + "@fmt/ruff-fmt@0.9.4": { + "integrity": "1e4f106e05f3493fe5ce490c2d27fbb4984f41afc237cf92fa7f2344ed543694" + }, + "@std/assert@0.221.0": { + "integrity": "a5f1aa6e7909dbea271754fd4ab3f4e687aeff4873b4cef9a320af813adb489a" + }, + "@std/assert@1.0.11": { + "integrity": "2461ef3c368fe88bc60e186e7744a93112f16fd110022e113a0849e94d1c83c1", + "dependencies": [ + "jsr:@std/internal" + ] + }, + "@std/bytes@0.221.0": { + "integrity": "64a047011cf833890a4a2ab7293ac55a1b4f5a050624ebc6a0159c357de91966" + }, + "@std/bytes@1.0.5": { + "integrity": "4465dd739d7963d964c809202ebea6d5c6b8e3829ef25c6a224290fbb8a1021e" + }, + "@std/encoding@1.0.7": { + "integrity": "f631247c1698fef289f2de9e2a33d571e46133b38d042905e3eac3715030a82d" + }, + "@std/fmt@1.0.5": { + "integrity": "0cfab43364bc36650d83c425cd6d99910fc20c4576631149f0f987eddede1a4d" + }, + "@std/fs@1.0.13": { + "integrity": "756d3ff0ade91c9e72b228e8012b6ff00c3d4a4ac9c642c4dac083536bf6c605", + "dependencies": [ + "jsr:@std/path@^1.0.8" + ] + }, + "@std/internal@1.0.5": { + "integrity": "54a546004f769c1ac9e025abd15a76b6671ddc9687e2313b67376125650dc7ba" + }, + "@std/io@0.221.0": { + "integrity": "faf7f8700d46ab527fa05cc6167f4b97701a06c413024431c6b4d207caa010da", + "dependencies": [ + "jsr:@std/assert@0.221", + "jsr:@std/bytes@0.221" + ] + }, + "@std/io@0.224.9": { + "integrity": "4414664b6926f665102e73c969cfda06d2c4c59bd5d0c603fd4f1b1c840d6ee3" + }, + "@std/io@0.225.2": { + "integrity": "3c740cd4ee4c082e6cfc86458f47e2ab7cb353dc6234d5e9b1f91a2de5f4d6c7", + "dependencies": [ + "jsr:@std/bytes@^1.0.5" + ] + }, + "@std/log@0.224.14": { + "integrity": "257f7adceee3b53bb2bc86c7242e7d1bc59729e57d4981c4a7e5b876c808f05e", + "dependencies": [ + "jsr:@std/fmt@^1.0.5", + "jsr:@std/fs@^1.0.11", + "jsr:@std/io@~0.225.2" + ] + }, + "@std/path@1.0.8": { + "integrity": "548fa456bb6a04d3c1a1e7477986b6cffbce95102d0bb447c67c4ee70e0364be" + }, + "@std/streams@0.221.0": { + "integrity": "47f2f74634b47449277c0ee79fe878da4424b66bd8975c032e3afdca88986e61", + "dependencies": [ + "jsr:@std/io@0.221" + ] + }, + "@std/text@1.0.10": { + "integrity": "9dcab377450253c0efa9a9a0c731040bfd4e1c03f8303b5934381467b7954338" + }, + "@std/yaml@1.0.5": { + "integrity": "71ba3d334305ee2149391931508b2c293a8490f94a337eef3a09cade1a2a2742" + } + }, + "workspace": { + "dependencies": [ + "jsr:@apexlang/apex@0.2", + "jsr:@apexlang/core@0.2", + "jsr:@std/assert@^1.0.11", + "jsr:@std/yaml@^1.0.5" + ] + } +} diff --git a/jsr.json b/jsr.json new file mode 100644 index 0000000..a8cbd8e --- /dev/null +++ b/jsr.json @@ -0,0 +1,31 @@ +{ + "name": "@apexlang/codegen", + "version": "0.1.10", + "description": "Code generators for Apex.", + "keywords": ["apex", "idl", "codegen"], + "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://www.github.com/apexlang/codegen" + }, + "bugs": { + "url": "https://www.github.com/apexlang/codegen/issues" + }, + "exports": { + "./cs": "./src/cs/mod.ts", + "./go": "./src/go/mod.ts", + "./json-schema": "./src/json-schema/mod.ts", + "./markdown": "./src/markdown/mod.ts", + "./openapiv3": "./src/openapiv3/mod.ts", + "./proto": "./src/proto/mod.ts", + "./python": "./src/python/mod.ts", + "./rest": "./src/rest/mod.ts", + "./rust": "./src/rust/mod.ts", + "./typescript": "./src/typescript/mod.ts", + "./utils": "./src/utils/mod.ts" + }, + "publish": { + "include": ["LICENSE", "README.md", "templates", "src/**/*.ts"], + "exclude": ["src/tests"] + } +} diff --git a/scripts/build_npm.ts b/scripts/build_npm.ts deleted file mode 100644 index a66ec5d..0000000 --- a/scripts/build_npm.ts +++ /dev/null @@ -1,46 +0,0 @@ -// ex. scripts/build_npm.ts -import { build, emptyDir } from "https://deno.land/x/dnt@0.40.0/mod.ts"; - -await emptyDir("./npm"); - -await build({ - entryPoints: [ - "./src/cs/mod.ts", - "./src/go/mod.ts", - "./src/json-schema/mod.ts", - "./src/markdown/mod.ts", - "./src/openapiv3/mod.ts", - "./src/proto/mod.ts", - "./src/python/mod.ts", - "./src/rest/mod.ts", - "./src/rust/mod.ts", - "./src/typescript/mod.ts", - "./src/utils/mod.ts", - ], - outDir: "./npm", - test: false, - shims: { - // see JS docs for overview and more options - deno: true, - }, - package: { - // package.json properties - name: "@apexlang/core", - version: Deno.args[0], - description: "Apex language JavaScript support", - keywords: ["apex", "idl", "codegen"], - license: "Apache-2.0", - repository: { - type: "git", - url: "https://github.com/apexlang/apex-js", - }, - bugs: { - url: "https://github.com/apexlang/apex-js/issues", - }, - }, - postBuild() { - // steps to run after building and before running the tests - Deno.copyFileSync("LICENSE", "npm/LICENSE"); - Deno.copyFileSync("README.md", "npm/README.md"); - }, -}); diff --git a/src/cs/alias_visitor.ts b/src/cs/alias_visitor.ts index c9ad22c..227cc56 100644 --- a/src/cs/alias_visitor.ts +++ b/src/cs/alias_visitor.ts @@ -14,12 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { BaseVisitor, Context } from "../deps/core/model.ts"; +import { BaseVisitor, type Context } from "@apexlang/core/model"; import { formatComment, pascalCase } from "../utils/mod.ts"; -import { expandType, Import } from "../go/mod.ts"; +import { expandType, type Import } from "../go/mod.ts"; export class AliasVisitor extends BaseVisitor { - visitAlias(context: Context): void { + public override visitAlias(context: Context): void { const { config, alias } = context; const aliases = config.aliases as { [key: string]: Import }; if (aliases && aliases[alias.name]) { diff --git a/src/cs/api_visitor.ts b/src/cs/api_visitor.ts index 9766c0e..64f4ab3 100644 --- a/src/cs/api_visitor.ts +++ b/src/cs/api_visitor.ts @@ -14,30 +14,30 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { BaseVisitor, Context } from "../deps/core/model.ts"; +import { BaseVisitor, type Context } from "@apexlang/core/model"; import { isService, pascalCase } from "../utils/mod.ts"; import { translations } from "./constant.ts"; -import { PathDirective } from "../rest/mod.ts"; +import type { PathDirective } from "../rest/mod.ts"; import { expandType, parseNamespaceName } from "./helpers.ts"; export class MinimalAPIVisitor extends BaseVisitor { - visitNamespaceBefore(context: Context) { + public override visitNamespaceBefore(context: Context) { this.write(`// Code generated by @apexlang/codegen. DO NOT EDIT.\n\n`); this.write(`using System;\nusing Microsoft.AspNetCore.Builder;\n\n`); super.visitNamespaceBefore(context); } - visitNamespace(context: Context) { + public override visitNamespace(context: Context) { this.write(`namespace ${parseNamespaceName(context.namespace.name)} {\n`); super.visitNamespace(context); } - visitNamespaceAfter(context: Context) { + public override visitNamespaceAfter(context: Context) { this.write(`}\n`); super.visitNamespaceAfter(context); } - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { if (!isService(context)) { return; } @@ -49,7 +49,7 @@ export class MinimalAPIVisitor extends BaseVisitor { } export class ApiServiceVisitor extends BaseVisitor { - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { let path = ""; context.namespace.annotation("path", (a) => { path = a?.convert().value; diff --git a/src/cs/enum_visitor.ts b/src/cs/enum_visitor.ts index d04fb2f..59ffe40 100644 --- a/src/cs/enum_visitor.ts +++ b/src/cs/enum_visitor.ts @@ -14,17 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { BaseVisitor, Context } from "../deps/core/model.ts"; +import { BaseVisitor, type Context } from "@apexlang/core/model"; import { formatComment, pascalCase } from "../utils/mod.ts"; export class EnumVisitor extends BaseVisitor { - visitEnumBefore(context: Context) { + public override visitEnumBefore(context: Context) { this.write(formatComment(" // ", context.enum.description)); this.write(` public enum ${pascalCase(context.enum.name)}\n {\n`); super.visitEnumBefore(context); } - visitEnumAfter(context: Context) { + public override visitEnumAfter(context: Context) { this.write(" }\n"); this.write(` @@ -39,7 +39,7 @@ export class EnumVisitor extends BaseVisitor { super.visitEnumAfter(context); } - visitEnum(context: Context) { + public override visitEnum(context: Context) { const values = context.enum.values; for (let i = 0; i < values.length; ++i) { this.write(` ${pascalCase(values[i].name)}`); diff --git a/src/cs/helpers.ts b/src/cs/helpers.ts index 8a5af1f..7939613 100644 --- a/src/cs/helpers.ts +++ b/src/cs/helpers.ts @@ -21,7 +21,7 @@ import { Map, Named, Optional, -} from "../deps/core/model.ts"; +} from "@apexlang/core/model"; import { pascalCase } from "../utils/mod.ts"; import { translations } from "./constant.ts"; diff --git a/src/cs/index_visitor.ts b/src/cs/index_visitor.ts index 0d1515c..a772355 100644 --- a/src/cs/index_visitor.ts +++ b/src/cs/index_visitor.ts @@ -16,7 +16,12 @@ limitations under the License. // This Visitor generates how final output should look like by combining all the visitors together -import { BaseVisitor, Context, Visitor, Writer } from "../deps/core/model.ts"; +import { + BaseVisitor, + type Context, + type Visitor, + type Writer, +} from "@apexlang/core/model"; import { InterfacesVisitor } from "./interfaces_visitor.ts"; import { MinimalAPIVisitor } from "./api_visitor.ts"; import { ScaffoldVisitor } from "./scaffold_visitor.ts"; @@ -31,35 +36,35 @@ export class IndexVisitor extends BaseVisitor { main_visitor = (writer: Writer): Visitor => new MainVisitor(writer); typeVisitor = (writer: Writer): Visitor => new TypeVisitor(writer); - visitNamespaceBefore(context: Context) { + public override visitNamespaceBefore(context: Context) { const visitor = this.apiVisitor(this.writer); context.namespace.accept(context, visitor); this.write(`\n`); super.visitNamespaceBefore(context); } - visitNamespace(context: Context) { + public override visitNamespace(context: Context) { const visitor = this.scaffoldVisitor(this.writer); context.namespace.accept(context, visitor); this.write(`\n`); super.visitNamespace(context); } - visitInterface(context: Context) { + public override visitInterface(context: Context) { const visitor = this.interfacesVisitor(this.writer); context.interface.accept(context, visitor); this.write(`\n`); super.visitInterface(context); } - visitNamespaceAfter(context: Context) { + public override visitNamespaceAfter(context: Context) { const visitor = this.main_visitor(this.writer); context.namespace.accept(context, visitor); this.write(`\n`); super.visitNamespaceBefore(context); } - visitType(context: Context) { + public override visitType(context: Context) { const visitor = this.typeVisitor(this.writer); context.type.accept(context, visitor); super.visitType(context); diff --git a/src/cs/interface_visitor.ts b/src/cs/interface_visitor.ts index 80b93e6..e930cc4 100644 --- a/src/cs/interface_visitor.ts +++ b/src/cs/interface_visitor.ts @@ -14,12 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { BaseVisitor, Context } from "../deps/core/model.ts"; +import { BaseVisitor, type Context } from "@apexlang/core/model"; import { formatComment, pascalCase } from "../utils/mod.ts"; import { expandType } from "./helpers.ts"; export class InterfaceVisitor extends BaseVisitor { - visitInterfaceBefore(context: Context) { + public override visitInterfaceBefore(context: Context) { this.write(formatComment(" // ", context.interface.description)); this.write( ` public interface ${pascalCase(context.interface.name)}\n {\n`, @@ -27,7 +27,7 @@ export class InterfaceVisitor extends BaseVisitor { super.visitInterfaceBefore(context); } - visitInterface(context: Context) { + public override visitInterface(context: Context) { const operations = context.interface.operations; for (let i = 0; i < operations.length; ++i) { const operation = operations[i]; @@ -50,7 +50,7 @@ export class InterfaceVisitor extends BaseVisitor { super.visitInterface(context); } - visitInterfaceAfter(context: Context) { + public override visitInterfaceAfter(context: Context) { this.write(" }\n\n"); super.visitInterfaceAfter(context); } diff --git a/src/cs/interfaces_visitor.ts b/src/cs/interfaces_visitor.ts index 36d225f..9f50ab8 100644 --- a/src/cs/interfaces_visitor.ts +++ b/src/cs/interfaces_visitor.ts @@ -14,7 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { BaseVisitor, Context, Visitor, Writer } from "../deps/core/model.ts"; +import { + BaseVisitor, + type Context, + type Visitor, + type Writer, +} from "@apexlang/core/model"; import { TypeVisitor } from "./types_visitor.ts"; import { InterfaceVisitor } from "./interface_visitor.ts"; import { parseNamespaceName } from "./helpers.ts"; @@ -29,42 +34,42 @@ export class InterfacesVisitor extends BaseVisitor { unionVisitor = (writer: Writer): Visitor => new UnionVisitor(writer); aliasVisitor = (writer: Writer): Visitor => new AliasVisitor(writer); - visitNamespaceBefore(context: Context) { + public override visitNamespaceBefore(context: Context) { this.write(`// Code generated by @apexlang/codegen. DO NOT EDIT.\n\n`); super.visitNamespaceBefore(context); } - visitNamespace(context: Context) { + public override visitNamespace(context: Context) { this.write(`namespace ${parseNamespaceName(context.namespace.name)} {\n`); super.visitNamespace(context); } - visitNamespaceAfter(context: Context) { + public override visitNamespaceAfter(context: Context) { this.write(`}\n`); super.visitNamespaceAfter(context); } - visitInterface(context: Context) { + public override visitInterface(context: Context) { const visitor = this.interfaceVisitor(this.writer); context.interface.accept(context, visitor); } - visitUnion(context: Context) { + public override visitUnion(context: Context) { const visitor = this.unionVisitor(this.writer); context.union.accept(context, visitor); } - visitAlias(context: Context) { + public override visitAlias(context: Context) { const visitor = this.aliasVisitor(this.writer); context.alias.accept(context, visitor); } - visitEnum(context: Context): void { + public override visitEnum(context: Context): void { const visitor = this.enumVisitor(this.writer); context.enum.accept(context, visitor); } - visitType(context: Context) { + public override visitType(context: Context) { const visitor = this.typeVisitor(this.writer); context.type.accept(context, visitor); } diff --git a/src/cs/main_visitor.ts b/src/cs/main_visitor.ts index 4e07f6d..bb6138a 100644 --- a/src/cs/main_visitor.ts +++ b/src/cs/main_visitor.ts @@ -16,22 +16,22 @@ limitations under the License. // This Visitor generates the Main method, which is the entry point for C# code. -import { BaseVisitor, Context } from "../deps/core/model.ts"; +import { BaseVisitor, type Context } from "@apexlang/core/model"; import { parseNamespaceName } from "./helpers.ts"; export class MainVisitor extends BaseVisitor { - visitNamespaceBefore(context: Context) { + public override visitNamespaceBefore(context: Context) { this.write(`namespace ${parseNamespaceName(context.namespace.name)} {\n`); super.visitNamespace(context); } - visitNamespace(context: Context) { + public override visitNamespace(context: Context) { this.write(`public class MainClass {\n`); this.write(`\t public static void Main(String[] args) {\n`); super.visitNamespace(context); } - visitInterface(context: Context) { + public override visitInterface(context: Context) { const { interface: iface } = context; if (iface.annotation("service")) { if (iface.annotation("uses")) { @@ -47,7 +47,7 @@ export class MainVisitor extends BaseVisitor { super.visitInterface(context); } - visitNamespaceAfter(context: Context) { + public override visitNamespaceAfter(context: Context) { this.write(`\t\t }\n`); this.write(`\t}\n`); this.write(`}\n`); diff --git a/src/cs/scaffold_visitor.ts b/src/cs/scaffold_visitor.ts index fffae8e..203aaba 100644 --- a/src/cs/scaffold_visitor.ts +++ b/src/cs/scaffold_visitor.ts @@ -28,17 +28,17 @@ export * from "./alias_visitor.ts"; export { InterfacesVisitor as default } from "./interfaces_visitor.ts"; import { formatComment, isOneOfType, pascalCase } from "../utils/mod.ts"; -import { BaseVisitor, Context } from "../deps/core/model.ts"; +import { BaseVisitor, type Context } from "@apexlang/core/model"; import { expandType, parseNamespaceName } from "./helpers.ts"; export class ScaffoldVisitor extends BaseVisitor { - // visitNamespaceBefore(context: Context) { + // public override visitNamespaceBefore(context: Context) { // this.write(`// Code generated by @apexlang/codegen. DO NOT EDIT.\n\n`); // this.write(`using System;\n\n`); // super.visitNamespaceBefore(context); // } - visitNamespace(context: Context) { + public override visitNamespace(context: Context) { this.write(`namespace ${parseNamespaceName(context.namespace.name)} {\n`); const service = new ServiceVisitor(this.writer); @@ -47,14 +47,14 @@ export class ScaffoldVisitor extends BaseVisitor { super.visitNamespace(context); } - visitNamespaceAfter(context: Context) { + public override visitNamespaceAfter(context: Context) { this.write(`}\n`); super.visitNamespaceAfter(context); } } export class ServiceVisitor extends BaseVisitor { - visitInterfaceBefore(context: Context) { + public override visitInterfaceBefore(context: Context) { if (!isValid(context)) { return; } @@ -87,7 +87,7 @@ export class ServiceVisitor extends BaseVisitor { super.visitInterfaceBefore(context); } - visitInterface(context: Context) { + public override visitInterface(context: Context) { if (!isValid(context)) { return; } diff --git a/src/cs/types_visitor.ts b/src/cs/types_visitor.ts index 77fdb19..0fc42e0 100644 --- a/src/cs/types_visitor.ts +++ b/src/cs/types_visitor.ts @@ -14,12 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { Argument, BaseVisitor, Context } from "../deps/core/model.ts"; +import { type Argument, BaseVisitor, type Context } from "@apexlang/core/model"; import { camelCase, formatComment, pascalCase } from "../utils/mod.ts"; import { expandType } from "./helpers.ts"; export class TypeVisitor extends BaseVisitor { - visitTypeBefore(context: Context): void { + public override visitTypeBefore(context: Context): void { const { type } = context; this.write(formatComment(" // ", type.description)); @@ -28,7 +28,7 @@ export class TypeVisitor extends BaseVisitor { super.visitTypesBefore(context); } - visitTypeField(context: Context) { + public override visitTypeField(context: Context) { if (context.fieldIndex > 0) { this.write(`\n`); } @@ -93,7 +93,7 @@ export class TypeVisitor extends BaseVisitor { } } - visitTypeAfter(context: Context) { + public override visitTypeAfter(context: Context) { this.write(" }\n\n"); super.visitTypeAfter(context); diff --git a/src/cs/union_visitor.ts b/src/cs/union_visitor.ts index b13000e..417c571 100644 --- a/src/cs/union_visitor.ts +++ b/src/cs/union_visitor.ts @@ -14,12 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { BaseVisitor, Context } from "../deps/core/model.ts"; +import { BaseVisitor, type Context } from "@apexlang/core/model"; import { formatComment, pascalCase } from "../utils/mod.ts"; import { expandType } from "../go/mod.ts"; export class UnionVisitor extends BaseVisitor { - visitUnion(context: Context): void { + public override visitUnion(context: Context): void { const { union } = context; this.write(` ${formatComment("// ", union.description)}`); this.write(`public record ${union.name} {\n`); diff --git a/src/deps/core/ast.ts b/src/deps/core/ast.ts deleted file mode 100644 index 0914f83..0000000 --- a/src/deps/core/ast.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "https://deno.land/x/apex_core@v0.1.5/ast/mod.ts"; diff --git a/src/deps/core/model.ts b/src/deps/core/model.ts deleted file mode 100644 index 5cf7730..0000000 --- a/src/deps/core/model.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "https://deno.land/x/apex_core@v0.1.5/model/mod.ts"; diff --git a/src/go/alias_visitor.ts b/src/go/alias_visitor.ts index 109d7cc..76c1c30 100644 --- a/src/go/alias_visitor.ts +++ b/src/go/alias_visitor.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { Context } from "../deps/core/model.ts"; +import type { Context } from "@apexlang/core/model"; import { expandType } from "./helpers.ts"; import { formatComment } from "../utils/mod.ts"; import { GoVisitor } from "./go_visitor.ts"; @@ -45,7 +45,7 @@ export function translateAlias({ } export class AliasVisitor extends GoVisitor { - visitAlias(context: Context): void { + public override visitAlias(context: Context): void { const { config, alias } = context; const aliases = config.aliases as { [key: string]: Import }; if (aliases && aliases[alias.name]) { diff --git a/src/go/constant.ts b/src/go/constant.ts index a4c8aa0..2c10702 100644 --- a/src/go/constant.ts +++ b/src/go/constant.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -export const translations = new Map([ +export const translations: Map = new Map([ ["ID", "string"], ["string", "string"], ["bytes", "[]byte"], diff --git a/src/go/enum_visitor.ts b/src/go/enum_visitor.ts index b9d1576..c77e5a1 100644 --- a/src/go/enum_visitor.ts +++ b/src/go/enum_visitor.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { Context, Writer } from "../deps/core/model.ts"; +import type { Context, Writer } from "@apexlang/core/model"; import { formatComment, pascalCase } from "../utils/mod.ts"; import { IMPORTS } from "./constant.ts"; import { getImporter, GoVisitor } from "./go_visitor.ts"; @@ -27,7 +27,7 @@ export class EnumVisitor extends GoVisitor { this.writeTypeInfo = writeTypeInfo; } - visitEnumBefore(context: Context): void { + public override visitEnumBefore(context: Context): void { super.triggerEnumsBefore(context); this.write(formatComment("// ", context.enum.description)); this.write(`type ${context.enum.name} int32 @@ -35,7 +35,7 @@ export class EnumVisitor extends GoVisitor { const (\n`); } - visitEnumValue(context: Context): void { + public override visitEnumValue(context: Context): void { const { enumValue } = context; this.write(formatComment("// ", enumValue.description)); this.write( @@ -46,7 +46,7 @@ export class EnumVisitor extends GoVisitor { super.triggerTypeField(context); } - visitEnumAfter(context: Context): void { + public override visitEnumAfter(context: Context): void { const $ = getImporter(context, IMPORTS); this.write(`)\n\n`); @@ -95,22 +95,41 @@ func (e *${context.enum.name}) UnmarshalJSON(b []byte) error { return err } return e.FromString(str) -} -\n\n`); +}\n\n`); + } + const yamlSupport = context.config.noEnumYAML + ? !context.config.noEnumYAML + : true; + if (yamlSupport) { + this.write(`// MarshalYAML marshals the enum as a YAML string + func (e ${context.enum.name}) MarshalYAML() (any, error) { + return e.String(), nil + } + + // UnmarshalYAML unmashals a quoted YAML string to the enum value + func (e *${context.enum.name}) UnmarshalYAML(unmarshal func(any) error) error { + var str string + if err := unmarshal(&str); err != nil { + return err } + + return e.FromString(str) + }\n\n`); + } + super.triggerEnumsAfter(context); } } export class EnumVisitorToStringMap extends GoVisitor { - visitEnumBefore(context: Context): void { + public override visitEnumBefore(context: Context): void { super.triggerEnumsBefore(context); this.write( `var toString${context.enum.name} = map[${context.enum.name}]string{\n`, ); } - visitEnumValue(context: Context): void { + public override visitEnumValue(context: Context): void { const { enumValue } = context; const display = enumValue.display ? enumValue.display : enumValue.name; this.write( @@ -119,21 +138,21 @@ export class EnumVisitorToStringMap extends GoVisitor { super.triggerTypeField(context); } - visitEnumAfter(context: Context): void { + public override visitEnumAfter(context: Context): void { this.write(`}\n\n`); super.triggerEnumsAfter(context); } } export class EnumVisitorToIDMap extends GoVisitor { - visitEnumBefore(context: Context): void { + public override visitEnumBefore(context: Context): void { super.triggerEnumsBefore(context); this.write( `var toID${context.enum.name} = map[string]${context.enum.name}{\n`, ); } - visitEnumValue(context: Context): void { + public override visitEnumValue(context: Context): void { const { enumValue } = context; const display = enumValue.display ? enumValue.display : enumValue.name; this.write( @@ -142,7 +161,7 @@ export class EnumVisitorToIDMap extends GoVisitor { super.triggerTypeField(context); } - visitEnumAfter(context: Context): void { + public override visitEnumAfter(context: Context): void { this.write(`}\n\n`); super.triggerEnumsAfter(context); } diff --git a/src/go/fiber_visitor.ts b/src/go/fiber_visitor.ts index aaccd19..0aa33db 100644 --- a/src/go/fiber_visitor.ts +++ b/src/go/fiber_visitor.ts @@ -14,7 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { AnyType, Context, Kind, Type } from "../deps/core/model.ts"; +import { + type AnyType, + type Context, + Kind, + type Type, +} from "@apexlang/core/model"; import { capitalize, convertOperationToType, @@ -31,7 +36,7 @@ import { getImporter, GoVisitor } from "./go_visitor.ts"; import { IMPORTS } from "./constant.ts"; export class FiberVisitor extends GoVisitor { - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { if (!isService(context)) { return; } @@ -43,7 +48,7 @@ export class FiberVisitor extends GoVisitor { } class FiberServiceVisitor extends GoVisitor { - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { const { interface: iface } = context; const $ = getImporter(context, IMPORTS); this @@ -53,7 +58,7 @@ class FiberServiceVisitor extends GoVisitor { ); } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { const { interface: iface, operation } = context; const $ = getImporter(context, IMPORTS); const path = getPath(context); @@ -154,7 +159,7 @@ class FiberServiceVisitor extends GoVisitor { }); } - visitInterfaceAfter(_context: Context): void { + public override visitInterfaceAfter(_context: Context): void { this.write(` } }\n`); } diff --git a/src/go/go_visitor.ts b/src/go/go_visitor.ts index f518b20..77aecee 100644 --- a/src/go/go_visitor.ts +++ b/src/go/go_visitor.ts @@ -16,19 +16,19 @@ limitations under the License. */ import { - Alias, - AnyType, + type Alias, + type AnyType, BaseVisitor, - Context, + type Context, Kind, - List, - Map as MapType, - Optional, - Primitive, + type List, + type Map as MapType, + type Optional, + type Primitive, PrimitiveName, - Type, -} from "../deps/core/model.ts"; -import { Import } from "./alias_visitor.ts"; + type Type, +} from "@apexlang/core/model"; +import type { Import } from "./alias_visitor.ts"; interface Imported { as?: string; @@ -220,7 +220,7 @@ export class GoVisitor extends BaseVisitor { private _ctx: Context | undefined; aliases: Record = {}; - writeHead(context: Context): void { + public override writeHead(context: Context): void { this.aliases = (context?.config?.aliases as Record) || {}; const packageName = context.config.package || "module"; @@ -240,7 +240,7 @@ export class GoVisitor extends BaseVisitor { super.writeHead(context); } - public renderImports(context: Context): string { + public override renderImports(context: Context): string { return getImports(context).render(); } } diff --git a/src/go/grpc_visitor.ts b/src/go/grpc_visitor.ts index 1030729..d56cd7e 100644 --- a/src/go/grpc_visitor.ts +++ b/src/go/grpc_visitor.ts @@ -16,21 +16,21 @@ limitations under the License. */ import { - Alias, - AnyType, - Context, - Enum, - Field, + type Alias, + type AnyType, + type Context, + type Enum, + type Field, Kind, - List, - Map, - Named, - Optional, - Primitive, + type List, + type Map, + type Named, + type Optional, + type Primitive, PrimitiveName, - Type, - Union, -} from "../deps/core/model.ts"; + type Type, + type Union, +} from "@apexlang/core/model"; import { capitalize, convertOperationToType, @@ -47,7 +47,7 @@ import { getImporter, getImports, GoVisitor, - ImportNames, + type ImportNames, } from "./go_visitor.ts"; import { expandType, fieldName, methodName, returnShare } from "./helpers.ts"; import { StructVisitor } from "./struct_visitor.ts"; @@ -58,7 +58,7 @@ export class GRPCVisitor extends GoVisitor { private input: { [name: string]: NamedType } = {}; private output: { [name: string]: NamedType } = {}; - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { if (!isService(context)) { return; } @@ -88,7 +88,7 @@ func New${iface.name}GRPCWrapper(service ${iface.name}) *${iface.name}GRPCWrappe }\n\n`); } - visitParameter(context: Context): void { + public override visitParameter(context: Context): void { if (!isService(context)) { return; } @@ -96,7 +96,7 @@ func New${iface.name}GRPCWrapper(service ${iface.name}) *${iface.name}GRPCWrappe this.checkType(context, parameter.type, this.input); } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { if (!isService(context)) { return; } @@ -370,7 +370,7 @@ func New${iface.name}GRPCWrapper(service ${iface.name}) *${iface.name}GRPCWrappe this.write(`}\n\n`); } - visitNamespaceAfter(context: Context): void { + public override visitNamespaceAfter(context: Context): void { const $ = getImporter(context, IMPORTS); for (const name of Object.keys(this.input)) { const named = this.input[name]; diff --git a/src/go/helpers.ts b/src/go/helpers.ts index f6cd471..7cd9298 100644 --- a/src/go/helpers.ts +++ b/src/go/helpers.ts @@ -32,7 +32,7 @@ import { PrimitiveName, Stream, Valued, -} from "../deps/core/model.ts"; +} from "@apexlang/core/model"; import { capitalize, renamed } from "../utils/mod.ts"; import { Import } from "./alias_visitor.ts"; import { translations } from "./constant.ts"; @@ -201,9 +201,9 @@ export function defaultValueForType( * returns string in quotes * @param s string to have quotes */ -export const strQuote = (s: string) => { +export function strQuote(s: string): string { return `\"${s}\"`; -}; +} let expandStreamPattern = `{{type}}`; export function setExpandStreamPattern(pattern: string) { diff --git a/src/go/interface_visitor.ts b/src/go/interface_visitor.ts index df3ba05..7c55322 100644 --- a/src/go/interface_visitor.ts +++ b/src/go/interface_visitor.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { Context } from "../deps/core/model.ts"; +import type { Context } from "@apexlang/core/model"; import { expandType, mapParam, methodName, returnPointer } from "./helpers.ts"; import { translateAlias } from "./alias_visitor.ts"; import { formatComment, isVoid, noCode } from "../utils/mod.ts"; @@ -22,13 +22,13 @@ import { getImporter, GoVisitor } from "./go_visitor.ts"; import { IMPORTS } from "./constant.ts"; export class InterfaceVisitor extends GoVisitor { - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { const { interface: iface } = context; this.write(formatComment("// ", iface.description)); this.write(`type ${iface.name} interface {\n`); } - visitFunction(context: Context): void { + public override visitFunction(context: Context): void { const { operation } = context; if (noCode(operation)) { return; @@ -49,7 +49,7 @@ export class InterfaceVisitor extends GoVisitor { this.write(`\n\n`); } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { const { operation } = context; if (noCode(operation)) { return; @@ -93,7 +93,7 @@ export class InterfaceVisitor extends GoVisitor { } } - visitInterfaceAfter(_context: Context): void { + public override visitInterfaceAfter(_context: Context): void { this.write(`}\n\n`); } } diff --git a/src/go/interfaces_visitor.ts b/src/go/interfaces_visitor.ts index 77a5cf3..6dc2aed 100644 --- a/src/go/interfaces_visitor.ts +++ b/src/go/interfaces_visitor.ts @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { Context, Visitor, Writer } from "../deps/core/model.ts"; +import { Context, Visitor, Writer } from "@apexlang/core/model"; import { EnumVisitor } from "./enum_visitor.ts"; import { DefaultsVisitor, StructVisitor } from "./struct_visitor.ts"; import { AliasVisitor } from "./alias_visitor.ts"; @@ -38,7 +38,7 @@ export class InterfacesVisitor extends GoVisitor { unionVisitor = (writer: Writer): Visitor => new UnionVisitor(writer); aliasVisitor = (writer: Writer): Visitor => new AliasVisitor(writer); - visitNamespaceBefore(context: Context): void { + public override visitNamespaceBefore(context: Context): void { const { namespace: ns } = context; this.writeTypeInfo = context.config.writeTypeInfo as boolean; if (this.writeTypeInfo == undefined) { @@ -62,13 +62,13 @@ export class InterfacesVisitor extends GoVisitor { super.triggerNamespaceBefore(context); } - visitFunctionBefore(context: Context): void { + public override visitFunctionBefore(context: Context): void { const { operation } = context; const visitor = this.serviceVisitor(this.writer); operation.accept(context, visitor); } - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { const { interface: iface } = context; if (isProvider(context)) { const visitor = this.dependencyVisitor(this.writer); @@ -79,22 +79,22 @@ export class InterfacesVisitor extends GoVisitor { } } - visitAlias(context: Context): void { + public override visitAlias(context: Context): void { const visitor = this.aliasVisitor(this.writer); context.alias.accept(context, visitor); } - visitEnum(context: Context): void { + public override visitEnum(context: Context): void { const visitor = this.enumVisitor(this.writer); context.enum.accept(context, visitor); } - visitUnion(context: Context): void { + public override visitUnion(context: Context): void { const visitor = this.unionVisitor(this.writer); context.union.accept(context, visitor); } - visitType(context: Context): void { + public override visitType(context: Context): void { const sVisitor = this.structVisitor(this.writer); context.type.accept(context, sVisitor); const dVisitor = this.defaultsVisitor(this.writer); diff --git a/src/go/main_visitor.ts b/src/go/main_visitor.ts index ff64e40..f7badca 100644 --- a/src/go/main_visitor.ts +++ b/src/go/main_visitor.ts @@ -14,8 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { Context, Writer } from "../deps/core/model.ts"; -import { camelCase, InterfaceUsesVisitor, UsesVisitor } from "../utils/mod.ts"; +import type { Context, Writer } from "@apexlang/core/model"; +import { + camelCase, + InterfaceUsesVisitor, + type UsesVisitor, +} from "../utils/mod.ts"; import { IMPORTS } from "./constant.ts"; import { getImporter, getImports, GoVisitor } from "./go_visitor.ts"; @@ -38,7 +42,7 @@ export class MainVisitor extends GoVisitor { usesVisitor = (writer: Writer): UsesVisitor => new InterfaceUsesVisitor(writer); - writeHead(context: Context): void { + public override writeHead(context: Context): void { const prev = context.config.package; context.config.package = "main"; context.config.doNotEdit = false; @@ -46,7 +50,7 @@ export class MainVisitor extends GoVisitor { context.config.package = prev; } - visitNamespaceBefore(context: Context): void { + public override visitNamespaceBefore(context: Context): void { const config = context.config as Config; const $ = getImporter(context, IMPORTS); const http = config.http || {}; diff --git a/src/go/msgpack_constants.ts b/src/go/msgpack_constants.ts index ae8b986..21ce0df 100644 --- a/src/go/msgpack_constants.ts +++ b/src/go/msgpack_constants.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -export const msgpackCodecFuncs = new Map([ +export const msgpackCodecFuncs: Map = new Map([ ["ID", "StringToBytes"], ["bool", "BoolToBytes"], ["string", "StringToBytes"], @@ -32,7 +32,7 @@ export const msgpackCodecFuncs = new Map([ ["bytes", "ByteArraToBytesy"], ]); -export const msgpackDecodeFuncs = new Map([ +export const msgpackDecodeFuncs: Map = new Map([ ["ID", "ReadString"], ["bool", "ReadBool"], ["string", "ReadString"], @@ -50,7 +50,10 @@ export const msgpackDecodeFuncs = new Map([ ["bytes", "ReadByteArray"], ]); -export const msgpackDecodeNillableFuncs = new Map([ +export const msgpackDecodeNillableFuncs: Map = new Map< + string, + string +>([ ["ID", "ReadNillableString"], ["bool", "ReadNillableBool"], ["string", "ReadNillableString"], @@ -68,7 +71,7 @@ export const msgpackDecodeNillableFuncs = new Map([ ["bytes", "ReadNillableByteArray"], ]); -export const msgpackEncodeFuncs = new Map([ +export const msgpackEncodeFuncs: Map = new Map([ ["ID", "WriteString"], ["bool", "WriteBool"], ["string", "WriteString"], @@ -86,7 +89,10 @@ export const msgpackEncodeFuncs = new Map([ ["bytes", "WriteByteArray"], ]); -export const msgpackEncodeNillableFuncs = new Map([ +export const msgpackEncodeNillableFuncs: Map = new Map< + string, + string +>([ ["ID", "WriteNillableString"], ["bool", "WriteNillableBool"], ["string", "WriteNillableString"], @@ -104,7 +110,7 @@ export const msgpackEncodeNillableFuncs = new Map([ ["bytes", "WriteNillableByteArray"], ]); -export const msgpackCastFuncs = new Map([ +export const msgpackCastFuncs: Map = new Map([ ["ID", "convert.String"], ["bool", "convert.Bool"], ["string", "convert.String"], @@ -121,7 +127,10 @@ export const msgpackCastFuncs = new Map([ ["bytes", "convert.ByteArray"], ]); -export const msgpackCastNillableFuncs = new Map([ +export const msgpackCastNillableFuncs: Map = new Map< + string, + string +>([ ["ID", "convert.NillableString"], ["bool", "convert.NillableBool"], ["string", "convert.NillableString"], diff --git a/src/go/msgpack_decoder_visitor.ts b/src/go/msgpack_decoder_visitor.ts index 1db04f6..2f4c9c6 100644 --- a/src/go/msgpack_decoder_visitor.ts +++ b/src/go/msgpack_decoder_visitor.ts @@ -14,14 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { Context } from "../deps/core/model.ts"; +import type { Context } from "@apexlang/core/model"; import { IMPORTS } from "./constant.ts"; import { getImporter, GoVisitor } from "./go_visitor.ts"; import { fieldName } from "./helpers.ts"; import { msgpackRead } from "./msgpack_helpers.ts"; export class MsgPackDecoderVisitor extends GoVisitor { - visitTypeFieldsBefore(context: Context): void { + public override visitTypeFieldsBefore(context: Context): void { super.triggerTypeFieldsBefore(context); const $ = getImporter(context, IMPORTS); @@ -45,7 +45,7 @@ export class MsgPackDecoderVisitor extends GoVisitor { } } - visitTypeField(context: Context): void { + public override visitTypeField(context: Context): void { const field = context.field!; this.write(`case "${field.name}":\n`); this.write( @@ -62,7 +62,7 @@ export class MsgPackDecoderVisitor extends GoVisitor { super.triggerTypeField(context); } - visitTypeFieldsAfter(context: Context): void { + public override visitTypeFieldsAfter(context: Context): void { if (context.fields.length > 0) { this.write(`default: err = decoder.Skip() diff --git a/src/go/msgpack_encoder_visitor.ts b/src/go/msgpack_encoder_visitor.ts index 30a197f..12bf310 100644 --- a/src/go/msgpack_encoder_visitor.ts +++ b/src/go/msgpack_encoder_visitor.ts @@ -14,14 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { Context } from "../deps/core/model.ts"; +import type { Context } from "@apexlang/core/model"; import { IMPORTS } from "./constant.ts"; import { getImporter, GoVisitor } from "./go_visitor.ts"; import { fieldName } from "./helpers.ts"; import { msgpackEncode } from "./msgpack_helpers.ts"; export class MsgPackEncoderVisitor extends GoVisitor { - visitTypeFieldsBefore(context: Context): void { + public override visitTypeFieldsBefore(context: Context): void { super.triggerTypeFieldsBefore(context); const $ = getImporter(context, IMPORTS); @@ -35,7 +35,7 @@ export class MsgPackEncoderVisitor extends GoVisitor { ); } - visitTypeField(context: Context): void { + public override visitTypeField(context: Context): void { const field = context.field; this.write(`encoder.WriteString("${field.name}")\n`); this.write( @@ -49,7 +49,7 @@ export class MsgPackEncoderVisitor extends GoVisitor { super.triggerTypeField(context); } - visitTypeFieldsAfter(context: Context): void { + public override visitTypeFieldsAfter(context: Context): void { this.write(` return nil }\n\n`); @@ -58,7 +58,7 @@ export class MsgPackEncoderVisitor extends GoVisitor { } export class MsgPackEncoderUnionVisitor extends GoVisitor { - visitTypeFieldsBefore(context: Context): void { + public override visitTypeFieldsBefore(context: Context): void { super.triggerTypeFieldsBefore(context); const $ = getImporter(context, IMPORTS); this.write( @@ -70,7 +70,7 @@ export class MsgPackEncoderUnionVisitor extends GoVisitor { ); } - visitTypeField(context: Context): void { + public override visitTypeField(context: Context): void { const field = context.field; this.write(`if o.${fieldName(field, field.name)} != nil {\n`); this.write(`encoder.WriteMapSize(1)\n`); @@ -88,7 +88,7 @@ export class MsgPackEncoderUnionVisitor extends GoVisitor { super.triggerTypeField(context); } - visitTypeFieldsAfter(context: Context): void { + public override visitTypeFieldsAfter(context: Context): void { this.write(` encoder.WriteNil() return nil diff --git a/src/go/msgpack_helpers.ts b/src/go/msgpack_helpers.ts index 72746fa..f32d089 100644 --- a/src/go/msgpack_helpers.ts +++ b/src/go/msgpack_helpers.ts @@ -15,20 +15,20 @@ limitations under the License. */ import { - Alias, - AnyType, - Context, - Enum, + type Alias, + type AnyType, + type Context, + type Enum, Kind, - List, - Map, - Named, - Optional, - Parameter, - Primitive, + type List, + type Map, + type Named, + type Optional, + type Parameter, + type Primitive, PrimitiveName, -} from "../deps/core/model.ts"; -import { Import, translateAlias } from "./alias_visitor.ts"; +} from "@apexlang/core/model"; +import { type Import, translateAlias } from "./alias_visitor.ts"; import { IMPORTS, translations } from "./constant.ts"; import { getImporter } from "./go_visitor.ts"; import { expandType, fieldName, returnShare } from "./helpers.ts"; diff --git a/src/go/msgpack_visitor.ts b/src/go/msgpack_visitor.ts index df0a107..7362ab8 100644 --- a/src/go/msgpack_visitor.ts +++ b/src/go/msgpack_visitor.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { Context, Kind, Writer } from "../deps/core/model.ts"; +import { type Context, Kind, type Writer } from "@apexlang/core/model"; import { convertOperationToType, convertUnionToType } from "../utils/mod.ts"; import { GoVisitor } from "./go_visitor.ts"; import { MsgPackDecoderVisitor } from "./msgpack_decoder_visitor.ts"; @@ -50,7 +50,7 @@ export class MsgPackVisitor extends GoVisitor { this.setCallback("OperationAfter", "arguments", operArgs); } - visitType(context: Context): void { + public override visitType(context: Context): void { const { type } = context; const decoder = new MsgPackDecoderVisitor(this.writer); type.accept(context, decoder); @@ -59,7 +59,7 @@ export class MsgPackVisitor extends GoVisitor { this.write(`\n`); } - visitUnion(context: Context): void { + public override visitUnion(context: Context): void { const { union } = context; const tr = context.getType.bind(context); const type = convertUnionToType(tr, union); diff --git a/src/go/scaffold_visitor.ts b/src/go/scaffold_visitor.ts index 96360ee..54dcd4a 100644 --- a/src/go/scaffold_visitor.ts +++ b/src/go/scaffold_visitor.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { Context } from "../deps/core/model.ts"; +import type { Context } from "@apexlang/core/model"; import { defaultValueForType, expandType, @@ -38,12 +38,12 @@ function getLogger(context: Context): Logger | undefined { } export class ScaffoldVisitor extends GoVisitor { - writeHead(context: Context): void { + public override writeHead(context: Context): void { context.config.doNotEdit = false; super.writeHead(context); } - visitNamespaceBefore(context: Context): void { + public override visitNamespaceBefore(context: Context): void { super.visitNamespaceBefore(context); const logger = getLogger(context); @@ -67,7 +67,7 @@ export class ScaffoldVisitor extends GoVisitor { } class ServiceVisitor extends GoVisitor { - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { const roleNames = (context.config.names as string[]) || []; const roleTypes = (context.config.types as string[]) || []; const { interface: iface } = context; @@ -121,7 +121,7 @@ class ServiceVisitor extends GoVisitor { }\n\n`); } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { if (!isValid(context)) { return; } diff --git a/src/go/struct_visitor.ts b/src/go/struct_visitor.ts index 0f4dc2f..dbe3940 100644 --- a/src/go/struct_visitor.ts +++ b/src/go/struct_visitor.ts @@ -14,12 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { Context, Kind, Named, Writer } from "../deps/core/model.ts"; +import { Context, Kind, Named, Writer } from "@apexlang/core/model"; import { expandType, fieldName } from "./helpers.ts"; import { translateAlias } from "./alias_visitor.ts"; import { formatComment } from "../utils/mod.ts"; import { getImports, GoVisitor } from "./go_visitor.ts"; -import { Kind as ASTKind, StringValue, Value } from "../deps/core/ast.ts"; +import { Kind as ASTKind, StringValue, Value } from "@apexlang/core/ast"; interface Serialize { value: string; @@ -33,7 +33,7 @@ export class StructVisitor extends GoVisitor { this.writeTypeInfo = writeTypeInfo; } - visitTypeBefore(context: Context): void { + public override visitTypeBefore(context: Context): void { const { type } = context; super.triggerTypeBefore(context); this.write(formatComment("// ", type.description)); @@ -49,7 +49,7 @@ export class StructVisitor extends GoVisitor { } } - visitTypeField(context: Context): void { + public override visitTypeField(context: Context): void { const { field, type } = context; const importer = getImports(context); importer.type(field.type); @@ -89,7 +89,7 @@ export class StructVisitor extends GoVisitor { super.triggerTypeField(context); } - visitTypeAfter(context: Context): void { + public override visitTypeAfter(context: Context): void { const { type } = context; const receiver = type.name.substring(0, 1).toLowerCase(); this.write(`}\n\n`); @@ -112,7 +112,7 @@ export class StructVisitor extends GoVisitor { } export class DefaultsVisitor extends GoVisitor { - visitTypeBefore(context: Context): void { + public override visitTypeBefore(context: Context): void { const { type } = context; super.triggerTypeBefore(context); this.write( @@ -125,7 +125,7 @@ export class DefaultsVisitor extends GoVisitor { return ${type.name}{\n`); } - public visitTypeField(context: Context): void { + public override visitTypeField(context: Context): void { const { field } = context; if (!field.default) { return; @@ -135,7 +135,7 @@ export class DefaultsVisitor extends GoVisitor { ); } - visitTypeAfter(_context: Context): void { + public override visitTypeAfter(_context: Context): void { this.write(`}\n}\n\n`); } } diff --git a/src/go/union_visitor.ts b/src/go/union_visitor.ts index b007b39..985f9c6 100644 --- a/src/go/union_visitor.ts +++ b/src/go/union_visitor.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { Annotated, Context } from "../deps/core/model.ts"; +import { Annotated, Context } from "@apexlang/core/model"; import { formatComment, typeName } from "../utils/mod.ts"; import { getImports, GoVisitor } from "./go_visitor.ts"; import { expandType, fieldName } from "./helpers.ts"; @@ -24,7 +24,7 @@ interface UnionKey { } export class UnionVisitor extends GoVisitor { - visitUnion(context: Context): void { + public override visitUnion(context: Context): void { const tick = "`"; const { union } = context; const imports = getImports(context); diff --git a/src/json-schema/json-schema.ts b/src/json-schema/json-schema.ts index 0427e06..65adede 100644 --- a/src/json-schema/json-schema.ts +++ b/src/json-schema/json-schema.ts @@ -14,25 +14,25 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { Named } from "../deps/core/ast.ts"; +import type { Named } from "@apexlang/core/ast"; import { - AnyType, + type AnyType, BaseVisitor, - Context, + type Context, Kind, - List, - Map, - Optional, - Primitive, + type List, + type Map, + type Optional, + type Primitive, PrimitiveName, - Type, - Writer, -} from "../deps/core/model.ts"; -import { + type Type, + type Writer, +} from "@apexlang/core/model"; +import type { ArraySchemaObject, ReferenceObject, SchemaObject, -} from "https://deno.land/x/openapi@0.1.0/mod.ts"; +} from "../openapiv3/types.ts"; import { convertArrayToObject } from "../utils/mod.ts"; interface Definitions { @@ -71,16 +71,16 @@ export class JsonSchemaVisitor extends BaseVisitor { super(writer); } - visitNamespace(context: Context): void { + public override visitNamespace(context: Context): void { context.config; this.schema.title = context.namespace.name; } - visitNamespaceAfter(_context: Context): void { + public override visitNamespaceAfter(_context: Context): void { this.write(JSON.stringify(this.schema.valueOf(), null, 2)); } - visitType(context: Context): void { + public override visitType(context: Context): void { const visitor = new TypeVisitor(this.writer); context.type.accept(context, visitor); @@ -90,7 +90,7 @@ export class JsonSchemaVisitor extends BaseVisitor { this.schema.$defs[context.type?.name!] = visitor.def; } - visitEnum(context: Context): void { + public override visitEnum(context: Context): void { const visitor = new EnumVisitor(this.writer); context.enum.accept(context, visitor); if (!this.schema.$defs) { @@ -99,7 +99,7 @@ export class JsonSchemaVisitor extends BaseVisitor { this.schema.$defs[context.enum?.name!] = visitor.def; } - visitUnion(context: Context): void { + public override visitUnion(context: Context): void { const visitor = new UnionVisitor(this.writer); context.union.accept(context, visitor); if (!this.schema.$defs) { @@ -108,7 +108,7 @@ export class JsonSchemaVisitor extends BaseVisitor { this.schema.$defs[context.union?.name!] = visitor.def; } - visitAlias(context: Context): void { + public override visitAlias(context: Context): void { const visitor = new AliasVisitor(this.writer); context.alias.accept(context, visitor); if (!this.schema.$defs) { @@ -125,7 +125,7 @@ class TypeVisitor extends BaseVisitor { super(writer); } - visitTypeField(context: Context): void { + public override visitTypeField(context: Context): void { const def: Mutable = {}; if (context.field.description) { def.description = context.field.description; @@ -146,7 +146,7 @@ class EnumVisitor extends BaseVisitor { super(writer); } - visitEnum(context: Context): void { + public override visitEnum(context: Context): void { const schema: SchemaObject = { description: context.enum.description, type: JsonSchemaType.String, @@ -163,7 +163,7 @@ class UnionVisitor extends BaseVisitor { super(writer); } - visitUnion(context: Context): void { + public override visitUnion(context: Context): void { const { union } = context; const arr: SchemaObject[] = []; convertArrayToObject( @@ -201,7 +201,7 @@ class AliasVisitor extends BaseVisitor { super(writer); } - visitAlias(context: Context): void { + public override visitAlias(context: Context): void { const schema: SchemaObject = { description: context.alias.description, }; diff --git a/src/markdown/helpers.ts b/src/markdown/helpers.ts index 7c488bf..c213f48 100644 --- a/src/markdown/helpers.ts +++ b/src/markdown/helpers.ts @@ -5,7 +5,7 @@ import { Map, Named, Optional, -} from "../deps/core/model.ts"; +} from "@apexlang/core/model"; export const expandType = (type: AnyType): string => { switch (type.kind) { diff --git a/src/markdown/markdown-visitor.ts b/src/markdown/markdown-visitor.ts index 94a4d31..671fc5b 100644 --- a/src/markdown/markdown-visitor.ts +++ b/src/markdown/markdown-visitor.ts @@ -1,4 +1,4 @@ -import { BaseVisitor, Context } from "../deps/core/model.ts"; +import { BaseVisitor, type Context } from "@apexlang/core/model"; import { expandType } from "./helpers.ts"; export class MarkdownVisitor extends BaseVisitor { @@ -24,7 +24,7 @@ export class MarkdownVisitor extends BaseVisitor { return desc ? `: ${desc}` : ""; } - visitNamespace(context: Context): void { + public override visitNamespace(context: Context): void { if (context.config.title) { this.writeLn(`# ${context.config.title}\n`); this.writeLn(`Namespace: **\`${context.namespace.name}\`**`); @@ -34,11 +34,11 @@ export class MarkdownVisitor extends BaseVisitor { this.writeDescription(context.namespace.description); } - public visitInterfacesBefore(_: Context): void { + public override visitInterfacesBefore(_: Context): void { this.writeHeader("Interfaces"); } - visitInterface(context: Context): void { + public override visitInterface(context: Context): void { const node = context.interface; this.writeDefinitionName(node.name); this.writeDescription(node.description); @@ -56,11 +56,11 @@ export class MarkdownVisitor extends BaseVisitor { } } - public visitTypesBefore(_: Context): void { + public override visitTypesBefore(_: Context): void { this.writeHeader("Types"); } - visitType(context: Context): void { + public override visitType(context: Context): void { const typ = context.type; this.writeDefinitionName(typ.name); this.writeDescription(typ.description); @@ -75,11 +75,11 @@ export class MarkdownVisitor extends BaseVisitor { } } - public visitEnumsBefore(_: Context): void { + public override visitEnumsBefore(_: Context): void { this.writeHeader("Enums"); } - visitEnum(context: Context): void { + public override visitEnum(context: Context): void { const e = context.enum; this.writeDefinitionName(e.name); @@ -89,22 +89,22 @@ export class MarkdownVisitor extends BaseVisitor { } } - public visitAliasesBefore(_: Context): void { + public override visitAliasesBefore(_: Context): void { this.writeHeader("Aliases"); } - visitAlias(context: Context): void { + public override visitAlias(context: Context): void { const a = context.alias; this.writeDefinitionName(a.name); this.writeLn(`\`alias ${a.name} = ${expandType(a.type)}\``); this.writeDescription(a.description); } - public visitUnionsBefore(_: Context): void { + public override visitUnionsBefore(_: Context): void { this.writeHeader("Unions"); } - visitUnion(context: Context): void { + public override visitUnion(context: Context): void { const u = context.union; this.writeDefinitionName(u.name); this.writeLn( diff --git a/src/mod.ts b/src/mod.ts deleted file mode 100644 index 5161629..0000000 --- a/src/mod.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2022 The Apex Authors. - -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. -*/ - -export * as cs from "./cs/mod.ts"; -export * as go from "./go/mod.ts"; -export * as jsonSchema from "./json-schema/mod.ts"; -export * as openapiv3 from "./openapiv3/mod.ts"; -export * as proto from "./proto/mod.ts"; -export * as python from "./python/mod.ts"; -export * as rest from "./rest/mod.ts"; -export * as rust from "./rust/mod.ts"; -export * as typescript from "./typescript/mod.ts"; -export * as utils from "./utils/mod.ts"; diff --git a/src/openapiv3/openapiv3.ts b/src/openapiv3/openapiv3.ts index 28509e7..d2c0829 100644 --- a/src/openapiv3/openapiv3.ts +++ b/src/openapiv3/openapiv3.ts @@ -16,21 +16,21 @@ limitations under the License. */ import { - Alias, - AnyType, + type Alias, + type AnyType, BaseVisitor, - Context, - Field, + type Context, + type Field, Kind, - List as ListType, - Map as MapType, - Named, - Optional, - Primitive, - Type, - Writer, -} from "../deps/core/model.ts"; -import { + type List as ListType, + type Map as MapType, + type Named, + type Optional, + type Primitive, + type Type, + type Writer, +} from "@apexlang/core/model"; +import type { Document, ExternalDocumentationObject, InfoObject, @@ -42,16 +42,16 @@ import { ResponsesObject, SchemaObject, ServerObject, -} from "https://deno.land/x/openapi@0.1.0/mod.ts"; +} from "./types.ts"; -import { SummaryDirective } from "./directives.ts"; -import * as yaml from "https://deno.land/std@0.167.0/encoding/yaml.ts"; +import type { SummaryDirective } from "./directives.ts"; +import * as yaml from "@std/yaml"; import { convertArrayToObject, ExposedTypesVisitor, isService, } from "../utils/mod.ts"; -import { getPath, ResponseDirective } from "../rest/mod.ts"; +import { getPath, type ResponseDirective } from "../rest/mod.ts"; type Method = "get" | "post" | "options" | "put" | "delete" | "patch"; @@ -127,14 +127,14 @@ export class OpenAPIV3Visitor extends BaseVisitor { super(writer); } - visitNamespaceBefore(context: Context) { + public override visitNamespaceBefore(context: Context) { const ns = context.namespace; const visitor = new ExposedTypesVisitor(this.writer); ns.accept(context, visitor); this.exposedTypes = visitor.found; } - visitNamespaceAfter(context: Context): void { + public override visitNamespaceAfter(context: Context): void { const filename = context.config["$filename"]; this.root.paths = this.paths; this.root.components = { schemas: this.schemas }; @@ -146,7 +146,7 @@ export class OpenAPIV3Visitor extends BaseVisitor { } } - visitNamespace(context: Context): void { + public override visitNamespace(context: Context): void { const ns = context.namespace; ns.annotation("info", (a) => { this.root.info = a.convert(); @@ -160,7 +160,7 @@ export class OpenAPIV3Visitor extends BaseVisitor { }); } - visitInterface(context: Context): void { + public override visitInterface(context: Context): void { if (!isService(context)) { return; } @@ -172,7 +172,7 @@ export class OpenAPIV3Visitor extends BaseVisitor { }); } - visitOperationBefore(context: Context): void { + public override visitOperationBefore(context: Context): void { if (!isService(context)) { return; } @@ -221,7 +221,7 @@ export class OpenAPIV3Visitor extends BaseVisitor { pathItem[method] = this.operation; } - visitParameter(context: Context): void { + public override visitParameter(context: Context): void { if (!this.operation || !isService(context)) { return; } @@ -435,7 +435,7 @@ export class OpenAPIV3Visitor extends BaseVisitor { this.operation!.parameters.push(p); } - visitOperationAfter(context: Context): void { + public override visitOperationAfter(context: Context): void { if (!this.operation || !isService(context)) { return; } @@ -497,7 +497,7 @@ export class OpenAPIV3Visitor extends BaseVisitor { this.operation = undefined; } - visitType(context: Context): void { + public override visitType(context: Context): void { const { type } = context; if (!this.exposedTypes.has(type.name)) { return; @@ -509,7 +509,7 @@ export class OpenAPIV3Visitor extends BaseVisitor { this.schemas[type.name] = schema; } - visitEnum(context: Context): void { + public override visitEnum(context: Context): void { const e = context.enum; if (!this.exposedTypes.has(e.name)) { return; @@ -523,7 +523,7 @@ export class OpenAPIV3Visitor extends BaseVisitor { this.schemas[e.name] = schema; } - visitUnion(context: Context): void { + public override visitUnion(context: Context): void { const { union } = context; const schema: SchemaObject = { type: Types.OBJECT, @@ -547,7 +547,7 @@ export class OpenAPIV3Visitor extends BaseVisitor { this.schemas[union.name] = schema; } - visitAlias(context: Context): void { + public override visitAlias(context: Context): void { const a = context.alias; const schema = this.typeToSchema(a); this.schemas[a.name] = schema; diff --git a/src/openapiv3/types.ts b/src/openapiv3/types.ts new file mode 100644 index 0000000..b3c9dcf --- /dev/null +++ b/src/openapiv3/types.ts @@ -0,0 +1,313 @@ +type UnknownRecord = Record; + +export type Document = { + readonly openapi: string; + readonly info: InfoObject; + readonly servers?: ServerObject[]; + readonly paths: PathsObject; + readonly components?: ComponentsObject; + readonly security?: SecurityRequirementObject[]; + readonly tags?: TagObject[]; + readonly externalDocs?: ExternalDocumentationObject; +}; + +export type InfoObject = { + readonly title: string; + readonly description?: string; + readonly termsOfService?: string; + readonly contact?: ContactObject; + readonly license?: LicenseObject; + readonly version: string; +}; + +export type ContactObject = { + readonly name?: string; + readonly url?: string; + readonly email?: string; +}; + +export type LicenseObject = { + readonly name: string; + readonly url?: string; +}; + +export type ServerObject = { + readonly url: string; + readonly description?: string; + readonly variables?: { [variable: string]: ServerVariableObject }; +}; + +export type ServerVariableObject = { + readonly enum?: string[]; + readonly default: string; + readonly description?: string; +}; + +export type PathsObject = { + readonly [pattern: string]: PathItemObject | undefined; +}; + +export type PathItemObject = { + readonly $ref?: string; + readonly summary?: string; + readonly description?: string; + readonly get?: OperationObject; + readonly put?: OperationObject; + readonly post?: OperationObject; + readonly delete?: OperationObject; + readonly options?: OperationObject; + readonly head?: OperationObject; + readonly patch?: OperationObject; + readonly trace?: OperationObject; + readonly servers?: ServerObject[]; + readonly parameters?: (ReferenceObject | ParameterObject)[]; +}; + +export type OperationObject = { + readonly tags?: string[]; + readonly summary?: string; + readonly description?: string; + readonly externalDocs?: ExternalDocumentationObject; + readonly operationId?: string; + readonly parameters?: (ReferenceObject | ParameterObject)[]; + readonly requestBody?: ReferenceObject | RequestBodyObject; + readonly responses?: ResponsesObject; + readonly callbacks?: { [callback: string]: ReferenceObject | CallbackObject }; + readonly deprecated?: boolean; + readonly security?: SecurityRequirementObject[]; + readonly servers?: ServerObject[]; +} & T; + +export type ExternalDocumentationObject = { + readonly description?: string; + readonly url: string; +}; + +export type ParameterObject = ParameterBaseObject & { + readonly name: string; + readonly in: string; +}; + +export type HeaderObject = ParameterBaseObject; + +export type ParameterBaseObject = { + readonly description?: string; + readonly required?: boolean; + readonly deprecated?: boolean; + readonly allowEmptyValue?: boolean; + readonly style?: string; + readonly explode?: boolean; + readonly allowReserved?: boolean; + readonly schema?: ReferenceObject | SchemaObject; + readonly example?: unknown; + readonly examples?: { [media: string]: ReferenceObject | ExampleObject }; + readonly content?: { [media: string]: MediaTypeObject }; +}; + +export type NonArraySchemaObjectType = + | "boolean" + | "object" + | "number" + | "string" + | "integer"; + +export type ArraySchemaObjectType = "array"; + +export type SchemaObject = ArraySchemaObject | NonArraySchemaObject; + +export type ArraySchemaObject = BaseSchemaObject & { + readonly type: ArraySchemaObjectType; + readonly items: ReferenceObject | SchemaObject; +}; + +export type NonArraySchemaObject = BaseSchemaObject & { + readonly type?: NonArraySchemaObjectType; +}; + +export type BaseSchemaObject = { + readonly title?: string; + readonly description?: string; + readonly format?: string; + readonly default?: unknown; + readonly multipleOf?: number; + readonly maximum?: number; + readonly exclusiveMaximum?: boolean; + readonly minimum?: number; + readonly exclusiveMinimum?: boolean; + readonly maxLength?: number; + readonly minLength?: number; + readonly pattern?: string; + readonly additionalProperties?: boolean | ReferenceObject | SchemaObject; + readonly maxItems?: number; + readonly minItems?: number; + readonly uniqueItems?: boolean; + readonly maxProperties?: number; + readonly minProperties?: number; + readonly required?: string[]; + readonly enum?: unknown[]; + readonly properties?: { + [name: string]: ReferenceObject | SchemaObject; + }; + readonly allOf?: (ReferenceObject | SchemaObject)[]; + readonly oneOf?: (ReferenceObject | SchemaObject)[]; + readonly anyOf?: (ReferenceObject | SchemaObject)[]; + readonly not?: ReferenceObject | SchemaObject; + + // OpenAPI-specific properties + readonly nullable?: boolean; + readonly discriminator?: DiscriminatorObject; + readonly readOnly?: boolean; + readonly writeOnly?: boolean; + readonly xml?: XMLObject; + readonly externalDocs?: ExternalDocumentationObject; + readonly example?: unknown; + readonly deprecated?: boolean; +}; + +export type DiscriminatorObject = { + readonly propertyName: string; + readonly mapping?: { [value: string]: string }; +}; + +export type XMLObject = { + readonly name?: string; + readonly namespace?: string; + readonly prefix?: string; + readonly attribute?: boolean; + readonly wrapped?: boolean; +}; + +export type ReferenceObject = { + readonly $ref: string; +}; + +export type ExampleObject = { + readonly summary?: string; + readonly description?: string; + readonly value?: unknown; + readonly externalValue?: string; +}; + +export type MediaTypeObject = { + readonly schema?: ReferenceObject | SchemaObject; + readonly example?: unknown; + readonly examples?: { [media: string]: ReferenceObject | ExampleObject }; + readonly encoding?: { [media: string]: EncodingObject }; +}; + +export type EncodingObject = { + readonly contentType?: string; + readonly headers?: { [header: string]: ReferenceObject | HeaderObject }; + readonly style?: string; + readonly explode?: boolean; + readonly allowReserved?: boolean; +}; + +export type RequestBodyObject = { + readonly description?: string; + readonly content: { [media: string]: MediaTypeObject }; + readonly required?: boolean; +}; + +export type ResponsesObject = { + readonly [code: string]: ReferenceObject | ResponseObject; +}; + +export type ResponseObject = { + readonly description: string; + readonly headers?: { [header: string]: ReferenceObject | HeaderObject }; + readonly content?: { [media: string]: MediaTypeObject }; + readonly links?: { [link: string]: ReferenceObject | LinkObject }; +}; + +export type LinkObject = { + readonly operationRef?: string; + readonly operationId?: string; + readonly parameters?: { [parameter: string]: unknown }; + readonly requestBody?: unknown; + readonly description?: string; + readonly server?: ServerObject; +}; + +export type CallbackObject = { + readonly [url: string]: PathItemObject; +}; + +export type SecurityRequirementObject = { + readonly [name: string]: string[]; +}; + +export type ComponentsObject = { + readonly schemas?: { [key: string]: ReferenceObject | SchemaObject }; + readonly responses?: { [key: string]: ReferenceObject | ResponseObject }; + readonly parameters?: { [key: string]: ReferenceObject | ParameterObject }; + readonly examples?: { [key: string]: ReferenceObject | ExampleObject }; + readonly requestBodies?: { + [key: string]: ReferenceObject | RequestBodyObject; + }; + readonly headers?: { [key: string]: ReferenceObject | HeaderObject }; + readonly securitySchemes?: { + [key: string]: ReferenceObject | SecuritySchemeObject; + }; + readonly links?: { [key: string]: ReferenceObject | LinkObject }; + readonly callbacks?: { [key: string]: ReferenceObject | CallbackObject }; +}; + +export type SecuritySchemeObject = + | HttpSecurityScheme + | ApiKeySecurityScheme + | OAuth2SecurityScheme + | OpenIdSecurityScheme; + +export type HttpSecurityScheme = { + readonly type: "http"; + readonly description?: string; + readonly scheme: string; + readonly bearerFormat?: string; +}; + +export type ApiKeySecurityScheme = { + readonly type: "apiKey"; + readonly description?: string; + readonly name: string; + readonly in: string; +}; + +export type OAuth2SecurityScheme = { + readonly type: "oauth2"; + readonly flows: { + readonly implicit?: { + readonly authorizationUrl: string; + readonly refreshUrl?: string; + readonly scopes: { [scope: string]: string }; + }; + readonly password?: { + readonly tokenUrl: string; + readonly refreshUrl?: string; + readonly scopes: { [scope: string]: string }; + }; + readonly clientCredentials?: { + readonly tokenUrl: string; + readonly refreshUrl?: string; + readonly scopes: { [scope: string]: string }; + }; + readonly authorizationCode?: { + readonly authorizationUrl: string; + readonly tokenUrl: string; + readonly refreshUrl?: string; + readonly scopes: { [scope: string]: string }; + }; + }; +}; + +export type OpenIdSecurityScheme = { + readonly type: "openIdConnect"; + readonly description?: string; + readonly openIdConnectUrl: string; +}; + +export type TagObject = { + readonly name: string; + readonly description?: string; + readonly externalDocs?: ExternalDocumentationObject; +}; diff --git a/src/proto/proto_visitor.ts b/src/proto/proto_visitor.ts index 923285f..d0b0442 100644 --- a/src/proto/proto_visitor.ts +++ b/src/proto/proto_visitor.ts @@ -15,22 +15,22 @@ limitations under the License. */ import { - Alias, - AnyType, + type Alias, + type AnyType, BaseVisitor, - Context, - Enum, + type Context, + type Enum, Kind, - List as ListType, - Map as MapType, - Named, - Optional, - Primitive, + type List as ListType, + type Map as MapType, + type Named, + type Optional, + type Primitive, PrimitiveName, - Stream, - Type, - Writer, -} from "../deps/core/model.ts"; + type Stream, + type Type, + type Writer, +} from "@apexlang/core/model"; import { convertOperationToType, ExposedTypesVisitor, @@ -55,7 +55,7 @@ export class ProtoVisitor extends BaseVisitor { private exposedTypes = new Set(); private valueTypes = new Set(); - visitNamespaceBefore(context: Context) { + public override visitNamespaceBefore(context: Context) { const ns = context.namespace; const exposedTypes = new ExposedTypesVisitor(this.writer); ns.accept(context, exposedTypes); @@ -65,13 +65,13 @@ export class ProtoVisitor extends BaseVisitor { this.valueTypes = wrapperTypes.found; } - visitNamespaceAfter(context: Context): void { + public override visitNamespaceAfter(context: Context): void { for (const request of this.requestTypes) { request.accept(context.clone({ type: request }), this); } } - visitNamespace(context: Context): void { + public override visitNamespace(context: Context): void { const ns = context.namespace; this.write(`syntax = "proto3"; @@ -87,7 +87,7 @@ package ${ns.name};\n\n`); ns.accept(context, visitor); } - visitInterface(context: Context) { + public override visitInterface(context: Context) { if (!shouldIncludeHandler(context)) { return; } @@ -99,7 +99,7 @@ package ${ns.name};\n\n`); context.interface.accept(context, visitor); } - visitTypeBefore(context: Context): void { + public override visitTypeBefore(context: Context): void { const { type } = context; if (!this.exposedTypes.has(type.name)) { return; @@ -108,7 +108,7 @@ package ${ns.name};\n\n`); this.write(`message ${type.name} {\n`); } - visitTypeField(context: Context): void { + public override visitTypeField(context: Context): void { const { type, field } = context; if (!this.exposedTypes.has(type.name)) { return; @@ -126,7 +126,7 @@ package ${ns.name};\n\n`); ); } - visitTypeAfter(context: Context): void { + public override visitTypeAfter(context: Context): void { const { type } = context; if (!this.exposedTypes.has(type.name)) { return; @@ -134,7 +134,7 @@ package ${ns.name};\n\n`); this.write(`}\n\n`); } - visitEnum(context: Context): void { + public override visitEnum(context: Context): void { const e = context.enum; if (!this.exposedTypes.has(e.name)) { return; @@ -154,7 +154,7 @@ package ${ns.name};\n\n`); this.write(`}\n\n`); } - visitUnion(context: Context): void { + public override visitUnion(context: Context): void { const u = context.union; if (!this.exposedTypes.has(u.name)) { return; @@ -196,7 +196,8 @@ class RoleVisitor extends BaseVisitor { this.requestTypes = requestTypes; this.exposedTypes = exposedTypes; } - visitInterfaceBefore(context: Context): void { + + public override visitInterfaceBefore(context: Context): void { if (!shouldIncludeHandler(context)) { return; } @@ -205,7 +206,7 @@ class RoleVisitor extends BaseVisitor { this.write(`service ${iface.name} {\n`); } - visitOperationBefore(context: Context): void { + public override visitOperationBefore(context: Context): void { if (!shouldIncludeHandler(context)) { return; } @@ -267,13 +268,13 @@ class RoleVisitor extends BaseVisitor { this.write(`) {};\n`); } - visitOperationAfter(context: Context): void { + public override visitOperationAfter(context: Context): void { if (!shouldIncludeHandler(context)) { return; } } - visitInterfaceAfter(context: Context): void { + public override visitInterfaceAfter(context: Context): void { if (!shouldIncludeHandler(context)) { return; } @@ -386,7 +387,7 @@ class ImportVisitor extends BaseVisitor { } } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { if (!shouldIncludeHandler(context)) { return; } @@ -398,7 +399,7 @@ class ImportVisitor extends BaseVisitor { this.checkSingleType(operation.type); } - visitParameter(context: Context): void { + public override visitParameter(context: Context): void { if (!shouldIncludeHandler(context)) { return; } @@ -406,17 +407,17 @@ class ImportVisitor extends BaseVisitor { this.checkType(parameter.type); } - visitType(context: Context): void { + public override visitType(context: Context): void { const { type } = context; this.checkType(type); } - visitTypeField(context: Context): void { + public override visitTypeField(context: Context): void { const { field } = context; this.checkType(field.type); } - visitNamespaceAfter(_context: Context): void { + public override visitNamespaceAfter(_context: Context): void { if (this.found.size > 0) { this.write(`\n`); } @@ -457,7 +458,7 @@ function primitiveMessageType(name: PrimitiveName): string { export class WrapperTypesVisitor extends BaseVisitor { found: Set = new Set(); - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { if (!isService(context)) { return; } diff --git a/src/python/args_visitor.ts b/src/python/args_visitor.ts index e96fad8..bfcd89e 100644 --- a/src/python/args_visitor.ts +++ b/src/python/args_visitor.ts @@ -14,12 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { BaseVisitor, Context } from "../deps/core/model.ts"; +import { BaseVisitor, type Context } from "@apexlang/core/model"; import { convertOperationToType, noCode } from "../utils/mod.ts"; import { ClassVisitor } from "./class_visitor.ts"; export class ArgsVisitor extends BaseVisitor { - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { const { interface: iface, operation } = context; if (noCode(operation)) { return; diff --git a/src/python/class_visitor.ts b/src/python/class_visitor.ts index 1a326ad..2931512 100644 --- a/src/python/class_visitor.ts +++ b/src/python/class_visitor.ts @@ -14,12 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { BaseVisitor, Context, Kind } from "../deps/core/model.ts"; +import { BaseVisitor, type Context, Kind } from "@apexlang/core/model"; import { defValue, expandType } from "./helpers.ts"; import { formatComment, snakeCase } from "../utils/mod.ts"; export class ClassVisitor extends BaseVisitor { - visitTypeBefore(context: Context): void { + public override visitTypeBefore(context: Context): void { super.triggerTypeBefore(context); const t = context.type!; this.write(`@deserialize @@ -33,7 +33,7 @@ export class ClassVisitor extends BaseVisitor { this.write(`${t.name}:\n`); } - visitTypeField(context: Context): void { + public override visitTypeField(context: Context): void { const field = context.field!; this.write(formatComment("\t# ", field.description)); let defaultSuffix = ""; @@ -59,7 +59,7 @@ export class ClassVisitor extends BaseVisitor { super.triggerTypeField(context); } - visitTypeAfter(_context: Context): void { + public override visitTypeAfter(_context: Context): void { this.write(`\n\n`); } } diff --git a/src/python/constant.ts b/src/python/constant.ts index 8934408..b77c09c 100644 --- a/src/python/constant.ts +++ b/src/python/constant.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -export const translations = new Map([ +export const translations: Map = new Map([ ["ID", "str"], ["string", "str"], ["i64", "int"], diff --git a/src/python/handler_visitor.ts b/src/python/handler_visitor.ts index 8ac4c32..e9f66e6 100644 --- a/src/python/handler_visitor.ts +++ b/src/python/handler_visitor.ts @@ -14,19 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { BaseVisitor, Context } from "../deps/core/model.ts"; +import { BaseVisitor, type Context } from "@apexlang/core/model"; import { expandType } from "./helpers.ts"; import { formatComment, isVoid, noCode, snakeCase } from "../utils/mod.ts"; export class HandlerVisitor extends BaseVisitor { - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { super.triggerInterfaceBefore(context); const { interface: iface } = context; this.write(formatComment("# ", iface.description)); this.write(`class ${iface.name}:\n`); } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { const { operation } = context; if (noCode(operation)) { return; @@ -56,7 +56,7 @@ export class HandlerVisitor extends BaseVisitor { super.triggerOperation(context); } - visitInterfaceAfter(context: Context): void { + public override visitInterfaceAfter(context: Context): void { this.write(`\n\n`); super.triggerInterfaceAfter(context); } diff --git a/src/python/helpers.ts b/src/python/helpers.ts index 2f8e92d..e613a51 100644 --- a/src/python/helpers.ts +++ b/src/python/helpers.ts @@ -29,7 +29,7 @@ import { PrimitiveName, Type, Valued, -} from "../deps/core/model.ts"; +} from "@apexlang/core/model"; import { capitalize, snakeCase } from "../utils/mod.ts"; /** @@ -148,9 +148,9 @@ export function defaultValueForType(type: AnyType): string { * returns string in quotes * @param s string to have quotes */ -export const strQuote = (s: string) => { +export function strQuote(s: string): string { return `'${s}'`; -}; +} /** * returns string of the expanded type of a node diff --git a/src/python/interface_visitor.ts b/src/python/interface_visitor.ts index e8e8aa2..703ff88 100644 --- a/src/python/interface_visitor.ts +++ b/src/python/interface_visitor.ts @@ -14,19 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { BaseVisitor, Context } from "../deps/core/model.ts"; +import { BaseVisitor, type Context } from "@apexlang/core/model"; import { expandType, mapArg, mapArgs } from "./helpers.ts"; import { formatComment, isVoid, noCode, snakeCase } from "../utils/mod.ts"; export class InterfaceVisitor extends BaseVisitor { - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { super.triggerInterfaceBefore(context); const { interface: iface } = context; this.write(formatComment("# ", iface.description)); this.write(`class ${iface.name}:\n`); } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { const operation = context.operation; if (noCode(operation)) { return; @@ -52,7 +52,7 @@ export class InterfaceVisitor extends BaseVisitor { super.triggerOperation(context); } - visitInterfaceAfter(_context: Context): void { + public override visitInterfaceAfter(_context: Context): void { this.write(`\n\n`); } } diff --git a/src/python/interfaces_visitor.ts b/src/python/interfaces_visitor.ts index 4d7bba3..e769aeb 100644 --- a/src/python/interfaces_visitor.ts +++ b/src/python/interfaces_visitor.ts @@ -15,23 +15,23 @@ limitations under the License. */ import { - Alias, - AnyType, + type Alias, + type AnyType, BaseVisitor, Context, - Enum, + type Enum, Kind, - Type, - Union, - Visitor, -} from "../deps/core/model.ts"; + type Type, + type Union, + type Visitor, +} from "@apexlang/core/model"; import { ClassVisitor } from "./class_visitor.ts"; import { InterfaceVisitor } from "./interface_visitor.ts"; import { isHandler, isProvider, visitNamed } from "../utils/mod.ts"; import { HandlerVisitor } from "./handler_visitor.ts"; export class InterfacesVisitor extends BaseVisitor { - visitNamespaceBefore(context: Context): void { + public override visitNamespaceBefore(context: Context): void { this.write(`from typing import Optional, Awaitable, Type, TypeVar from serde import serialize, deserialize from dataclasses import dataclass, field\n\n\n`); @@ -42,12 +42,12 @@ from dataclasses import dataclass, field\n\n\n`); } class TypesVisitor extends BaseVisitor { - visitTypeBefore(context: Context): void { + public override visitTypeBefore(context: Context): void { const clazz = new ClassVisitor(this.writer); context.type!.accept(context, clazz); } - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { if (isProvider(context)) { const iface = new InterfaceVisitor(this.writer); context.interface.accept(context, iface); diff --git a/src/python/provider_visitor.ts b/src/python/provider_visitor.ts index 1256d4a..6fb57a3 100644 --- a/src/python/provider_visitor.ts +++ b/src/python/provider_visitor.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { BaseVisitor, Context } from "../deps/core/model.ts"; +import { BaseVisitor, type Context } from "@apexlang/core/model"; import { expandType } from "./helpers.ts"; import { camelCase, @@ -26,14 +26,14 @@ import { } from "../utils/mod.ts"; export class ProviderVisitor extends BaseVisitor { - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { const { interface: iface } = context; this.write(`class ${iface.name}Impl(${iface.name}): \tdef __init__(self, invoker: Invoker): \t\tself.invoker = invoker\n\n`); } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { const { interface: iface } = context; this.write(`\n`); const operation = context.operation!; @@ -90,7 +90,7 @@ export class ProviderVisitor extends BaseVisitor { super.triggerOperation(context); } - visitInterfaceAfter(context: Context): void { + public override visitInterfaceAfter(context: Context): void { if (!isProvider(context)) { super.triggerInterfaceAfter(context); return; diff --git a/src/python/scaffold_visitor.ts b/src/python/scaffold_visitor.ts index b80ae90..6d106dc 100644 --- a/src/python/scaffold_visitor.ts +++ b/src/python/scaffold_visitor.ts @@ -15,17 +15,17 @@ limitations under the License. */ import { - Alias, - AnyType, + type Alias, + type AnyType, BaseVisitor, - Context, + type Context, Kind, - List, - Map, - Optional, - Type, - Writer, -} from "../deps/core/model.ts"; + type List, + type Map, + type Optional, + type Type, + type Writer, +} from "@apexlang/core/model"; import { defaultValueForType, expandType, mapArg, mapArgs } from "./helpers.ts"; import { isHandler, @@ -36,7 +36,7 @@ import { } from "../utils/mod.ts"; export class ScaffoldVisitor extends BaseVisitor { - visitNamespaceBefore(context: Context): void { + public override visitNamespaceBefore(context: Context): void { this.write(`#!/usr/bin/env python3\n`); const adapter = new AdapterTypesVisitor(this.writer); context.namespace.accept(context, adapter); @@ -45,7 +45,7 @@ export class ScaffoldVisitor extends BaseVisitor { this.write(`\n`); } - visitNamespaceAfter(context: Context): void { + public override visitNamespaceAfter(context: Context): void { const main = new MainVisitor(this.writer); context.namespace.accept(context, main); @@ -54,7 +54,7 @@ export class ScaffoldVisitor extends BaseVisitor { \n`); } - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { if (!isHandler(context)) { return; } @@ -64,11 +64,11 @@ export class ScaffoldVisitor extends BaseVisitor { } class MainVisitor extends BaseVisitor { - visitNamespaceBefore(_context: Context): void { + public override visitNamespaceBefore(_context: Context): void { this.write(`def main():\n`); } - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { if (!isHandler(context)) { return; } @@ -77,7 +77,7 @@ class MainVisitor extends BaseVisitor { this.write(`\tregister_${snakeCase(name)}(${name}Impl())\n`); } - visitNamespaceAfter(_context: Context): void { + public override visitNamespaceAfter(_context: Context): void { this.write(`\n\tstart()\n`); } } @@ -90,7 +90,7 @@ class ImplVisitor extends BaseVisitor { this.stateful = stateful; } - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { if (!isHandler(context)) { return; } @@ -99,7 +99,7 @@ class ImplVisitor extends BaseVisitor { this.write(`class ${name}Impl(${name}):\n`); } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { this.write(`\n`); const { operation } = context; if (noCode(operation)) { @@ -134,16 +134,17 @@ class ImplVisitor extends BaseVisitor { super.triggerOperation(context); } - visitInterfaceAfter(_context: Context): void { + public override visitInterfaceAfter(_context: Context): void { this.write(`\n\n`); } } class AdapterTypesVisitor extends BaseVisitor { - visitNamespaceBefore(_content: Context): void { + public override visitNamespaceBefore(_content: Context): void { this.write(`from adapter import start`); } - visitInterface(context: Context): void { + + public override visitInterface(context: Context): void { const { interface: iface } = context; if (isHandler(context)) { this.write(`, register_${snakeCase(iface.name)}`); @@ -152,7 +153,8 @@ class AdapterTypesVisitor extends BaseVisitor { this.write(`, ${snakeCase(iface.name)}`); } } - visitNamespaceAfter(_content: Context): void { + + public override visitNamespaceAfter(_content: Context): void { this.write(`\n`); } } @@ -161,7 +163,7 @@ class TypesVisitor extends BaseVisitor { hasObjects = false; found: Set = new Set(); - visitNamespaceBefore(_context: Context): void {} + public override visitNamespaceBefore(_context: Context): void {} private addImport(name: string): void { if (!this.found.has(name)) { @@ -204,24 +206,24 @@ class TypesVisitor extends BaseVisitor { } } - visitInterface(context: Context): void { + public override visitInterface(context: Context): void { const { interface: iface } = context; if (isHandler(context)) { this.addImport(iface.name); } } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { const operation = context.operation!; this.addType(operation.type); } - visitParameter(context: Context): void { + public override visitParameter(context: Context): void { const parameter = context.parameter!; this.addType(parameter.type); } - visitNamespaceAfter(_context: Context): void { + public override visitNamespaceAfter(_context: Context): void { if (this.hasObjects) { this.write(`\n\n`); } diff --git a/src/python/wrapper_visitor.ts b/src/python/wrapper_visitor.ts index c134528..106d1ea 100644 --- a/src/python/wrapper_visitor.ts +++ b/src/python/wrapper_visitor.ts @@ -14,18 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { BaseVisitor, Context } from "../deps/core/model.ts"; +import { BaseVisitor, type Context } from "@apexlang/core/model"; import { expandType } from "./helpers.ts"; import { capitalize, isVoid, noCode, snakeCase } from "../utils/mod.ts"; export class WrapperVisitor extends BaseVisitor { - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { super.triggerInterfaceBefore(context); const { interface: iface } = context; this.write(`def register_${snakeCase(iface.name)}(h: ${iface.name}):\n`); } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { const { interface: iface } = context; const operation = context.operation!; if (noCode(operation)) { @@ -74,14 +74,14 @@ export class WrapperVisitor extends BaseVisitor { super.triggerOperation(context); } - visitInterfaceAfter(context: Context): void { + public override visitInterfaceAfter(context: Context): void { this.write(`\n\n`); super.triggerInterfaceAfter(context); } } export class WrapperStatefulVisitor extends BaseVisitor { - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { super.triggerInterfaceBefore(context); const { namespace: ns, interface: iface } = context; const fullns = ns.name + "." + iface.name; @@ -93,7 +93,7 @@ export class WrapperStatefulVisitor extends BaseVisitor { ); } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { const { namespace: ns, interface: iface } = context; const fullns = ns.name + "." + iface.name; const operation = context.operation!; @@ -152,7 +152,7 @@ export class WrapperStatefulVisitor extends BaseVisitor { super.triggerOperation(context); } - visitInterfaceAfter(context: Context): void { + public override visitInterfaceAfter(context: Context): void { this.write(`\n\n`); super.triggerInterfaceAfter(context); } diff --git a/src/rest/mod.ts b/src/rest/mod.ts index ec52e5e..3be191e 100644 --- a/src/rest/mod.ts +++ b/src/rest/mod.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { Context, Operation } from "../deps/core/model.ts"; +import { Context, Operation } from "@apexlang/core/model"; export interface PathDirective { value: string; diff --git a/src/rust/rust-basic.ts b/src/rust/rust-basic.ts index f49baa3..1b9f8ad 100644 --- a/src/rust/rust-basic.ts +++ b/src/rust/rust-basic.ts @@ -1,4 +1,4 @@ -import { Context, Writer } from "../deps/core/model.ts"; +import type { Context, Writer } from "@apexlang/core/model"; import { ContextWriter } from "./visitors/base.ts"; import { StructVisitor } from "./visitors/struct_visitor.ts"; import { @@ -24,7 +24,7 @@ export class RustBasic extends ContextWriter { super(writer); } - visitContextBefore(context: Context): void { + public override visitContextBefore(context: Context): void { this.append( utils.generatedHeader( context.config.generatedHeader || [ @@ -43,28 +43,28 @@ export class RustBasic extends ContextWriter { } } - visitType(context: Context): void { + public override visitType(context: Context): void { this.append(new StructVisitor(context.type, context).toString()); } - visitInterface(context: Context): void { + public override visitInterface(context: Context): void { this.append(new InterfaceVisitor(context.interface, context).toString()); } - visitEnum(context: Context): void { + public override visitEnum(context: Context): void { this.append(new EnumVisitor(context.enum, context).toString()); } - visitUnion(context: Context): void { + public override visitUnion(context: Context): void { this.append(new UnionVisitor(context.union, context).toString()); } - visitFunction(context: Context): void { + public override visitFunction(context: Context): void { const vis = visibility(context.operation.name, context.config); this.append(genOperation(context.operation, vis, context.config)); } - visitAlias(context: Context): void { + public override visitAlias(context: Context): void { const { alias } = context; const vis = visibility(alias.name, context.config); diff --git a/src/rust/utils/mod.ts b/src/rust/utils/mod.ts index 81199ca..6c4338e 100644 --- a/src/rust/utils/mod.ts +++ b/src/rust/utils/mod.ts @@ -29,7 +29,7 @@ export function rustifyCaps(name: string): string { return base; } -import { ObjectMap } from "../../deps/core/model.ts"; +import type { ObjectMap } from "@apexlang/core/model"; export type visibility = "pub" | "pub(crate)" | ""; diff --git a/src/rust/utils/types.ts b/src/rust/utils/types.ts index fa66a33..6ff0158 100644 --- a/src/rust/utils/types.ts +++ b/src/rust/utils/types.ts @@ -1,16 +1,16 @@ // deno-lint-ignore-file no-explicit-any import { - AnyType, + type AnyType, Kind, - List, - Map, - Named, - ObjectMap, - Optional, - Primitive, + type List, + type Map, + type Named, + type ObjectMap, + type Optional, + type Primitive, PrimitiveName, - Stream, -} from "../../deps/core/model.ts"; + type Stream, +} from "@apexlang/core/model"; import { rustifyCaps } from "./mod.ts"; export function apexToRustType( diff --git a/src/rust/visitors/base.ts b/src/rust/visitors/base.ts index 63d227b..2c56ce4 100644 --- a/src/rust/visitors/base.ts +++ b/src/rust/visitors/base.ts @@ -1,14 +1,14 @@ import { AbstractVisitor, - Alias, + type Alias, BaseVisitor, - Context, - Enum, - Interface, - Type, - Union, - Writer, -} from "../../deps/core/model.ts"; + type Context, + type Enum, + type Interface, + type Type, + type Union, + type Writer, +} from "@apexlang/core/model"; export type VisitorTypes = Alias | Type | Union | Enum | Interface; @@ -31,7 +31,7 @@ export class SourceGenerator extends AbstractVisitor { return this.source; } - toString(): string { + public override toString(): string { this.root.accept(this.context, this); return this.getSource(); } @@ -48,7 +48,7 @@ export class ContextWriter extends BaseVisitor { this.source += source; } - visitContextAfter(_context: Context): void { + public override visitContextAfter(_context: Context): void { this.write(this.source); } } diff --git a/src/rust/visitors/enum_visitor.ts b/src/rust/visitors/enum_visitor.ts index 031d509..fc60f00 100644 --- a/src/rust/visitors/enum_visitor.ts +++ b/src/rust/visitors/enum_visitor.ts @@ -1,5 +1,5 @@ -import { Context, Enum, ObjectMap } from "../../deps/core/model.ts"; -import { IndexTypeDirective } from "../directives.ts"; +import type { Context, Enum, ObjectMap } from "@apexlang/core/model"; +import type { IndexTypeDirective } from "../directives.ts"; import { customAttributes, rustDoc, @@ -22,7 +22,7 @@ export class EnumVisitor extends SourceGenerator { this.visibility = visibility(this.root.name, this.config); } - getSource(): string { + public override getSource(): string { const optionalDisplayImpl = this.hasDisplayValues ? displayImpl(this.root) : ""; @@ -56,7 +56,7 @@ export class EnumVisitor extends SourceGenerator { `; } - visitEnumValue(context: Context): void { + public override visitEnumValue(context: Context): void { const { enumValue } = context; this.hasDisplayValues ||= enumValue.display !== undefined; this.hasIndices ||= enumValue.index !== undefined; diff --git a/src/rust/visitors/interface_visitor.ts b/src/rust/visitors/interface_visitor.ts index 534f1cf..15b09f4 100644 --- a/src/rust/visitors/interface_visitor.ts +++ b/src/rust/visitors/interface_visitor.ts @@ -1,10 +1,10 @@ // deno-lint-ignore-file no-explicit-any -import { +import type { Context, Interface, ObjectMap, Operation, -} from "../../deps/core/model.ts"; +} from "@apexlang/core/model"; import { customAttributes, rustDoc, @@ -27,7 +27,7 @@ export class InterfaceVisitor extends SourceGenerator { this.visibility = visibility(this.root.name, this.config); } - getSource(): string { + public override getSource(): string { const prefix = trimLines([ rustDoc(this.root.description), customAttributes(this.root.name, this.config), @@ -37,7 +37,7 @@ export class InterfaceVisitor extends SourceGenerator { ${this.visibility} trait ${rustifyCaps(this.root.name)} {${this.source}}\n`; } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { this.append(genOperation(context.operation, this.visibility, this.config)); } } diff --git a/src/rust/visitors/struct_visitor.ts b/src/rust/visitors/struct_visitor.ts index c9c7534..7456169 100644 --- a/src/rust/visitors/struct_visitor.ts +++ b/src/rust/visitors/struct_visitor.ts @@ -1,5 +1,10 @@ // deno-lint-ignore-file no-explicit-any -import { Context, Kind, ObjectMap, Type } from "../../deps/core/model.ts"; +import { + type Context, + Kind, + type ObjectMap, + type Type, +} from "@apexlang/core/model"; import { isPrimitive, isRecursiveType } from "../../utils/mod.ts"; import { customAttributes, @@ -25,7 +30,7 @@ export class StructVisitor extends SourceGenerator { this.visibility = visibility(this.root.name, this.config); } - getSource(): string { + public override getSource(): string { const prefix = trimLines([ rustDoc(this.root.description), deriveDirective(this.root.name, this.config), @@ -39,7 +44,7 @@ export class StructVisitor extends SourceGenerator { }`; } - visitTypeField(context: Context): void { + public override visitTypeField(context: Context): void { const { field } = context; const isRecursive = isRecursiveType(field.type); const isHeapAllocated = field.type.kind === Kind.Map || diff --git a/src/rust/visitors/union_visitor.ts b/src/rust/visitors/union_visitor.ts index dcc6c7d..bca7bec 100644 --- a/src/rust/visitors/union_visitor.ts +++ b/src/rust/visitors/union_visitor.ts @@ -1,12 +1,12 @@ // deno-lint-ignore-file no-explicit-any import { - AnyType, - Context, + type AnyType, + type Context, Kind, - ObjectMap, - Primitive, - Union, -} from "../../deps/core/model.ts"; + type ObjectMap, + type Primitive, + type Union, +} from "@apexlang/core/model"; import { codegenType, isNamed, isRecursiveType } from "../../utils/mod.ts"; import { customAttributes, @@ -48,7 +48,7 @@ export class UnionVisitor extends SourceGenerator { this.visibility = visibility(this.root.name, this.config); } - getSource(): string { + public override getSource(): string { const variants = this.root.members.map((member) => { const t = member.type; const isRecursive = isRecursiveType(t); diff --git a/src/typescript/alias_visitor.ts b/src/typescript/alias_visitor.ts index d509c8b..0f5a6d0 100644 --- a/src/typescript/alias_visitor.ts +++ b/src/typescript/alias_visitor.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { BaseVisitor, Context } from "../deps/core/model.ts"; +import { BaseVisitor, type Context } from "@apexlang/core/model"; import { expandType } from "./helpers.ts"; import { formatComment } from "../utils/mod.ts"; @@ -44,7 +44,7 @@ export function defaultForAlias( } export class AliasVisitor extends BaseVisitor { - visitAlias(context: Context): void { + public override visitAlias(context: Context): void { const alias = context.alias!; const aliases = context.config.aliases as { [key: string]: Import }; diff --git a/src/typescript/api_visitor.ts b/src/typescript/api_visitor.ts index dd640a9..1229e79 100644 --- a/src/typescript/api_visitor.ts +++ b/src/typescript/api_visitor.ts @@ -15,17 +15,17 @@ limitations under the License. */ import { - AnyType, + type AnyType, BaseVisitor, - Context, - Interface, + type Context, + type Interface, Kind, - List, - Map, - Optional, - Type, - Writer, -} from "../deps/core/model.ts"; + type List, + type Map, + type Optional, + type Type, + type Writer, +} from "@apexlang/core/model"; import { camelCase, isHandler, @@ -37,18 +37,18 @@ import { import { defaultValueForType, expandType, mapArg, mapArgs } from "./helpers.ts"; export class ApiVisitor extends BaseVisitor { - visitNamespaceBefore(context: Context): void { + public override visitNamespaceBefore(context: Context): void { const types = new TypesVisitor(this.writer); context.namespace.accept(context, types); this.write(`\n`); } - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { const impl = new ImplVisitor(this.writer); context.interface.accept(context, impl); } - visitNamespaceAfter(_context: Context): void {} + public override visitNamespaceAfter(_context: Context): void {} } class ImplVisitor extends BaseVisitor { @@ -59,13 +59,13 @@ class ImplVisitor extends BaseVisitor { this.stateful = stateful; } - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { super.triggerInterfaceBefore(context); const { interface: iface } = context; this.write(`class ${iface.name}Impl implements ${iface.name} {`); } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { const { operation } = context; if (noCode(operation)) { return; @@ -90,17 +90,18 @@ class ImplVisitor extends BaseVisitor { super.triggerOperation(context); } - visitInterfaceAfter(context: Context): void { + public override visitInterfaceAfter(context: Context): void { this.write(`}\n\n`); super.triggerInterfaceAfter(context); } } -class AdapterTypesVisitor extends BaseVisitor { - visitNamespaceBefore(_content: Context): void { +class _AdapterTypesVisitor extends BaseVisitor { + public override visitNamespaceBefore(_content: Context): void { this.write(`import { start`); } - visitInterface(context: Context): void { + + public override visitInterface(context: Context): void { const { interface: iface } = context; if (isHandler(context)) { this.write(`, register${pascalCase(iface.name)}`); @@ -109,7 +110,8 @@ class AdapterTypesVisitor extends BaseVisitor { this.write(`, ${camelCase(iface.name)}`); } } - visitNamespaceAfter(_content: Context): void { + + public override visitNamespaceAfter(_content: Context): void { this.write(` } from "./adapter";\n`); } } @@ -161,24 +163,24 @@ class TypesVisitor extends BaseVisitor { } } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { const operation = context.operation!; this.addType(operation.type); } - visitInterface(context: Context): void { + public override visitInterface(context: Context): void { const iface = context.interface!; this.addType(iface); } - visitParameter(context: Context): void { + public override visitParameter(context: Context): void { const parameter = context.parameter!; this.addType(parameter.type); } - visitNamespaceBefore(_context: Context): void {} + public override visitNamespaceBefore(_context: Context): void {} - visitNamespaceAfter(_context: Context): void { + public override visitNamespaceAfter(_context: Context): void { if (this.hasObjects) { this.write(` } from "./interfaces";\n\n`); } diff --git a/src/typescript/args_visitor.ts b/src/typescript/args_visitor.ts index e96fad8..bfcd89e 100644 --- a/src/typescript/args_visitor.ts +++ b/src/typescript/args_visitor.ts @@ -14,12 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { BaseVisitor, Context } from "../deps/core/model.ts"; +import { BaseVisitor, type Context } from "@apexlang/core/model"; import { convertOperationToType, noCode } from "../utils/mod.ts"; import { ClassVisitor } from "./class_visitor.ts"; export class ArgsVisitor extends BaseVisitor { - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { const { interface: iface, operation } = context; if (noCode(operation)) { return; diff --git a/src/typescript/class_visitor.ts b/src/typescript/class_visitor.ts index 73cbf88..59b5f1a 100644 --- a/src/typescript/class_visitor.ts +++ b/src/typescript/class_visitor.ts @@ -14,15 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { BaseVisitor, Context, Field } from "../deps/core/model.ts"; +import { BaseVisitor, type Context, type Field } from "@apexlang/core/model"; import { defValue, expandType } from "./helpers.ts"; import { formatComment } from "../utils/mod.ts"; export class ClassVisitor extends BaseVisitor { - decorate(field: Field): string { + decorate(_field: Field): string { return ""; } - visitTypeBefore(context: Context): void { + + public override visitTypeBefore(context: Context): void { super.triggerTypeBefore(context); const t = context.type!; this.write(formatComment("// ", t.description)); @@ -32,7 +33,7 @@ export class ClassVisitor extends BaseVisitor { this.write(`class ${t.name} {\n`); } - visitTypeField(context: Context): void { + public override visitTypeField(context: Context): void { const field = context.field!; this.write(formatComment(" // ", field.description)); const et = expandType(field.type!, true); @@ -43,7 +44,7 @@ export class ClassVisitor extends BaseVisitor { super.triggerTypeField(context); } - visitTypeAfter(context: Context): void { + public override visitTypeAfter(context: Context): void { this.write(`\n`); const ctor = new ConstructorVisitor(this.writer); context.type!.accept(context.clone({ type: context.type! }), ctor); @@ -54,7 +55,7 @@ export class ClassVisitor extends BaseVisitor { } class ConstructorVisitor extends BaseVisitor { - visitTypeBefore(context: Context): void { + public override visitTypeBefore(context: Context): void { super.triggerTypeBefore(context); const t = context.type!; this.write(`constructor({\n`); @@ -72,13 +73,13 @@ class ConstructorVisitor extends BaseVisitor { this.write(`} = {}) {\n`); } - visitTypeField(context: Context): void { + public override visitTypeField(context: Context): void { const field = context.field!; this.write(` this.${field.name} = ${field.name}\n`); super.triggerTypeField(context); } - visitTypeAfter(context: Context): void { + public override visitTypeAfter(context: Context): void { this.write(`}\n`); super.triggerTypeAfter(context); } diff --git a/src/typescript/constant.ts b/src/typescript/constant.ts index 5105119..970a2cf 100644 --- a/src/typescript/constant.ts +++ b/src/typescript/constant.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -export const translations = new Map([ +export const translations: Map = new Map([ ["ID", "string"], ["bytes", "ArrayBuffer"], ["i64", "number"], diff --git a/src/typescript/enum_visitor.ts b/src/typescript/enum_visitor.ts index 27146a5..4ac2e73 100644 --- a/src/typescript/enum_visitor.ts +++ b/src/typescript/enum_visitor.ts @@ -14,17 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { BaseVisitor, Context } from "../deps/core/model.ts"; +import { BaseVisitor, type Context } from "@apexlang/core/model"; import { formatComment, pascalCase } from "../utils/mod.ts"; export class EnumVisitor extends BaseVisitor { - visitEnumBefore(context: Context): void { + public override visitEnumBefore(context: Context): void { super.triggerEnumsBefore(context); this.write(formatComment("// ", context.enum.description)); this.write(`export enum ${context.enum.name} {\n`); } - visitEnumValue(context: Context): void { + public override visitEnumValue(context: Context): void { const { enumValue } = context; this.write(formatComment("// ", enumValue.description)); this.write( @@ -33,7 +33,7 @@ export class EnumVisitor extends BaseVisitor { super.triggerTypeField(context); } - visitEnumAfter(context: Context): void { + public override visitEnumAfter(context: Context): void { this.write(`}\n\n`); super.triggerEnumsAfter(context); } diff --git a/src/typescript/handler_visitor.ts b/src/typescript/handler_visitor.ts index d5f8db4..4cc1484 100644 --- a/src/typescript/handler_visitor.ts +++ b/src/typescript/handler_visitor.ts @@ -14,12 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { BaseVisitor, Context } from "../deps/core/model.ts"; +import { BaseVisitor, type Context } from "@apexlang/core/model"; import { expandType, mapArg, mapArgs } from "./helpers.ts"; import { camelCase, formatComment, noCode } from "../utils/mod.ts"; export class HandlerVisitor extends BaseVisitor { - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { super.triggerInterfaceBefore(context); const { interface: iface } = context; this.write(formatComment("// ", iface.description)); @@ -27,7 +27,7 @@ export class HandlerVisitor extends BaseVisitor { \n`); } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { const { operation } = context; if (noCode(operation)) { return; @@ -45,7 +45,7 @@ export class HandlerVisitor extends BaseVisitor { super.triggerOperation(context); } - visitInterfaceAfter(context: Context): void { + public override visitInterfaceAfter(context: Context): void { this.write(`}\n\n`); super.triggerInterfaceAfter(context); } diff --git a/src/typescript/helpers.ts b/src/typescript/helpers.ts index f8a966e..b027e59 100644 --- a/src/typescript/helpers.ts +++ b/src/typescript/helpers.ts @@ -30,7 +30,7 @@ import { Primitive, Type, Valued, -} from "../deps/core/model.ts"; +} from "@apexlang/core/model"; import { capitalize, renamed } from "../utils/mod.ts"; import { defaultForAlias } from "./alias_visitor.ts"; import { translations } from "./constant.ts"; @@ -161,9 +161,9 @@ export function defaultValueForType(type: AnyType): string { * returns string in quotes * @param s string to have quotes */ -export const strQuote = (s: string) => { +export function strQuote(s: string): string { return `'${s}'`; -}; +} /** * returns string of the expanded type of a node diff --git a/src/typescript/imports_visitor.ts b/src/typescript/imports_visitor.ts index d1327ba..d61fb95 100644 --- a/src/typescript/imports_visitor.ts +++ b/src/typescript/imports_visitor.ts @@ -15,21 +15,21 @@ limitations under the License. */ import { - AnyType, + type AnyType, BaseVisitor, - Context, + type Context, Kind, - List, - Map, - Optional, - Type, -} from "../deps/core/model.ts"; -import { Import } from "./alias_visitor.ts"; + type List, + type Map, + type Optional, + type Type, +} from "@apexlang/core/model"; +import type { Import } from "./alias_visitor.ts"; export class ImportsVisitor extends BaseVisitor { private imports: { [key: string]: Import } = {}; - visitNamespaceAfter(_context: Context): void { + public override visitNamespaceAfter(_context: Context): void { const modules: { [module: string]: string[] } = {}; for (const key in this.imports) { const i = this.imports[key]; @@ -88,15 +88,15 @@ export class ImportsVisitor extends BaseVisitor { } } - visitParameter(context: Context): void { + public override visitParameter(context: Context): void { this.checkType(context, context.parameter!.type); } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { this.checkType(context, context.operation!.type); } - visitTypeField(context: Context): void { + public override visitTypeField(context: Context): void { this.checkType(context, context.field!.type); } } diff --git a/src/typescript/interface_visitor.ts b/src/typescript/interface_visitor.ts index 1f2fc57..cbaf3d9 100644 --- a/src/typescript/interface_visitor.ts +++ b/src/typescript/interface_visitor.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { BaseVisitor, Context, Writer } from "../deps/core/model.ts"; +import { BaseVisitor, type Context, type Writer } from "@apexlang/core/model"; import { expandType, mapArg, mapArgs } from "./helpers.ts"; import { camelCase, formatComment } from "../utils/mod.ts"; @@ -26,7 +26,7 @@ export class InterfaceVisitor extends BaseVisitor { this.stateful = stateful; } - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { super.triggerInterfaceBefore(context); const { interface: iface } = context; this.write(formatComment("// ", iface.description)); @@ -34,7 +34,7 @@ export class InterfaceVisitor extends BaseVisitor { \n`); } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { const operation = context.operation!; let opVal = ""; this.write(formatComment(" // ", operation.description)); @@ -49,7 +49,7 @@ export class InterfaceVisitor extends BaseVisitor { super.triggerOperation(context); } - visitInterfaceAfter(context: Context): void { + public override visitInterfaceAfter(context: Context): void { this.write(`}\n\n`); super.triggerInterfaceAfter(context); } diff --git a/src/typescript/interfaces_visitor.ts b/src/typescript/interfaces_visitor.ts index 1bd0cdc..7ff4428 100644 --- a/src/typescript/interfaces_visitor.ts +++ b/src/typescript/interfaces_visitor.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { BaseVisitor, Context } from "../deps/core/model.ts"; +import { BaseVisitor, type Context } from "@apexlang/core/model"; import { ClassVisitor } from "./class_visitor.ts"; import { EnumVisitor } from "./enum_visitor.ts"; import { InterfaceVisitor } from "./interface_visitor.ts"; @@ -22,28 +22,28 @@ import { AliasVisitor } from "./alias_visitor.ts"; import { ImportsVisitor } from "./imports_visitor.ts"; export class InterfacesVisitor extends BaseVisitor { - visitNamespaceBefore(context: Context): void { + public override visitNamespaceBefore(context: Context): void { const e = new ImportsVisitor(this.writer); context.namespace.accept(context, e); this.write(`\n`); } - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { const iface = new InterfaceVisitor(this.writer); context.interface.accept(context, iface); } - visitAlias(context: Context): void { + public override visitAlias(context: Context): void { const e = new AliasVisitor(this.writer); context.alias!.accept(context, e); } - visitEnum(context: Context): void { + public override visitEnum(context: Context): void { const e = new EnumVisitor(this.writer); context.enum!.accept(context, e); } - visitType(context: Context): void { + public override visitType(context: Context): void { const clazz = new ClassVisitor(this.writer); context.type!.accept(context, clazz); } diff --git a/src/typescript/plugin.ts b/src/typescript/plugin.ts index 0443ea6..4f8e7fe 100644 --- a/src/typescript/plugin.ts +++ b/src/typescript/plugin.ts @@ -1,5 +1,5 @@ -import { Configuration } from "https://deno.land/x/apex_cli@v0.0.18/src/config.ts"; -import * as ast from "https://deno.land/x/apex_core@v0.1.5/ast.ts"; +import { Configuration } from "@apexlang/apex/config.ts"; +import * as ast from "@apexlang/core/ast"; const importUrl = new URL(".", import.meta.url); @@ -25,13 +25,13 @@ export default function ( }; config.generates[`./src/api.ts`] = { ifNotExists: true, - module: "https://deno.land/x/apex_codegen/typescript/mod.ts", + module: "@apexlang/codegen/typescript", visitorClass: "ApiVisitor", config: {}, }; config.generates[`./src/interfaces.ts`] = { ifNotExists: true, - module: "https://deno.land/x/apex_codegen/typescript/mod.ts", + module: "@apexlang/codegen/typescript", visitorClass: "InterfacesVisitor", config: {}, }; diff --git a/src/typescript/provider_visitor.ts b/src/typescript/provider_visitor.ts index a4dd4e0..0ac5820 100644 --- a/src/typescript/provider_visitor.ts +++ b/src/typescript/provider_visitor.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { BaseVisitor, Context } from "../deps/core/model.ts"; +import { BaseVisitor, type Context } from "@apexlang/core/model"; import { expandType, strQuote } from "./helpers.ts"; import { camelCase, @@ -25,7 +25,7 @@ import { } from "../utils/mod.ts"; export class ProviderVisitor extends BaseVisitor { - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { const { interface: iface } = context; this.write(`export class ${iface.name}Impl implements ${iface.name} { private adapter: IAdapter; @@ -35,7 +35,7 @@ export class ProviderVisitor extends BaseVisitor { }\n\n`); } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { const { interface: iface } = context; this.write(`\n`); const operation = context.operation!; @@ -101,7 +101,7 @@ export class ProviderVisitor extends BaseVisitor { super.triggerOperation(context); } - visitInterfaceAfter(context: Context): void { + public override visitInterfaceAfter(context: Context): void { if (!isProvider(context)) { super.triggerInterfaceAfter(context); return; diff --git a/src/typescript/scaffold_visitor.ts b/src/typescript/scaffold_visitor.ts index 79b530e..a9323b8 100644 --- a/src/typescript/scaffold_visitor.ts +++ b/src/typescript/scaffold_visitor.ts @@ -15,16 +15,16 @@ limitations under the License. */ import { - AnyType, + type AnyType, BaseVisitor, - Context, + type Context, Kind, - List, - Map, - Optional, - Type, - Writer, -} from "../deps/core/model.ts"; + type List, + type Map, + type Optional, + type Type, + type Writer, +} from "@apexlang/core/model"; import { camelCase, isHandler, @@ -36,7 +36,7 @@ import { import { defaultValueForType, expandType, mapArg, mapArgs } from "./helpers.ts"; export class ScaffoldVisitor extends BaseVisitor { - visitNamespaceBefore(context: Context): void { + public override visitNamespaceBefore(context: Context): void { const adapter = new AdapterTypesVisitor(this.writer); context.namespace.accept(context, adapter); const types = new TypesVisitor(this.writer); @@ -44,14 +44,14 @@ export class ScaffoldVisitor extends BaseVisitor { this.write(`\n`); } - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { if (isHandler(context)) { const impl = new ImplVisitor(this.writer); context.interface.accept(context, impl); } } - visitNamespaceAfter(_context: Context): void { + public override visitNamespaceAfter(_context: Context): void { this.write(`\nstart();\n`); } } @@ -64,13 +64,13 @@ class ImplVisitor extends BaseVisitor { this.stateful = stateful; } - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { super.triggerInterfaceBefore(context); const { interface: iface } = context; this.write(`class ${iface.name}Impl {`); } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { const { operation } = context; if (noCode(operation)) { return; @@ -101,7 +101,7 @@ class ImplVisitor extends BaseVisitor { super.triggerOperation(context); } - visitInterfaceAfter(context: Context): void { + public override visitInterfaceAfter(context: Context): void { this.write(`}\n\n`); const name = context.interface.name; this.write(`register${pascalCase(name)}(new ${name}Impl());\n\n`); @@ -110,10 +110,11 @@ class ImplVisitor extends BaseVisitor { } class AdapterTypesVisitor extends BaseVisitor { - visitNamespaceBefore(_content: Context): void { + public override visitNamespaceBefore(_content: Context): void { this.write(`import { start`); } - visitInterface(context: Context): void { + + public override visitInterface(context: Context): void { const { interface: iface } = context; if (isHandler(context)) { this.write(`, register${pascalCase(iface.name)}`); @@ -122,7 +123,8 @@ class AdapterTypesVisitor extends BaseVisitor { this.write(`, ${camelCase(iface.name)}`); } } - visitNamespaceAfter(_content: Context): void { + + public override visitNamespaceAfter(_content: Context): void { this.write(` } from "./adapter";\n`); } } @@ -169,19 +171,19 @@ class TypesVisitor extends BaseVisitor { } } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { const operation = context.operation!; this.addType(operation.type); } - visitParameter(context: Context): void { + public override visitParameter(context: Context): void { const parameter = context.parameter!; this.addType(parameter.type); } - visitNamespaceBefore(_context: Context): void {} + public override visitNamespaceBefore(_context: Context): void {} - visitNamespaceAfter(_context: Context): void { + public override visitNamespaceAfter(_context: Context): void { if (this.hasObjects) { this.write(` } from "./interfaces";\n\n`); } diff --git a/src/typescript/service_interface_visitor.ts b/src/typescript/service_interface_visitor.ts index d6fed3c..d479e50 100644 --- a/src/typescript/service_interface_visitor.ts +++ b/src/typescript/service_interface_visitor.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { BaseVisitor, Context, Writer } from "../deps/core/model.ts"; +import { BaseVisitor, type Context, type Writer } from "@apexlang/core/model"; import { expandType, mapArg, mapArgs } from "./helpers.ts"; import { camelCase, formatComment } from "../utils/mod.ts"; @@ -26,7 +26,7 @@ export class ServiceInterfaceVisitor extends BaseVisitor { this.stateful = stateful; } - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { super.triggerInterfaceBefore(context); const { interface: iface } = context; this.write(formatComment("// ", iface.description)); @@ -34,7 +34,7 @@ export class ServiceInterfaceVisitor extends BaseVisitor { \n`); } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { const operation = context.operation!; let opVal = ""; this.write(formatComment(" // ", operation.description)); @@ -49,7 +49,7 @@ export class ServiceInterfaceVisitor extends BaseVisitor { super.triggerOperation(context); } - visitInterfaceAfter(context: Context): void { + public override visitInterfaceAfter(context: Context): void { this.write(`}\n\n`); super.triggerInterfaceAfter(context); } diff --git a/src/typescript/service_interfaces_visitor.ts b/src/typescript/service_interfaces_visitor.ts index 6d7e716..d7a7dd7 100644 --- a/src/typescript/service_interfaces_visitor.ts +++ b/src/typescript/service_interfaces_visitor.ts @@ -14,38 +14,38 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { BaseVisitor, Context } from "../deps/core/model.ts"; +import { BaseVisitor, type Context } from "@apexlang/core/model"; import { ClassVisitor } from "./class_visitor.ts"; import { ServiceInterfaceVisitor } from "./service_interface_visitor.ts"; import { AliasVisitor } from "./alias_visitor.ts"; import { ImportsVisitor } from "./imports_visitor.ts"; export class ServiceInterfacesVisitor extends BaseVisitor { - visitNamespaceBefore(context: Context): void { + public override visitNamespaceBefore(context: Context): void { this.write(`import { Expose, Type } from "class-transformer";\n`); const e = new ImportsVisitor(this.writer); context.namespace.accept(context, e); this.write(`\n`); } - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { const iface = new ServiceInterfaceVisitor(this.writer); context.interface.accept(context, iface); } - visitAlias(context: Context): void { + public override visitAlias(context: Context): void { const e = new AliasVisitor(this.writer); context.alias!.accept(context, e); } - // visitEnum(context: Context): void { + // public override visitEnum(context: Context): void { // const e = new EnumVisitor(this.writer); // context.enum!.accept(context, e); // const s = new EnumVisitorToString(this.writer); // context.enum!.accept(context, s); // } - visitType(context: Context): void { + public override visitType(context: Context): void { const clazz = new ClassVisitor(this.writer); context.type!.accept(context, clazz); } diff --git a/src/typescript/wrapper_visitor.ts b/src/typescript/wrapper_visitor.ts index cbda5d0..728403b 100644 --- a/src/typescript/wrapper_visitor.ts +++ b/src/typescript/wrapper_visitor.ts @@ -14,12 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { BaseVisitor, Context } from "../deps/core/model.ts"; +import { BaseVisitor, type Context } from "@apexlang/core/model"; import { expandType } from "./helpers.ts"; import { camelCase, capitalize, isVoid, noCode } from "../utils/mod.ts"; export class WrapperVisitor extends BaseVisitor { - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { super.triggerInterfaceBefore(context); const { interface: iface } = context; this.write( @@ -27,7 +27,7 @@ export class WrapperVisitor extends BaseVisitor { ); } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { const { interface: iface, operation } = context; if (noCode(operation)) { return; @@ -73,14 +73,14 @@ export class WrapperVisitor extends BaseVisitor { super.triggerOperation(context); } - visitInterfaceAfter(context: Context): void { + public override visitInterfaceAfter(context: Context): void { this.write(`}\n\n`); super.triggerInterfaceAfter(context); } } export class WrapperStatefulVisitor extends BaseVisitor { - visitInterfaceBefore(context: Context): void { + public override visitInterfaceBefore(context: Context): void { super.triggerInterfaceBefore(context); const { namespace, interface: iface } = context; const ns = namespace.name + "." + iface.name; @@ -94,7 +94,7 @@ export class WrapperStatefulVisitor extends BaseVisitor { ); } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { const { interface: iface, operation } = context; if (noCode(operation)) { return; @@ -147,7 +147,7 @@ export class WrapperStatefulVisitor extends BaseVisitor { super.triggerOperation(context); } - visitInterfaceAfter(context: Context): void { + public override visitInterfaceAfter(context: Context): void { this.write(`}\n\n`); super.triggerInterfaceAfter(context); } diff --git a/src/utils/exposed_types.ts b/src/utils/exposed_types.ts index 995ad9f..6176c49 100644 --- a/src/utils/exposed_types.ts +++ b/src/utils/exposed_types.ts @@ -15,18 +15,18 @@ limitations under the License. */ import { - Alias, - AnyType, + type Alias, + type AnyType, BaseVisitor, - Context, + type Context, Kind, - List, - Map, - Named, - Optional, - Type, - Union, -} from "../deps/core/model.ts"; + type List, + type Map, + type Named, + type Optional, + type Type, + type Union, +} from "@apexlang/core/model"; import { isNamed, isService } from "./utilities.ts"; export class ExposedTypesVisitor extends BaseVisitor { @@ -77,7 +77,7 @@ export class ExposedTypesVisitor extends BaseVisitor { } } - visitOperation(context: Context): void { + public override visitOperation(context: Context): void { if (!isService(context)) { return; } @@ -85,7 +85,7 @@ export class ExposedTypesVisitor extends BaseVisitor { this.checkType(operation.type); } - visitParameter(context: Context): void { + public override visitParameter(context: Context): void { if (!isService(context)) { return; } diff --git a/src/utils/uses_visitor.ts b/src/utils/uses_visitor.ts index 16e082e..31cb3f1 100644 --- a/src/utils/uses_visitor.ts +++ b/src/utils/uses_visitor.ts @@ -15,11 +15,11 @@ limitations under the License. */ import { - Annotation, + type Annotation, BaseVisitor, - Context, - Visitor, -} from "../deps/core/model.ts"; + type Context, + type Visitor, +} from "@apexlang/core/model"; import { isProvider, isService } from "./utilities.ts"; export interface UsesVisitor extends Visitor { @@ -31,7 +31,7 @@ export class InterfaceUsesVisitor extends BaseVisitor implements UsesVisitor { services: Map = new Map(); dependencies: string[] = []; - visitInterface(context: Context): void { + public override visitInterface(context: Context): void { const { interface: iface } = context; if (isService(context)) { let dependencies: string[] = []; diff --git a/src/utils/utilities.ts b/src/utils/utilities.ts index e3868b7..df4ec05 100644 --- a/src/utils/utilities.ts +++ b/src/utils/utilities.ts @@ -15,25 +15,25 @@ limitations under the License. */ import { - Alias, - Annotated, - Annotation, - AnyType, - Context, - Enum, - Interface, + type Alias, + type Annotated, + type Annotation, + type AnyType, + type Context, + type Enum, + type Interface, Kind, - List, - Map, - Named, - Operation, - Optional, - Primitive, - Stream, + type List, + type Map, + type Named, + type Operation, + type Optional, + type Primitive, + type Stream, Type, - TypeResolver, - Union, -} from "../deps/core/model.ts"; + type TypeResolver, + type Union, +} from "@apexlang/core/model"; import { FieldDefinition, ListType, @@ -43,9 +43,9 @@ import { Optional as OptionalAST, Stream as StreamType, StringValue, - Type as ASTType, + type Type as ASTType, TypeDefinition, -} from "../deps/core/ast.ts"; +} from "@apexlang/core/ast"; export function isOneOfType(context: Context, types: string[]): boolean { if (context.interface) { @@ -255,7 +255,7 @@ export function visitNamed(t: AnyType, callback: (name: string) => void): void { } } -export const primitives = new Set([ +export const primitives: Set = new Set([ "bool", "i8", "i16", @@ -350,24 +350,24 @@ export function formatComment( // https://github.com/blakeembrey/change-case // Pasted here to avoid an NPM dependency for the CLI. -export function camelCaseTransform(input: string, index: number) { +export function camelCaseTransform(input: string, index: number): string { if (index === 0) return input.toLowerCase(); return pascalCaseTransform(input, index); } -export function camelCaseTransformMerge(input: string, index: number) { +export function camelCaseTransformMerge(input: string, index: number): string { if (index === 0) return input.toLowerCase(); return pascalCaseTransformMerge(input); } -export function camelCase(input: string, options: Options = {}) { +export function camelCase(input: string, options: Options = {}): string { return pascalCase(input, { transform: camelCaseTransform, ...options, }); } -export function pascalCaseTransform(input: string, index: number) { +export function pascalCaseTransform(input: string, index: number): string { const firstChar = input.charAt(0); const lowerChars = input.substr(1).toLowerCase(); if (index > 0 && firstChar >= "0" && firstChar <= "9") { @@ -376,11 +376,11 @@ export function pascalCaseTransform(input: string, index: number) { return `${firstChar.toUpperCase()}${lowerChars}`; } -export function pascalCaseTransformMerge(input: string) { +export function pascalCaseTransformMerge(input: string): string { return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase(); } -export function pascalCase(input: string, options: Options = {}) { +export function pascalCase(input: string, options: Options = {}): string { return noCase(input, { delimiter: "", transform: pascalCaseTransform, @@ -388,14 +388,14 @@ export function pascalCase(input: string, options: Options = {}) { }); } -export function snakeCase(input: string, options: Options = {}) { +export function snakeCase(input: string, options: Options = {}): string { return dotCase(input, { delimiter: "_", ...options, }); } -export function dotCase(input: string, options: Options = {}) { +export function dotCase(input: string, options: Options = {}): string { return noCase(input, { delimiter: ".", ...options, @@ -415,7 +415,7 @@ export interface Options { transform?: (part: string, index: number, parts: string[]) => string; } -export function noCase(input: string, options: Options = {}) { +export function noCase(input: string, options: Options = {}): string { const { splitRegexp = DEFAULT_SPLIT_REGEXP, stripRegexp = DEFAULT_STRIP_REGEXP, @@ -442,7 +442,7 @@ export function noCase(input: string, options: Options = {}) { /** * Replace `re` in the input string with the replacement value. */ -function replace(input: string, re: RegExp | RegExp[], value: string) { +function replace(input: string, re: RegExp | RegExp[], value: string): string { if (re instanceof RegExp) return input.replace(re, value); return re.reduce((input, re) => input.replace(re, value), input); } @@ -491,7 +491,7 @@ const SUPPORTED_LOCALE: Record = { /** * Localized lower case. */ -export function localeLowerCase(str: string, locale: string) { +export function localeLowerCase(str: string, locale: string): string { const lang = SUPPORTED_LOCALE[locale.toLowerCase()]; if (lang) return lowerCase(str.replace(lang.regexp, (m) => lang.map[m])); return lowerCase(str); @@ -500,7 +500,7 @@ export function localeLowerCase(str: string, locale: string) { /** * Lower case as a function. */ -export function lowerCase(str: string) { +export function lowerCase(str: string): string { return str.toLowerCase(); } diff --git a/templates/basic/apex.yaml.tmpl b/templates/basic/apex.yaml.tmpl index 8ce06f8..cc6d1d9 100644 --- a/templates/basic/apex.yaml.tmpl +++ b/templates/basic/apex.yaml.tmpl @@ -1,5 +1,5 @@ spec: spec.apexlang generates: openapi.yaml: - module: 'https://deno.land/x/apex_codegen@v0.1.7/openapiv3/mod.ts' + module: 'jsr:@apexlang/codegen/openapiv3' visitorClass: OpenAPIV3Visitor diff --git a/templates/generator/src/default-visitor.ts b/templates/generator/src/default-visitor.ts index 6358dff..bd187ef 100644 --- a/templates/generator/src/default-visitor.ts +++ b/templates/generator/src/default-visitor.ts @@ -1,7 +1,4 @@ -import { - BaseVisitor, - Context, -} from "https://deno.land/x/apex_core@v0.1.5/model/mod.ts"; +import { BaseVisitor, type Context } from "@apexlang/core/model"; import { TypeVisitor } from "./visitors/type-visitor.ts"; import { InterfaceVisitor } from "./visitors/interface-visitor.ts"; import { EnumVisitor } from "./visitors/enum-visitor.ts"; @@ -19,7 +16,7 @@ export class DefaultVisitor extends BaseVisitor { * *************************************************************************/ // .visitContextBefore() runs at the start of execution. - visitContextBefore(context: Context): void { + public override visitContextBefore(context: Context): void { // Add a generated header to your source by // uncommenting the following lines: /* @@ -49,7 +46,7 @@ export class DefaultVisitor extends BaseVisitor { } } - visitContextAfter(context: Context): void { + public override visitContextAfter(context: Context): void { /* If a "footer" option exists in the configuration, add it to the generated output. @@ -63,37 +60,37 @@ export class DefaultVisitor extends BaseVisitor { } } - visitNamespace(context: Context): void { + public override visitNamespace(context: Context): void { const { namespace } = context; // The name of the namespace from the Apex schema. - const name = namespace.name; + const _name = namespace.name; // Use `.write()` to write to the destination buffer. this.write(``); } - visitType(context: Context): void { + public override visitType(context: Context): void { this.write(new TypeVisitor(context).buffer()); } - visitInterface(context: Context): void { + public override visitInterface(context: Context): void { this.write(new InterfaceVisitor(context).buffer()); } - visitEnum(context: Context): void { + public override visitEnum(context: Context): void { this.write(new EnumVisitor(context).buffer()); } - visitUnion(context: Context): void { + public override visitUnion(context: Context): void { this.write(new UnionVisitor(context).buffer()); } - visitFunction(context: Context): void { + public override visitFunction(context: Context): void { this.write(convertOperation(context.operation, true, context.config)); } - visitAlias(context: Context): void { + public override visitAlias(context: Context): void { this.write(new AliasVisitor(context).buffer()); } } diff --git a/templates/generator/src/utils/conversions.ts b/templates/generator/src/utils/conversions.ts index 4b30d06..9bc17ae 100644 --- a/templates/generator/src/utils/conversions.ts +++ b/templates/generator/src/utils/conversions.ts @@ -1,9 +1,5 @@ -import { - ObjectMap, - Operation, - Parameter, -} from "https://deno.land/x/apex_core@v0.1.5/model/mod.ts"; -import * as utils from "https://deno.land/x/apex_codegen@v0.1.7/utils/mod.ts"; +import type { ObjectMap, Operation, Parameter } from "@apexlang/core/model"; +import * as utils from "@apexlang/codegen/utils"; import { convertType } from "./types.ts"; /** @@ -38,16 +34,16 @@ export function convertOperation( config: ObjectMap, ): string { // The name of the Operation. - const name = op.name; + const _name = op.name; // A comment generated from the description. - const comment = convertDescription(op.description); + const _comment = convertDescription(op.description); // The return type of the operation, converted via `convertType()` - const type = convertType(op.type, config); + const _type = convertType(op.type, config); // Iterate over the Operation's Parameters and generate new output. - const params = op.parameters.map((arg) => convertParameter(arg, config)); + const _params = op.parameters.map((arg) => convertParameter(arg, config)); if (global) { // Generate output for global functions here. @@ -68,10 +64,10 @@ export function convertOperation( */ export function convertParameter(param: Parameter, config: ObjectMap): string { // The name of the Parameter - const name = param.name; + const _name = param.name; // The type of the Parameter, converted via `convertType()` - const type = convertType(param.type, config); + const _type = convertType(param.type, config); // Combine the above to create and return new output here. return ``; diff --git a/templates/generator/src/utils/types.ts b/templates/generator/src/utils/types.ts index a04d532..bb6def5 100644 --- a/templates/generator/src/utils/types.ts +++ b/templates/generator/src/utils/types.ts @@ -1,14 +1,14 @@ import { - AnyType, + type AnyType, Kind, - List, - Map, - Named, - ObjectMap, - Optional, - Primitive, + type List, + type Map, + type Named, + type ObjectMap, + type Optional, + type Primitive, PrimitiveName, -} from "https://deno.land/x/apex_core@v0.1.5/model/mod.ts"; +} from "@apexlang/core/model"; /** * Convert an Apex type to a type suitable for the destination format. @@ -36,7 +36,7 @@ export function convertType(typ: AnyType, config: ObjectMap): string { const t = typ as List; // The list element's type - const itemType = convertType(t.type, config); + const _itemType = convertType(t.type, config); return ``; } @@ -53,9 +53,9 @@ export function convertType(typ: AnyType, config: ObjectMap): string { const t = typ as Map; // The type of the keys in the Map. - const keyType = convertType(t.keyType, config); + const _keyType = convertType(t.keyType, config); // The type of the values in the Map. - const valueType = convertType(t.valueType, config); + const _valueType = convertType(t.valueType, config); return ``; } @@ -72,7 +72,7 @@ export function convertType(typ: AnyType, config: ObjectMap): string { const t = typ as Optional; // The inner type of the Optional node. - const innerType = convertType(t.type, config); + const _innerType = convertType(t.type, config); return ``; } @@ -130,7 +130,7 @@ export function convertType(typ: AnyType, config: ObjectMap): string { * * @throws Throws if there is a type unaccounted for. */ -function convertPrimitive(typ: Primitive, config: ObjectMap): string { +function convertPrimitive(typ: Primitive, _config: ObjectMap): string { switch (typ.name) { case PrimitiveName.Bool: return "bool"; diff --git a/templates/generator/src/visitors/alias-visitor.ts b/templates/generator/src/visitors/alias-visitor.ts index cc81800..cf5e879 100644 --- a/templates/generator/src/visitors/alias-visitor.ts +++ b/templates/generator/src/visitors/alias-visitor.ts @@ -1,7 +1,4 @@ -import { - Alias, - Context, -} from "https://deno.land/x/apex_core@v0.1.5/model/mod.ts"; +import type { Alias, Context } from "@apexlang/core/model"; import { convertDescription } from "../utils/conversions.ts"; import { convertType } from "../utils/types.ts"; @@ -23,14 +20,14 @@ export class AliasVisitor extends SourceGenerator { super(context.alias, context); } - buffer(): string { + override buffer(): string { // The name of the Alias from the Apex schema. - const name = this.node.name; + const _name = this.node.name; // A comment generated from the description. - const comment = convertDescription(this.node.description); + const _comment = convertDescription(this.node.description); - const type = convertType(this.node.type, this.context.config); + const _type = convertType(this.node.type, this.context.config); // Combine the above to create and return new output here. return ``; diff --git a/templates/generator/src/visitors/base.ts b/templates/generator/src/visitors/base.ts index 100400c..0e5fdc4 100644 --- a/templates/generator/src/visitors/base.ts +++ b/templates/generator/src/visitors/base.ts @@ -1,14 +1,14 @@ import { - Alias, + type Alias, BaseVisitor, - Context, - Enum, - Interface, - ObjectMap, - Type, - Union, + type Context, + type Enum, + type Interface, + type ObjectMap, + type Type, + type Union, Writer, -} from "https://deno.land/x/apex_core@v0.1.5/model/mod.ts"; +} from "@apexlang/core/model"; export type VisitorTypes = Alias | Type | Union | Enum | Interface; diff --git a/templates/generator/src/visitors/enum-visitor.ts b/templates/generator/src/visitors/enum-visitor.ts index 0a8bcd2..c9955ab 100644 --- a/templates/generator/src/visitors/enum-visitor.ts +++ b/templates/generator/src/visitors/enum-visitor.ts @@ -1,7 +1,4 @@ -import { - Context, - Enum, -} from "https://deno.land/x/apex_core@v0.1.5/model/mod.ts"; +import type { Context, Enum } from "@apexlang/core/model"; import { convertDescription } from "../utils/conversions.ts"; import { SourceGenerator } from "./base.ts"; @@ -25,35 +22,35 @@ export class EnumVisitor extends SourceGenerator { super(context.enum, context); } - buffer(): string { + override buffer(): string { // The name of the Enum from the Apex schema. - const name = this.node.name; + const _name = this.node.name; // Get the buffered output. Your visitor operations write // to this buffer when they call `.write()`. - const innerSource = this.writer.string(); + const _innerSource = this.writer.string(); // A comment generated from the description. - const comment = convertDescription(this.node.description); + const _comment = convertDescription(this.node.description); // Combine the above to create and return new output here. return ``; } - visitEnumValue(context: Context): void { + override visitEnumValue(context: Context): void { const { enumValue } = context; // The name of the EnumValue variant. - const name = enumValue.name; + const _name = enumValue.name; // The display value for the Enum (if defined). - const display = enumValue.display; + const _display = enumValue.display; // The index of the Enum (if defined). - const index = enumValue.index; + const _index = enumValue.index; // A comment generated from the description. - const comment = convertDescription(this.node.description); + const _comment = convertDescription(this.node.description); // Append to the buffer in `this.writer`. Get the buffer's // state by calling `this.writer.string()`. diff --git a/templates/generator/src/visitors/interface-visitor.ts b/templates/generator/src/visitors/interface-visitor.ts index 746bc0d..8ea006d 100644 --- a/templates/generator/src/visitors/interface-visitor.ts +++ b/templates/generator/src/visitors/interface-visitor.ts @@ -1,7 +1,4 @@ -import { - Context, - Interface, -} from "https://deno.land/x/apex_core@v0.1.5/model/mod.ts"; +import type { Context, Interface } from "@apexlang/core/model"; import { convertDescription, convertOperation } from "../utils/conversions.ts"; import { SourceGenerator } from "./base.ts"; @@ -23,26 +20,26 @@ export class InterfaceVisitor extends SourceGenerator { super(context.interface, context); } - buffer(): string { + override buffer(): string { // The name of the Interface from the Apex schema. - const name = this.node.name; + const _name = this.node.name; // Get the buffered output. Your visitor operations write // to this buffer when they call `.write()`. - const innerSource = this.writer.string(); + const _innerSource = this.writer.string(); // A comment generated from the description. - const comment = convertDescription(this.node.description); + const _comment = convertDescription(this.node.description); // Combine the above to create and return new output here. return ``; } - visitOperation(context: Context): void { + override visitOperation(context: Context): void { const { operation } = context; // Generate new output from `convertOperation()` below. - const converted = convertOperation(operation, false, this.config); + const _converted = convertOperation(operation, false, this.config); // Append to the buffer in `this.writer`. Get the buffer's // state by calling `this.writer.string()`. diff --git a/templates/generator/src/visitors/type-visitor.ts b/templates/generator/src/visitors/type-visitor.ts index d12069b..4013ba9 100644 --- a/templates/generator/src/visitors/type-visitor.ts +++ b/templates/generator/src/visitors/type-visitor.ts @@ -1,7 +1,4 @@ -import { - Context, - Type, -} from "https://deno.land/x/apex_core@v0.1.5/model/mod.ts"; +import type { Context, Type } from "@apexlang/core/model"; import { convertDescription } from "../utils/conversions.ts"; import { convertType } from "../utils/types.ts"; import { SourceGenerator } from "./base.ts"; @@ -24,32 +21,32 @@ export class TypeVisitor extends SourceGenerator { super(context.type, context); } - buffer(): string { + override buffer(): string { // This is the Type name from the input Apex schema. - const name = this.node.name; + const _name = this.node.name; // This is a comment generated from the description in Apex. - const comment = convertDescription(this.node.description); + const _comment = convertDescription(this.node.description); // Get the buffered output. Your visitor operations write // to this buffer when they call `.write()`. - const innerSource = this.writer.string(); + const _innerSource = this.writer.string(); // Combine the above to create and return new source. return ``; } - visitTypeField(context: Context): void { + override visitTypeField(context: Context): void { const { field } = context; // The name of the TypeField from the Apex schema. - const name = field.name; + const _name = field.name; // The type of the field, converted from Apex type with `convertType()`. - const convertedType = convertType(field.type, context.config); + const _convertedType = convertType(field.type, context.config); // A comment generated from the description. - const comment = convertDescription(field.description); + const _comment = convertDescription(field.description); // Append to the buffer in `this.writer`. Get the buffer's // state by calling `this.writer.string()`. diff --git a/templates/generator/src/visitors/union-visitor.ts b/templates/generator/src/visitors/union-visitor.ts index eb94fea..c8e7945 100644 --- a/templates/generator/src/visitors/union-visitor.ts +++ b/templates/generator/src/visitors/union-visitor.ts @@ -1,7 +1,4 @@ -import { - Context, - Union, -} from "https://deno.land/x/apex_core@v0.1.5/model/mod.ts"; +import type { Context, Union } from "@apexlang/core/model"; import { convertDescription } from "../utils/conversions.ts"; import { convertType } from "../utils/types.ts"; @@ -22,18 +19,18 @@ export class UnionVisitor extends SourceGenerator { super(context.union, context); } - buffer(): string { + override buffer(): string { // Iterate over each type in the Union and convert it // with `convertType()` - const types = this.node.types.map((t) => { + const _types = this.node.members.map((t) => { return convertType(t, this.config); }); // A comment generated from the description. - const comment = convertDescription(this.node.description); + const _comment = convertDescription(this.node.description); // The name of the Union as defined in the Apex schema. - const name = this.node.name; + const _name = this.node.name; // Combine the above to create and return new output. return ``; diff --git a/templates/generator/test/default.test.ts b/templates/generator/test/default.test.ts index 31f5ce4..09aaf07 100644 --- a/templates/generator/test/default.test.ts +++ b/templates/generator/test/default.test.ts @@ -1,7 +1,7 @@ import { parse } from "./parse.ts"; import { DefaultVisitor } from "../src/default-visitor.ts"; -import { Writer } from "https://deno.land/x/apex_core@v0.1.5/model/mod.ts"; -import { assert } from "https://deno.land/std@0.167.0/testing/asserts.ts"; +import { Writer } from "@apexlang/core/model"; +import { assert } from "@std/assert"; Deno.test("should generate apex from apex", () => { // Define test apex we can parse. diff --git a/templates/generator/test/parse.ts b/templates/generator/test/parse.ts index 1841bac..1f85107 100644 --- a/templates/generator/test/parse.ts +++ b/templates/generator/test/parse.ts @@ -1,5 +1,5 @@ -import { parse as parseApex } from "https://deno.land/x/apex_core@v0.1.5/mod.ts"; -import { Context } from "https://deno.land/x/apex_core@v0.1.5/model/mod.ts"; +import { parse as parseApex } from "@apexlang/core"; +import { Context } from "@apexlang/core/model"; export function parse(src: string): Context { const doc = parseApex(src); diff --git a/templates/go/apex.yaml.tmpl b/templates/go/apex.yaml.tmpl index 263de63..9aa5e4d 100644 --- a/templates/go/apex.yaml.tmpl +++ b/templates/go/apex.yaml.tmpl @@ -7,10 +7,10 @@ config: interface: "logr.Logger" generates: openapi.yaml: - module: 'https://deno.land/x/apex_codegen@v0.1.7/openapiv3/mod.ts' + module: 'jsr:@apexlang/codegen/openapiv3' visitorClass: OpenAPIV3Visitor proto/service.proto: - module: 'https://deno.land/x/apex_codegen@v0.1.7/proto/mod.ts' + module: 'jsr:@apexlang/codegen/proto' visitorClass: ProtoVisitor config: options: @@ -24,31 +24,31 @@ generates: --go-grpc_opt=paths=source_relative proto/service.proto pkg/{{.package}}/interfaces.go: - module: 'https://deno.land/x/apex_codegen@v0.1.7/go/mod.ts' + module: 'jsr:@apexlang/codegen/go' visitorClass: InterfacesVisitor pkg/{{.package}}/fiber.go: - module: 'https://deno.land/x/apex_codegen@v0.1.7/go/mod.ts' + module: 'jsr:@apexlang/codegen/go' visitorClass: FiberVisitor pkg/{{.package}}/grpc.go: - module: 'https://deno.land/x/apex_codegen@v0.1.7/go/mod.ts' + module: 'jsr:@apexlang/codegen/go' visitorClass: GRPCVisitor config: protoPackage: {{.module}}/proto pkg/{{.package}}/services.go: ifNotExists: true - module: 'https://deno.land/x/apex_codegen@v0.1.7/go/mod.ts' + module: 'jsr:@apexlang/codegen/go' visitorClass: ScaffoldVisitor config: types: - service pkg/{{.package}}/providers.go: ifNotExists: true - module: 'https://deno.land/x/apex_codegen@v0.1.7/go/mod.ts' + module: 'jsr:@apexlang/codegen/go' visitorClass: ScaffoldVisitor config: types: - provider cmd/main.go: ifNotExists: false # Change to true to control dependency injection - module: 'https://deno.land/x/apex_codegen@v0.1.7/go/mod.ts' + module: 'jsr:@apexlang/codegen/go' visitorClass: MainVisitor diff --git a/templates/nodejs/apex.yaml b/templates/nodejs/apex.yaml index 50bce77..c5651d5 100644 --- a/templates/nodejs/apex.yaml +++ b/templates/nodejs/apex.yaml @@ -1,3 +1,3 @@ spec: apex.axdl plugins: - - 'https://raw.githubusercontent.com/apexlang/codegen/main/src/typescript/plugin.ts' + - 'jsr:@apexlang/codegen/typescript/plugin.ts' diff --git a/templates/python/apex.yaml b/templates/python/apex.yaml index 5a303b0..e67ea0a 100644 --- a/templates/python/apex.yaml +++ b/templates/python/apex.yaml @@ -1,9 +1,9 @@ spec: spec.apexlang generates: interfaces.py: - module: "https://deno.land/x/apex_codegen@v0.1.7/python/mod.ts" + module: "jsr:@apexlang/codegen/python" visitorClass: InterfacesVisitor service.py: ifNotExists: true - module: "https://deno.land/x/apex_codegen@v0.1.7/python/mod.ts" + module: "jsr:@apexlang/codegen/python" visitorClass: ScaffoldVisitor diff --git a/test/parse.ts b/test/parse.ts index eee6f42..14ac263 100644 --- a/test/parse.ts +++ b/test/parse.ts @@ -1,5 +1,5 @@ -import { parse as parseApex } from "https://deno.land/x/apex_core@v0.1.5/mod.ts"; -import { Context, Namespace, Type } from "../src/deps/core/model.ts"; +import { parse as parseApex } from "@apexlang/core"; +import { Context, type Namespace, type Type } from "@apexlang/core/model"; export function parse(src: string): Namespace { const doc = parseApex(src); diff --git a/test/utils/utilities.test.ts b/test/utils/utilities.test.ts index c5ccb7e..fbaf657 100644 --- a/test/utils/utilities.test.ts +++ b/test/utils/utilities.test.ts @@ -1,4 +1,4 @@ -import { assert } from "https://deno.land/std@0.213.0/assert/assert.ts"; +import { assert } from "@std/assert"; import { isRecursiveType } from "../../src/utils/utilities.ts"; import { getTypes, parse } from "../parse.ts"; @@ -32,6 +32,6 @@ Deno.test("should not identify non-recursive types", () => { } `; const model = parse(apex); - const [parent, child] = getTypes(model, ["Parent"]); + const [parent, _child] = getTypes(model, ["Parent"]); assert(!isRecursiveType(parent)); });