Skip to content

Commit

Permalink
Merge pull request #1217 from polywrap/ts-codegen-type-safety
Browse files Browse the repository at this point in the history
Feat: TypeScript App/Plugin Codegen Type Safety
  • Loading branch information
dOrgJelli authored Sep 7, 2022
2 parents 165b176 + a5d42ba commit 1e04535
Show file tree
Hide file tree
Showing 16 changed files with 251 additions and 251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export type {{#detectKeyword}}{{type}}{{/detectKeyword}} = {{type}}Enum | {{type
{{#methods}}

/* URI: "{{parent.uri}}" */
interface {{parent.type}}_Args_{{name}} extends Record<string, unknown> {
interface {{parent.type}}_Args_{{name}} {
{{#arguments}}
{{name}}{{^required}}?{{/required}}: {{#toTypescript}}{{toGraphQLType}}{{/toTypescript}};
{{/arguments}}
Expand All @@ -106,7 +106,7 @@ export const {{type}} = {
return client.invoke<{{#return}}{{#toTypescript}}{{toGraphQLType}}{{/toTypescript}}{{/return}}>({
uri,
method: "{{name}}",
args
args: args as unknown as Record<string, unknown>
});
}{{^last}},{{/last}}
{{^last}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
{{#moduleType}}
{{#methods}}

export interface Args_{{name}} extends Record<string, unknown> {
export interface Args_{{name}} {
{{#arguments}}
{{name}}{{^required}}?{{/required}}: {{#toTypescript}}{{toGraphQLType}}{{/toTypescript}};
{{/arguments}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export type {{#detectKeyword}}{{type}}{{/detectKeyword}} = {{type}}Enum | {{type
{{#importedModuleTypes}}
{{#methods}}
/* URI: "{{parent.uri}}" */
interface {{parent.type}}_Args_{{name}} extends Record<string, unknown> {
interface {{parent.type}}_Args_{{name}} {
{{#arguments}}
{{name}}{{^required}}?{{/required}}: {{#toTypescript}}{{toGraphQLType}}{{/toTypescript}};
{{/arguments}}
Expand All @@ -116,7 +116,7 @@ export const {{type}} = {
return client.invoke<{{#return}}{{#toTypescript}}{{toGraphQLType}}{{/toTypescript}}{{/return}}>({
uri: "{{parent.uri}}",
method: "{{name}}",
args
args: args as unknown as Record<string, unknown>
});
}{{^last}},{{/last}}
{{^last}}
Expand All @@ -141,7 +141,7 @@ export class {{#detectKeyword}}{{type}}{{/detectKeyword}} {
return client.invoke<{{#return}}{{#toTypescript}}{{toGraphQLType}}{{/toTypescript}}{{/return}}>({
uri: this.uri,
method: "{{name}}",
args
args: args as unknown as Record<string, unknown>
});
}
{{^last}}
Expand Down
8 changes: 4 additions & 4 deletions packages/test-cases/cases/bind/sanity/output/app-ts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export type TestImport_Enum = TestImport_EnumEnum | TestImport_EnumString;
/// Imported Modules START ///

/* URI: "testimport.uri.eth" */
interface TestImport_Module_Args_importedMethod extends Record<string, unknown> {
interface TestImport_Module_Args_importedMethod {
str: Types.String;
optStr?: Types.String | null;
u: Types.UInt;
Expand All @@ -160,7 +160,7 @@ interface TestImport_Module_Args_importedMethod extends Record<string, unknown>
}

/* URI: "testimport.uri.eth" */
interface TestImport_Module_Args_anotherMethod extends Record<string, unknown> {
interface TestImport_Module_Args_anotherMethod {
arg: Array<Types.String>;
}

Expand All @@ -174,7 +174,7 @@ export const TestImport_Module = {
return client.invoke<Types.TestImport_Object | null>({
uri,
method: "importedMethod",
args
args: args as unknown as Record<string, unknown>
});
},

Expand All @@ -186,7 +186,7 @@ export const TestImport_Module = {
return client.invoke<Types.Int32>({
uri,
method: "anotherMethod",
args
args: args as unknown as Record<string, unknown>
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
MaybeAsync
} from "@polywrap/core-js";

export interface Args_moduleMethod extends Record<string, unknown> {
export interface Args_moduleMethod {
str: Types.String;
optStr?: Types.String | null;
en: Types.CustomEnum;
Expand All @@ -23,21 +23,21 @@ export interface Args_moduleMethod extends Record<string, unknown> {
mapOfArrOfObj: Map<Types.String, Array<Types.AnotherType>>;
}

export interface Args_objectMethod extends Record<string, unknown> {
export interface Args_objectMethod {
object: Types.AnotherType;
optObject?: Types.AnotherType | null;
objectArray: Array<Types.AnotherType>;
optObjectArray?: Array<Types.AnotherType | null> | null;
}

export interface Args_optionalEnvMethod extends Record<string, unknown> {
export interface Args_optionalEnvMethod {
object: Types.AnotherType;
optObject?: Types.AnotherType | null;
objectArray: Array<Types.AnotherType>;
optObjectArray?: Array<Types.AnotherType | null> | null;
}

export interface Args_if extends Record<string, unknown> {
export interface Args_if {
if: Types._else;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export type TestImport_Enum = TestImport_EnumEnum | TestImport_EnumString;
/// Imported Modules START ///

/* URI: "testimport.uri.eth" */
interface TestImport_Module_Args_importedMethod extends Record<string, unknown> {
interface TestImport_Module_Args_importedMethod {
str: Types.String;
optStr?: Types.String | null;
u: Types.UInt;
Expand All @@ -173,7 +173,7 @@ interface TestImport_Module_Args_importedMethod extends Record<string, unknown>
}

/* URI: "testimport.uri.eth" */
interface TestImport_Module_Args_anotherMethod extends Record<string, unknown> {
interface TestImport_Module_Args_anotherMethod {
arg: Array<Types.String>;
}

Expand All @@ -191,7 +191,7 @@ export class TestImport_Module {
return client.invoke<Types.TestImport_Object | null>({
uri: this.uri,
method: "importedMethod",
args
args: args as unknown as Record<string, unknown>
});
}

Expand All @@ -202,7 +202,7 @@ export class TestImport_Module {
return client.invoke<Types.Int32>({
uri: this.uri,
method: "anotherMethod",
args
args: args as unknown as Record<string, unknown>
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import {
MaybeAsync
} from "@polywrap/core-js";

export interface Args_methodOne extends Record<string, unknown> {
export interface Args_methodOne {
str: Types.String;
optStr?: Types.String | null;
}

export interface Args_methodTwo extends Record<string, unknown> {
export interface Args_methodTwo {
arg: Types.UInt32;
}

Expand Down
Loading

0 comments on commit 1e04535

Please sign in to comment.