diff --git a/.dockerignore b/.dockerignore index 8182104..59486ac 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,4 @@ target Dockerfile -.dockerignore \ No newline at end of file +.dockerignore +.gitkeep diff --git a/.github/workflows/deno.yml b/.github/workflows/deno.yml index ac58c6c..10ab7e7 100644 --- a/.github/workflows/deno.yml +++ b/.github/workflows/deno.yml @@ -27,7 +27,7 @@ jobs: - name: Setup Deno # uses: denoland/setup-deno@v1 - uses: denoland/setup-deno@61fe2df320078202e33d7d5ad347e7dcfa0e8f31 # v1.1.2 + uses: denoland/setup-deno@0df5d9c641efdff149993c321fc27c11c5df8623 # v1.1.3 with: deno-version: v1.x diff --git a/CHANGELOG.md b/CHANGELOG.md index a827f09..49f5a88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ This changelog documents the changes between release versions. ## main -Changes to be included in the next upcoming releaase. +Changes to be included in the next upcoming release. ## v0.19 diff --git a/Dockerfile b/Dockerfile index c441aed..518fa15 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,15 @@ -FROM denoland/deno:alpine-1.37.1 +FROM denoland/deno:alpine-1.38.3 COPY ./src /app -COPY ./functions /functions -WORKDIR /functions +RUN deno cache /app/mod.ts -RUN ls /app +COPY ./functions /functions/src # Pre-cache inference results and dependencies -RUN EARLY_ENTRYPOINT_EXIT=true sh /app/entrypoint.sh +RUN PRECACHE_ONLY=true /app/entrypoint.sh -ENTRYPOINT [ "sh", "/app/entrypoint.sh" ] +EXPOSE 8080 + +ENTRYPOINT [ "/app/entrypoint.sh" ] CMD [ ] diff --git a/README.md b/README.md index 1d82a2d..ba9cbb4 100644 --- a/README.md +++ b/README.md @@ -2,21 +2,21 @@ ![image](https://github.com/hasura/ndc-typescript-deno/assets/92299/9f139964-d0ed-4c92-b01f-9fda255717d4) -The Typescript (Deno) Connector allows a running connector to be inferred from a Typescript file (optionally with dependencies). +The TypeScript (Deno) Connector allows a running connector to be inferred from a TypeScript file (optionally with dependencies). ![image](https://github.com/hasura/ndc-typescript-deno/assets/92299/fb7f4afd-0302-432b-b7ce-3cc7d1f3546b) Useful Links: -* [Typescript Deno Connector on the NDC Hub](https://hasura.io/connectors/typescript-deno) -* [Typescript Deno Connector on deno.com](https://deno.land/x/hasura_typescript_connector) +* [TypeScript Deno Connector on the NDC Hub](https://hasura.io/connectors/typescript-deno) +* [TypeScript Deno Connector on deno.com](https://deno.land/x/hasura_typescript_connector) * [Hasura V3 Documentation](https://hasura.io/docs/3.0) * [Hasura CLI](https://github.com/hasura/v3-cli#hasura-v3-cli) * [CLI Connector Plugin](https://hasura.io/docs/latest/hasura-cli/connector-plugin/) * [Hasura VSCode Extension](https://marketplace.visualstudio.com/items?itemName=HasuraHQ.hasura) * [Deno](https://deno.com) * [Native Data Connector Specification](https://hasura.github.io/ndc-spec/) -* [Typescript NDC SDK](https://github.com/hasura/ndc-sdk-typescript/) +* [TypeScript NDC SDK](https://github.com/hasura/ndc-sdk-typescript/) * [DDN Limited Alpha Access Form](https://forms.gle/zHTrVEbsQoBK8ecr5) @@ -24,7 +24,7 @@ Useful Links: The connector runs in the following manner: -* Typescript sources are assembled (with `index.ts` acting as your interface definition) +* TypeScript sources are assembled (with `index.ts` acting as your interface definition) * Dependencies are fetched * Inference is performed and made available via the `/schema` endpoint * Functions are served via the connector protocol @@ -54,7 +54,7 @@ Once the Hasura DDN is generally available this will no longer be required. Your functions should be organised into a directory with one file acting as the entrypoint.
- An example Typescript entrypoint: + An example TypeScript entrypoint: ```typescript @@ -123,7 +123,6 @@ Limitations: * All numbers are exported as `Float`s * Unrecognised types will become opaque scalars, for example: union types. * Optional object fields are not currently supported -* Complex input types are supported by the connector, but are not supported in "commands" in Hasura3 projects * Functions can be executed via both the `/query` and `/mutation` endpoints * Conflicting type names in dependencies will be namespaced with their relative path * Generic type parameters will be treated as scalars when referenced @@ -145,26 +144,15 @@ In order to develop your functions locally the following is the recommended prac { "functions": "./functions/index.ts", "vendor": "./vendor", - "preVendor": true, "schemaMode": "INFER" } ``` -* (Optionally) If you want your development vendor and inference resources to be used to speed up deployment, add the following to your `./config.json`: - ```json - { - "functions": "./functions/index.ts", - "vendor": "./functions/vendor", - "preVendor": true, - "schemaLocation": "./functions/schema.json", - "schemaMode": "INFER" - } - ``` - * Make sure to .gitignore your computed `vendor` and `schema.json` files. + * Make sure to .gitignore your computed `vendor` files. * Start the connector ```sh -deno run -A --watch --check https://deno.land/x/hasura_typescript_connector/mod.ts serve --configuration ./config.json +deno run -A --watch=./functions --check https://deno.land/x/hasura_typescript_connector/mod.ts serve --configuration ./config.json ``` -* (Optionally) Add a test-suite to your functions. See [Deno Testing Basics](https://docs.deno.com/runtime/manual/basics/testing). +* (Optionally) Add a test-suite for your functions. See [Deno Testing Basics](https://docs.deno.com/runtime/manual/basics/testing). ## Config Format @@ -172,25 +160,25 @@ deno run -A --watch --check https://deno.land/x/hasura_typescript_connector/mod. The configuration object has the following properties: ``` - functions (string): Location of your functions entrypoint (default: ./functions/index.ts) + functions (string): Location of your functions entrypoint vendor (string): Location of dependencies vendor folder (optional) - preVendor (boolean): Perform vendoring prior to inference in a sub-process (default: false) - schemaMode (string): INFER the schema from your functions, or READ it from a file. - schemaLocation (string): Location of your schema file. schemaMode=READ reads the file, schemaMode=INFER writes the file (optional) + preVendor (boolean): Perform vendoring prior to inference in a sub-process (default: true) + schemaMode (string): INFER the schema from your functions, or READ it from a file. (default: INFER) + schemaLocation (string): Location of your schema file. schemaMode=READ reads the file (required), schemaMode=INFER writes the file (optional) ``` NOTE: When deploying the connector with the `connector create` command your config is currently replaced with: -``` +```json { - "functions": "/functions/index.ts", + "functions": "/functions/src/index.ts", "vendor": "/functions/vendor", "schemaMode": "READ", "schemaLocation": "/functions/schema.json" } ``` -This means that your functions volume will have to be mounted to `/functions`. +This means that your functions volume will have to be mounted to `/functions/src`. ## Deployment for Hasura Users @@ -203,7 +191,7 @@ You will need: Create the connector: -``` +```bash hasura3 connector create my-cool-connector:v1 \ --github-repo-url https://github.com/hasura/ndc-typescript-deno/tree/main \ --config-file <(echo '{}') \ @@ -220,7 +208,7 @@ Monitor the deployment status by name - This will indicate in-progress, complete List all your connectors with their deployed URLs: > hasura3 connector list - + View logs from your running connector: > hasura3 connector logs my-cool-connector:v1 @@ -343,7 +331,7 @@ In order to perform local development on this codebase: * Check out the repository: `git clone https://github.com/hasura/ndc-typescript-deno.git` * This assumes that you will be testing against function in `./functions` -* Serve your functions with `deno run -A --watch --check ./src/mod.ts serve --configuration <(echo '{"functions": "./functions/index.ts", "vendor": "./functions/vendor", "schemaMode": "INFER"}')` +* Serve your functions with `deno run -A --watch=./functions --check ./src/mod.ts serve --configuration <(echo '{"functions": "./functions/index.ts", "vendor": "./vendor", "schemaMode": "INFER"}')` * The connector should now be running on localhost:8100 and respond to any changes to the your functions and the connector source * Use the `hasura3` tunnel commands to reference this connector from a Hasura Cloud project diff --git a/functions/.gitkeep b/functions/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/functions/index.ts b/functions/index.ts deleted file mode 100644 index ed7bd52..0000000 --- a/functions/index.ts +++ /dev/null @@ -1,6 +0,0 @@ - -// Placeholder index.ts to allow CI to run against functions volume - -export function hello(): string { - return 'hello world'; -} \ No newline at end of file diff --git a/src/README.md b/src/README.md index 855fd25..0479013 100644 --- a/src/README.md +++ b/src/README.md @@ -1,8 +1,8 @@ -# Hasura NDC Typescript (Deno) Connector +# Hasura NDC TypeScript (Deno) Connector ![image](https://github.com/hasura/ndc-typescript-deno/assets/92299/9f139964-d0ed-4c92-b01f-9fda255717d4) -The Typescript (Deno) Connector allows a running connector to be inferred from a Typescript file (optionally with dependencies). +The TypeScript (Deno) Connector allows a running connector to be inferred from a TypeScript file (optionally with dependencies). ![image](https://github.com/hasura/ndc-typescript-deno/assets/92299/fb7f4afd-0302-432b-b7ce-3cc7d1f3546b) @@ -19,14 +19,13 @@ Once your project is set up, run locally with: { "functions": "./functions/index.ts", "vendor": "./vendor", - "preVendor": true, "schemaMode": "INFER" } -> deno run -A --watch --check https://deno.land/x/hasura_typescript_connector/mod.ts serve --configuration ./config.json +> deno run -A --watch=./functions --check https://deno.land/x/hasura_typescript_connector/mod.ts serve --configuration ./config.json ``` -## Typescript Functions Format +## TypeScript Functions Format Your functions should be organised into a directory with one file acting as the entrypoint. diff --git a/src/connector.ts b/src/connector.ts index 728940f..cab17cb 100644 --- a/src/connector.ts +++ b/src/connector.ts @@ -1,21 +1,20 @@ - -import { FunctionPositions, ProgramInfo, programInfo, Struct } from "./infer.ts"; -import { resolve } from "https://deno.land/std@0.203.0/path/mod.ts"; -import { JSONSchemaObject } from "npm:@json-schema-tools/meta-schema"; - -import sdk from 'npm:@hasura/ndc-sdk-typescript@1.2.4'; - /** * Implementation of the Connector interface for Deno connector. * Using https://github.com/hasura/ndc-qdrant/blob/main/src/index.ts as an example. */ +import { FunctionPositions, ProgramInfo, programInfo, Struct } from "./infer.ts"; +import { resolve } from "https://deno.land/std@0.208.0/path/mod.ts"; +import { JSONSchemaObject } from "npm:@json-schema-tools/meta-schema"; + +import * as sdk from 'npm:@hasura/ndc-sdk-typescript@1.2.5'; +export * as sdk from 'npm:@hasura/ndc-sdk-typescript@1.2.5'; + export type State = { - info: ProgramInfo, functions: any } -export interface Configuration { +export interface RawConfiguration { functions: string, port?: number, // Included only for punning Connector.start() hostname?: string, // Included only for punning Connector.start() @@ -25,7 +24,7 @@ export interface Configuration { preVendor?: boolean, } -export const CONFIGURATION_SCHEMA: JSONSchemaObject = { +export const RAW_CONFIGURATION_SCHEMA: JSONSchemaObject = { description: 'Typescript (Deno) Connector Configuration', type: 'object', required: [ 'functions' ], @@ -55,6 +54,19 @@ export const CONFIGURATION_SCHEMA: JSONSchemaObject = { } }; +type Configuration = { + inferenceConfig: InferenceConfig, + programInfo: ProgramInfo, +} + +type InferenceConfig = { + functions: string, + schemaMode: 'READ' | 'INFER', + schemaLocation?: string, + vendorDir: string, + preVendor: boolean, +} + export const CAPABILITIES_RESPONSE: sdk.CapabilitiesResponse = { versions: "^0.1.0", capabilities: { @@ -75,13 +87,12 @@ type Payload = { /** * Performs analysis on the supplied program. * Expects that if there are dependencies then they will have been vendored. - * - * @param cmdObj + * + * @param cmdObj * @returns Schema and argument position information */ -export function getInfo(cmdObj: Configuration): ProgramInfo { - const schemaMode = cmdObj.schemaMode || 'INFER'; - switch(schemaMode) { +export function getInfo(cmdObj: InferenceConfig): ProgramInfo { + switch(cmdObj.schemaMode) { /** * The READ option is available in case the user wants to pre-cache their schema during development. */ @@ -96,8 +107,8 @@ export function getInfo(cmdObj: Configuration): ProgramInfo { return JSON.parse(decoded); } case 'INFER': { - console.error(`Inferring schema with map location ${cmdObj.vendor}`); - const info = programInfo(cmdObj.functions, cmdObj.vendor, cmdObj.preVendor); + console.error(`Inferring schema with map location ${cmdObj.vendorDir}`); + const info = programInfo(cmdObj.functions, cmdObj.vendorDir, cmdObj.preVendor); const schemaLocation = cmdObj.schemaLocation; if(schemaLocation) { console.error(`Writing schema to ${cmdObj.schemaLocation}`); @@ -116,10 +127,10 @@ export function getInfo(cmdObj: Configuration): ProgramInfo { * Performs invocation of the requested function. * Assembles the arguments into the correct order. * This doesn't catch any exceptions. - * - * @param functions - * @param positions - * @param payload + * + * @param functions + * @param positions + * @param payload * @returns the result of invocation with no wrapper */ async function invoke(functions: any, positions: FunctionPositions, payload: Payload): Promise { @@ -137,9 +148,9 @@ async function invoke(functions: any, positions: FunctionPositions, payload: Pay /** * This takes argument position information and a payload of function * and named arguments and returns the correctly ordered arguments ready to be applied. - * - * @param functions - * @param payload + * + * @param functions + * @param payload * @returns An array of the function's arguments in the definition order */ function reposition(functions: FunctionPositions, payload: Payload): Array { @@ -178,6 +189,7 @@ function pruneFields(func: string, fields: Struct | null | undefin } async function query( + configuration: Configuration, state: State, func: string, requestArgs: Struct, @@ -188,7 +200,7 @@ async function query( args: requestArgs }; try { - const result = await invoke(state.functions, state.info.positions, payload); + const result = await invoke(state.functions, configuration.programInfo.positions, payload); const pruned = pruneFields(func, requestFields, result); return pruned; } catch(e) { @@ -214,18 +226,16 @@ function resolveArguments( /** * See https://github.com/hasura/ndc-sdk-typescript for information on these interfaces. */ -export const connector: sdk.Connector = { +export const connector: sdk.Connector = { async try_init_state( config: Configuration, _metrics: unknown ): Promise { - const functionsArg = resolve(config.functions || './functions/index.ts'); + const functionsArg = config.inferenceConfig.functions; const functionsURL = `file://${functionsArg}`; // NOTE: This is required to run directly from deno.land. const functions = await import(functionsURL); - const info = getInfo(config); return { - functions, - info + functions } }, @@ -233,8 +243,12 @@ export const connector: sdk.Connector = { return CAPABILITIES_RESPONSE; }, - make_empty_configuration(): Configuration { - const conf: Configuration = { + get_raw_configuration_schema(): JSONSchemaObject { + return RAW_CONFIGURATION_SCHEMA; + }, + + make_empty_configuration(): RawConfiguration { + const conf: RawConfiguration = { functions: './functions/index.ts', vendor: './vendor' }; @@ -242,25 +256,33 @@ export const connector: sdk.Connector = { }, // TODO: https://github.com/hasura/ndc-typescript-deno/issues/27 Make this add in the defaults - update_configuration(configuration: Configuration): Promise { + update_configuration(configuration: RawConfiguration): Promise { return Promise.resolve(configuration); }, - validate_raw_configuration(configuration: Configuration): Promise { - const defaults = { - preVendor: true, + validate_raw_configuration(configuration: RawConfiguration): Promise { + if (configuration.functions.trim() === "") { + throw new sdk.BadRequest("'functions' must be set to the location of the TypeScript file that contains your functions") + } + if (configuration.schemaMode === "READ" && !configuration.schemaLocation) { + throw new sdk.BadRequest("'schemaLocation' must be set if 'schemaMode' is READ"); } - const response = { ...defaults, ...configuration } - return Promise.resolve(response); + const inferenceConfig: InferenceConfig = { + functions: resolve(configuration.functions), + schemaMode: configuration.schemaMode ?? "INFER", + preVendor: configuration.preVendor ?? true, + schemaLocation: configuration.schemaLocation, + vendorDir: resolve(configuration.vendor || "./vendor"), + }; + const programInfo = getInfo(inferenceConfig); + return Promise.resolve({ + inferenceConfig, + programInfo + }); }, get_schema(config: Configuration): Promise { - const result = getInfo(config); - return Promise.resolve(result.schema); - }, - - get_raw_configuration_schema(): JSONSchemaObject { - return CONFIGURATION_SCHEMA; + return Promise.resolve(config.programInfo.schema); }, // TODO: https://github.com/hasura/ndc-typescript-deno/issues/28 What do we want explain to do in this scenario? @@ -274,12 +296,12 @@ export const connector: sdk.Connector = { // NOTE: query and mutation both make all functions available and discrimination is performed by the schema async query( - _configuration: Configuration, + configuration: Configuration, state: State, request: sdk.QueryRequest ): Promise { const args = resolveArguments(request.collection, request.arguments); - const result = await query(state, request.collection, args, request.query.fields); + const result = await query(configuration, state, request.collection, args, request.query.fields); return [{ aggregates: {}, rows: [{ @@ -289,7 +311,7 @@ export const connector: sdk.Connector = { }, async mutation( - _configuration: Configuration, + configuration: Configuration, state: State, request: sdk.MutationRequest ): Promise { @@ -297,7 +319,7 @@ export const connector: sdk.Connector = { for(const op of request.operations) { switch(op.type) { case 'procedure': { - const result = await query(state, op.name, op.arguments, op.fields); + const result = await query(configuration, state, op.name, op.arguments, op.fields); results.push({ affected_rows: 1, returning: [{ diff --git a/src/entrypoint.sh b/src/entrypoint.sh index e40b8e4..03cd101 100755 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -1,8 +1,8 @@ -#!/bin/sh +#!/usr/bin/env sh #### # This script serves as the entrypoint for the Dockerfile -# It is used both during the build phase (with EARLY_ENTRYPOINT_EXIT=true), and during the run phase. +# It is used both during the build phase (with PRECACHE_ONLY=true), and during the run phase. # This could be split into two scripts easily enough if that is required. #### @@ -10,12 +10,17 @@ set -e cd /functions +if [ ! -f ./src/index.ts ] +then + echo "No /functions/src/index.ts found - Please place your functions in /functions/src" + exit 0 +fi + if [ -d vendor ] then echo "found existing vendor results" else - deno vendor --node-modules-dir -f index.ts - deno vendor -f /app/mod.ts + deno vendor --node-modules-dir --vendor /functions/vendor -f ./src/index.ts fi if [ -f schema.json ] @@ -24,25 +29,32 @@ then else deno run \ --allow-env --allow-sys --allow-read --allow-net --allow-write \ - --import-map vendor/import_map.json \ /app/mod.ts infer \ --vendor /functions/vendor \ - index.ts >schema.json + ./src/index.ts >schema.json fi -if [ "$EARLY_ENTRYPOINT_EXIT" ] +if [ "$PRECACHE_ONLY" ] then echo "Thanks for running pre-caching - Please come again soon!" exit 0 fi -# The config is always the same for `connector create` -echo '{"functions": "/functions/index.ts", "vendor": "/functions/vendor", "preVendor": false, "schemaMode": "READ", "schemaLocation": "/functions/schema.json"}' \ - > /config.json +if [[ "$WATCH" == "1" || "$WATCH" == "true" ]] +then + DENO_PARAMS="--watch=/functions/src --no-clear-screen" + echo '{"functions": "/functions/src/index.ts", "vendor": "/functions/vendor", "preVendor": true, "schemaMode": "INFER" }' \ + > /etc/connector-config.json + +else + DENO_PARAMS="" + echo '{"functions": "/functions/src/index.ts", "vendor": "/functions/vendor", "preVendor": false, "schemaMode": "READ", "schemaLocation": "/functions/schema.json"}' \ + > /etc/connector-config.json +fi deno run \ --allow-run --allow-net --allow-read --allow-write --allow-env --allow-sys \ - --import-map vendor/import_map.json \ + $DENO_PARAMS \ /app/mod.ts serve \ --port 8080 \ - --configuration /config.json + --configuration /etc/connector-config.json diff --git a/src/infer.ts b/src/infer.ts index 641d285..9bb7204 100644 --- a/src/infer.ts +++ b/src/infer.ts @@ -2,16 +2,16 @@ /** * This module provides the inference implementation for the connector. * It relies on the Typescript compiler to perform the heavy lifting. - * + * * The exported function that is intended for use is `programInfo`. - * - * Dependencies are required to be vendored before invocation. + * + * Dependencies are required to be vendored before invocation. */ import ts, { FunctionDeclaration, StringLiteralLike } from "npm:typescript@5.1.6"; -import { resolve, dirname } from "https://deno.land/std@0.203.0/path/mod.ts"; -import { existsSync } from "https://deno.land/std@0.201.0/fs/mod.ts"; -import * as sdk from 'npm:@hasura/ndc-sdk-typescript@1.0.0'; +import { resolve, dirname } from "https://deno.land/std@0.208.0/path/mod.ts"; +import { existsSync } from "https://deno.land/std@0.208.0/fs/mod.ts"; +import * as sdk from 'npm:@hasura/ndc-sdk-typescript@1.2.5'; export type Struct = Record; @@ -50,7 +50,6 @@ const scalar_mappings: {[key: string]: string} = { const no_ops: sdk.ScalarType = { aggregate_functions: {}, comparison_operators: {}, - update_operators: {}, }; // TODO: https://github.com/hasura/ndc-typescript-deno/issues/21 Use standard logging from SDK @@ -138,7 +137,7 @@ function validate_type(root_file: string, checker: ts.TypeChecker, object_names: const info = get_object_type_info(root_file, checker, ty, name); if (info) { const type_str_qualified = info.type_name; // lookup_type_name(root_file, checker, info, object_names, name, ty); - + // Shortcut recursion if the type has already been named if(schema_response.object_types[type_str_qualified]) { return { type: 'named', name: type_str_qualified }; @@ -179,7 +178,7 @@ function validate_type(root_file: string, checker: ts.TypeChecker, object_names: /** * Executes `deno vendor` in a subprocess as a conveneience. - * + * * @param vendorPath * @param filename */ @@ -208,10 +207,10 @@ function error(message: string): never { /** * Logs simple listing of functions/procedures on stderr. - * - * @param prompt - * @param positions - * @param info + * + * @param prompt + * @param positions + * @param info */ function listing(prompt: string, positions: FunctionPositions, info: Array) { if(info.length > 0) { @@ -263,7 +262,7 @@ function get_object_type_info(root_file: string, checker: ts.TypeChecker, ty: an // - type Bar = { test: string } // - type GenericBar = { data: T } if ((ty.objectFlags & ts.ObjectFlags.Anonymous) !== 0) { - const members = + const members = ty.aliasTypeArguments !== undefined ? ty.target.members : ty.members; @@ -281,7 +280,7 @@ function get_object_type_info(root_file: string, checker: ts.TypeChecker, ty: an generic_parameter_types: [], members: get_members(checker, ty, Array.from(ty.members.keys())), } - } + } // Generic interface type - this covers: // interface IGenericThing { data: T } else if ((ty.objectFlags & ts.ObjectFlags.Reference) !== 0 && (ty.target.objectFlags & ts.ObjectFlags.Interface) !== 0 && checker.isArrayType(ty) == false && ty.symbol.escapedName !== "Promise") { @@ -306,30 +305,8 @@ function get_object_type_info(root_file: string, checker: ts.TypeChecker, ty: an return null; } -/** - * This wraps the exception variant programInfoException and calls Deno.exit(1) on error. - * @param filename_arg - * @param vendor_arg - * @param perform_vendor - * @returns - */ -export function programInfo(filename_arg?: string, vendor_arg?: string, perform_vendor?: boolean): ProgramInfo { - try { - const info = programInfoException(filename_arg, vendor_arg, perform_vendor); - listing('Functions', info.positions, info.schema.functions) - listing('Procedures', info.positions, info.schema.procedures) - return info; - } catch(e) { - console.error(e.message); - // console.error(e.stack); - Deno.exit(1); - } -} - -export function programInfoException(filename_arg?: string, vendor_arg?: string, perform_vendor?: boolean): ProgramInfo { +export function programInfo(filename: string, vendorPath: string, perform_vendor: boolean): ProgramInfo { // TODO: https://github.com/hasura/ndc-typescript-deno/issues/27 This should have already been established upstream - const filename = resolve(filename_arg || './functions/index.ts'); - const vendorPath = resolve(vendor_arg || './vendor'); const importMapPath = `${vendorPath}/import_map.json`; let pathsMap: {[key: string]: Array} = {}; @@ -558,5 +535,8 @@ export function programInfoException(filename_arg?: string, vendor_arg?: string, positions } + listing('Functions', result.positions, result.schema.functions) + listing('Procedures', result.positions, result.schema.procedures) + return result; } diff --git a/src/mod.ts b/src/mod.ts index ee39cdf..bd7d129 100644 --- a/src/mod.ts +++ b/src/mod.ts @@ -1,5 +1,3 @@ - - /** * Typescript entrypoint for running the connector. */ @@ -8,10 +6,10 @@ import * as commander from 'npm:commander@11.0.0'; import { programInfo } from './infer.ts' import { connector } from './connector.ts' -import sdk from 'npm:@hasura/ndc-sdk-typescript@1.2.4'; +import sdk from 'npm:@hasura/ndc-sdk-typescript@1.2.5'; const inferCommand = new commander.Command("infer") - .argument('', 'Typescript source entrypoint') + .argument('', 'TypeScript source entrypoint') .option('-v, --vendor ', 'Vendor location (optional)') .action((entrypoint, cmdObj, _command) => { const output = programInfo(entrypoint, cmdObj.vendor, cmdObj.preVendor); diff --git a/src/test/classes_test.ts b/src/test/classes_test.ts index 8b1b3bc..b2ab68c 100644 --- a/src/test/classes_test.ts +++ b/src/test/classes_test.ts @@ -1,6 +1,6 @@ -import * as test from "https://deno.land/std@0.202.0/assert/mod.ts"; -import * as path from "https://deno.land/std@0.203.0/path/mod.ts"; +import * as test from "https://deno.land/std@0.208.0/assert/mod.ts"; +import * as path from "https://deno.land/std@0.208.0/path/mod.ts"; import * as infer from '../infer.ts'; // Classes are currently not supoported and should throw an error diff --git a/src/test/complex_dependency_test.ts b/src/test/complex_dependency_test.ts index 3641f40..3238b18 100644 --- a/src/test/complex_dependency_test.ts +++ b/src/test/complex_dependency_test.ts @@ -1,6 +1,6 @@ -import * as test from "https://deno.land/std@0.202.0/assert/mod.ts"; -import * as path from "https://deno.land/std@0.203.0/path/mod.ts"; +import * as test from "https://deno.land/std@0.208.0/assert/mod.ts"; +import * as path from "https://deno.land/std@0.208.0/path/mod.ts"; import * as infer from '../infer.ts'; // This program omits its return type and it is inferred via the 'fetch' dependency. diff --git a/src/test/conflicting_names_test.ts b/src/test/conflicting_names_test.ts index dd73b24..c922a82 100644 --- a/src/test/conflicting_names_test.ts +++ b/src/test/conflicting_names_test.ts @@ -1,6 +1,6 @@ -import * as test from "https://deno.land/std@0.202.0/assert/mod.ts"; -import * as path from "https://deno.land/std@0.203.0/path/mod.ts"; +import * as test from "https://deno.land/std@0.208.0/assert/mod.ts"; +import * as path from "https://deno.land/std@0.208.0/path/mod.ts"; import * as infer from '../infer.ts'; Deno.test("Conflicting Type Names in Imports", () => { @@ -64,17 +64,14 @@ Deno.test("Conflicting Type Names in Imports", () => { Boolean: { aggregate_functions: {}, comparison_operators: {}, - update_operators: {}, }, Float: { aggregate_functions: {}, comparison_operators: {}, - update_operators: {}, }, String: { aggregate_functions: {}, comparison_operators: {}, - update_operators: {}, }, } } diff --git a/src/test/external_dependencies_test.ts b/src/test/external_dependencies_test.ts index 68600e2..ded9f58 100644 --- a/src/test/external_dependencies_test.ts +++ b/src/test/external_dependencies_test.ts @@ -1,6 +1,6 @@ -import * as test from "https://deno.land/std@0.202.0/assert/mod.ts"; -import * as path from "https://deno.land/std@0.203.0/path/mod.ts"; +import * as test from "https://deno.land/std@0.208.0/assert/mod.ts"; +import * as path from "https://deno.land/std@0.208.0/path/mod.ts"; import * as infer from '../infer.ts'; // Skipped due to NPM dependency resolution not currently being supported. @@ -22,7 +22,6 @@ Deno.test({ String: { aggregate_functions: {}, comparison_operators: {}, - update_operators: {}, }, }, object_types: {}, diff --git a/src/test/infer_test.ts b/src/test/infer_test.ts index 21607e1..1018075 100644 --- a/src/test/infer_test.ts +++ b/src/test/infer_test.ts @@ -1,6 +1,6 @@ -import * as test from "https://deno.land/std@0.202.0/assert/mod.ts"; -import * as path from "https://deno.land/std@0.203.0/path/mod.ts"; +import * as test from "https://deno.land/std@0.208.0/assert/mod.ts"; +import * as path from "https://deno.land/std@0.208.0/path/mod.ts"; import * as infer from '../infer.ts'; Deno.test("Inference", () => { @@ -21,12 +21,10 @@ Deno.test("Inference", () => { Float: { aggregate_functions: {}, comparison_operators: {}, - update_operators: {}, }, String: { aggregate_functions: {}, comparison_operators: {}, - update_operators: {}, }, }, object_types: {}, @@ -143,12 +141,10 @@ Deno.test("Complex Inference", () => { Float: { aggregate_functions: {}, comparison_operators: {}, - update_operators: {}, }, String: { aggregate_functions: {}, comparison_operators: {}, - update_operators: {}, }, } } diff --git a/src/test/inline_types_test.ts b/src/test/inline_types_test.ts index c247a6f..29a0c42 100644 --- a/src/test/inline_types_test.ts +++ b/src/test/inline_types_test.ts @@ -1,6 +1,6 @@ -import * as test from "https://deno.land/std@0.202.0/assert/mod.ts"; -import * as path from "https://deno.land/std@0.203.0/path/mod.ts"; +import * as test from "https://deno.land/std@0.208.0/assert/mod.ts"; +import * as path from "https://deno.land/std@0.208.0/path/mod.ts"; import * as infer from '../infer.ts'; Deno.test({ name: "Type Parameters", @@ -20,12 +20,10 @@ Deno.test({ name: "Type Parameters", "String": { "aggregate_functions": {}, "comparison_operators": {}, - "update_operators": {} }, "Float": { "aggregate_functions": {}, "comparison_operators": {}, - "update_operators": {} } }, "object_types": { diff --git a/src/test/pg_dep_test.ts b/src/test/pg_dep_test.ts index a3eb993..1eef5cd 100644 --- a/src/test/pg_dep_test.ts +++ b/src/test/pg_dep_test.ts @@ -1,6 +1,6 @@ -import * as test from "https://deno.land/std@0.202.0/assert/mod.ts"; -import * as path from "https://deno.land/std@0.203.0/path/mod.ts"; +import * as test from "https://deno.land/std@0.208.0/assert/mod.ts"; +import * as path from "https://deno.land/std@0.208.0/path/mod.ts"; import * as infer from '../infer.ts'; // NOTE: It would be good to have explicit timeout for this @@ -84,17 +84,14 @@ Deno.test("Inferred Dependency Based Result Type", () => { String: { aggregate_functions: {}, comparison_operators: {}, - update_operators: {}, }, insert_todos_output: { aggregate_functions: {}, comparison_operators: {}, - update_operators: {}, }, insert_user_output: { aggregate_functions: {}, comparison_operators: {}, - update_operators: {}, }, }, object_types: {}, diff --git a/src/test/recursive_types_test.ts b/src/test/recursive_types_test.ts index 3edb4cf..5000b37 100644 --- a/src/test/recursive_types_test.ts +++ b/src/test/recursive_types_test.ts @@ -1,6 +1,6 @@ -import * as test from "https://deno.land/std@0.202.0/assert/mod.ts"; -import * as path from "https://deno.land/std@0.203.0/path/mod.ts"; +import * as test from "https://deno.land/std@0.208.0/assert/mod.ts"; +import * as path from "https://deno.land/std@0.208.0/path/mod.ts"; import * as infer from '../infer.ts'; Deno.test("Recursive Types", () => { @@ -51,7 +51,6 @@ Deno.test("Recursive Types", () => { Float: { aggregate_functions: {}, comparison_operators: {}, - update_operators: {}, }, }, } diff --git a/src/test/type_parameters_test.ts b/src/test/type_parameters_test.ts index f1eae2e..08c712e 100644 --- a/src/test/type_parameters_test.ts +++ b/src/test/type_parameters_test.ts @@ -1,6 +1,6 @@ -import * as test from "https://deno.land/std@0.202.0/assert/mod.ts"; -import * as path from "https://deno.land/std@0.203.0/path/mod.ts"; +import * as test from "https://deno.land/std@0.208.0/assert/mod.ts"; +import * as path from "https://deno.land/std@0.208.0/path/mod.ts"; import * as infer from '../infer.ts'; Deno.test({ name: "Type Parameters", @@ -58,12 +58,10 @@ Deno.test({ name: "Type Parameters", Float: { aggregate_functions: {}, comparison_operators: {}, - update_operators: {}, }, String: { aggregate_functions: {}, comparison_operators: {}, - update_operators: {}, }, }, procedures: [ diff --git a/src/test/validation_algorithm_test.ts b/src/test/validation_algorithm_test.ts index 38cd3da..9c238dd 100644 --- a/src/test/validation_algorithm_test.ts +++ b/src/test/validation_algorithm_test.ts @@ -1,6 +1,6 @@ -import * as test from "https://deno.land/std@0.202.0/assert/mod.ts"; -import * as path from "https://deno.land/std@0.203.0/path/mod.ts"; +import * as test from "https://deno.land/std@0.208.0/assert/mod.ts"; +import * as path from "https://deno.land/std@0.208.0/path/mod.ts"; import * as infer from '../infer.ts'; Deno.test({ name: "Type Parameters", @@ -234,12 +234,10 @@ Deno.test({ name: "Type Parameters", Float: { aggregate_functions: {}, comparison_operators: {}, - update_operators: {}, }, String: { aggregate_functions: {}, comparison_operators: {}, - update_operators: {}, }, } } diff --git a/src/test/void_test.ts b/src/test/void_test.ts index 6988282..88e279c 100644 --- a/src/test/void_test.ts +++ b/src/test/void_test.ts @@ -1,6 +1,6 @@ -import * as test from "https://deno.land/std@0.202.0/assert/mod.ts"; -import * as path from "https://deno.land/std@0.203.0/path/mod.ts"; +import * as test from "https://deno.land/std@0.208.0/assert/mod.ts"; +import * as path from "https://deno.land/std@0.208.0/path/mod.ts"; import * as infer from '../infer.ts'; // NOTE: It would be good to have explicit timeout for this