From 26fd283f9f34a7b22c6159e32d5b0684df96794f Mon Sep 17 00:00:00 2001 From: n0cte Date: Thu, 25 Aug 2022 04:31:42 +0300 Subject: [PATCH 01/12] simplify package url matching --- packages/schema/bind/src/bindings/golang/functions.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/packages/schema/bind/src/bindings/golang/functions.ts b/packages/schema/bind/src/bindings/golang/functions.ts index 132a5962c7..e1a95d706a 100644 --- a/packages/schema/bind/src/bindings/golang/functions.ts +++ b/packages/schema/bind/src/bindings/golang/functions.ts @@ -99,15 +99,6 @@ export const makeImports: MustacheFn = () => { return (text: string, render: (template: string) => string): string => { const types = render(text).split(","); const exist: { [key: string]: boolean } = {}; - const pattern = new RegExp( - "^(https?:\\/\\/)?" + // protocol - "((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|" + // domain name - "((\\d{1,3}\\.){3}\\d{1,3}))" + // OR ip (v4) address - "(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*" + // port and path - "(\\?[;&a-z\\d%_.~+=-]*)?" + // query string - "(\\#[-a-z\\d_]*)?$", - "i" - ); for (const t of types) { switch (t) { case "*big.Int": @@ -119,7 +110,7 @@ export const makeImports: MustacheFn = () => { exist["github.com/valyala/fastjson"] = true; break; default: - if (pattern.test(t)) { + if (/([^/\s]+\/)(.*)/.test(t)) { exist[t] = true; } break; From 81517ce45630acded32e99f2b3f7d4a59c192f14 Mon Sep 17 00:00:00 2001 From: n0cte Date: Fri, 26 Aug 2022 20:14:01 +0300 Subject: [PATCH 02/12] remove unused import --- packages/schema/bind/src/bindings/golang/functions.ts | 6 ++---- .../golang/wasm/templates/env-type/Env%type%-go.mustache | 2 +- .../templates/env-type/Env%type%Serialization-go.mustache | 2 +- .../wasm/templates/imported/env-type/Env%type%-go.mustache | 2 +- .../imported/env-type/Env%type%Serialization-go.mustache | 2 +- .../imported/module-type/%type%Serialization-go.mustache | 2 +- .../templates/imported/object-type/Object%type%-go.mustache | 2 +- .../object-type/Object%type%Serialization-go.mustache | 2 +- .../module-type/module/%type%Serialization-go.mustache | 2 +- .../wasm/templates/module-type/types/%type%Args-go.mustache | 3 +-- .../wasm/templates/object-type/Object%type%-go.mustache | 2 +- .../object-type/Object%type%Serialization-go.mustache | 2 +- .../cases/bind/sanity/output/wasm-go/types/module_args.go | 4 ---- 13 files changed, 13 insertions(+), 20 deletions(-) diff --git a/packages/schema/bind/src/bindings/golang/functions.ts b/packages/schema/bind/src/bindings/golang/functions.ts index e1a95d706a..c8682f469b 100644 --- a/packages/schema/bind/src/bindings/golang/functions.ts +++ b/packages/schema/bind/src/bindings/golang/functions.ts @@ -116,15 +116,13 @@ export const makeImports: MustacheFn = () => { break; } } - const imports: Array = [ - "github.com/consideritdone/polywrap-go/polywrap/msgpack", - ]; + const imports: Array = []; imports.push(...Object.keys(exist)); const txt = imports .sort() .map((imp) => `\t"${imp}"`) .join("\n"); - return `import (\n${txt}\n)`; + return txt !== "" ? `import (\n${txt}\n)` : ""; }; }; diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/env-type/Env%type%-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/env-type/Env%type%-go.mustache index 4cc1a1eea6..5f8f4bb605 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/env-type/Env%type%-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/env-type/Env%type%-go.mustache @@ -1,6 +1,6 @@ package types -{{#makeImports}}{{#properties}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/properties}}{{/makeImports}} +{{#makeImports}}github.com/consideritdone/polywrap-go/polywrap/msgpack,{{#properties}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/properties}}{{/makeImports}} type {{#toUpper}}{{type}}{{/toUpper}} struct { {{#stuctProps}} diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/env-type/Env%type%Serialization-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/env-type/Env%type%Serialization-go.mustache index 0574f0e584..e5f6038776 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/env-type/Env%type%Serialization-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/env-type/Env%type%Serialization-go.mustache @@ -1,6 +1,6 @@ package types -{{#makeImports}}{{#properties}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/properties}}{{/makeImports}} +{{#makeImports}}github.com/consideritdone/polywrap-go/polywrap/msgpack,{{#properties}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/properties}}{{/makeImports}} func serialize{{#toUpper}}{{type}}{{/toUpper}}(value *{{#toUpper}}{{type}}{{/toUpper}}) []byte { ctx := msgpack.NewContext("Serializing (encoding) env-type: {{#toUpper}}{{type}}{{/toUpper}}") diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%-go.mustache index 7f50e2c6a6..c2baa3b34e 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%-go.mustache @@ -1,6 +1,6 @@ package {{#toSnakeCase}}{{namespace}}{{/toSnakeCase}} -{{#makeImports}}{{#properties}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/properties}}{{/makeImports}} +{{#makeImports}}github.com/consideritdone/polywrap-go/polywrap/msgpack,{{#properties}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/properties}}{{/makeImports}} type {{#toUpper}}{{type}}{{/toUpper}} struct { {{#stuctProps}} diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%Serialization-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%Serialization-go.mustache index ac4ea04a6f..4e6c9dd790 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%Serialization-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%Serialization-go.mustache @@ -1,6 +1,6 @@ package {{#toSnakeCase}}{{namespace}}{{/toSnakeCase}} -{{#makeImports}}{{#properties}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/properties}}{{/makeImports}} +{{#makeImports}}github.com/consideritdone/polywrap-go/polywrap/msgpack,{{#properties}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/properties}}{{/makeImports}} func serialize{{#toUpper}}{{type}}{{/toUpper}}(value *{{#toUpper}}{{type}}{{/toUpper}}) []byte { ctx := msgpack.NewContext("Serializing (encoding) env-type: {{#toUpper}}{{type}}{{/toUpper}}") diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Serialization-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Serialization-go.mustache index e908e48bfc..aac4f5059c 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Serialization-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Serialization-go.mustache @@ -1,6 +1,6 @@ package {{#toSnakeCase}}{{namespace}}{{/toSnakeCase}} -{{#makeImports}}{{#arguments}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/arguments}}{{/makeImports}} +{{#makeImports}}github.com/consideritdone/polywrap-go/polywrap/msgpack,{{#arguments}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/arguments}}{{/makeImports}} {{#methods}} type Args{{#toUpper}}{{name}}{{/toUpper}} struct { diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%-go.mustache index 7f50e2c6a6..c2baa3b34e 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%-go.mustache @@ -1,6 +1,6 @@ package {{#toSnakeCase}}{{namespace}}{{/toSnakeCase}} -{{#makeImports}}{{#properties}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/properties}}{{/makeImports}} +{{#makeImports}}github.com/consideritdone/polywrap-go/polywrap/msgpack,{{#properties}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/properties}}{{/makeImports}} type {{#toUpper}}{{type}}{{/toUpper}} struct { {{#stuctProps}} diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%Serialization-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%Serialization-go.mustache index 3274d8b9c4..7fab6d87f5 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%Serialization-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%Serialization-go.mustache @@ -1,6 +1,6 @@ package {{#toSnakeCase}}{{namespace}}{{/toSnakeCase}} -{{#makeImports}}{{#properties}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/properties}}{{/makeImports}} +{{#makeImports}}github.com/consideritdone/polywrap-go/polywrap/msgpack,{{#properties}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/properties}}{{/makeImports}} func serialize{{#toUpper}}{{type}}{{/toUpper}}(value *{{#toUpper}}{{type}}{{/toUpper}}) []byte { ctx := msgpack.NewContext("Serializing (encoding) env-type: {{#toUpper}}{{type}}{{/toUpper}}") diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache index 6bd9f9c0f1..e944bcd35e 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache @@ -1,6 +1,6 @@ package module -{{#makeImports}}{{goImport}}/wrap/types,{{#arguments}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/arguments}}{{/makeImports}} +{{#makeImports}}github.com/consideritdone/polywrap-go/polywrap/msgpack,{{goImport}}/wrap/types,{{#arguments}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/arguments}}{{/makeImports}} {{#methods}} func deserialize{{#toUpper}}{{name}}{{/toUpper}}Args(argsBuf []byte) *types.Args{{#toUpper}}{{name}}{{/toUpper}} { diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/types/%type%Args-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/types/%type%Args-go.mustache index 6beabd9e0e..0d91b68ac7 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/types/%type%Args-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/types/%type%Args-go.mustache @@ -1,6 +1,5 @@ package types - - +{{#makeImports}}{{#arguments}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/arguments}}{{/makeImports}} {{#methods}} type Args{{#toUpper}}{{name}}{{/toUpper}} struct { {{#stuctProps}} diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/object-type/Object%type%-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/object-type/Object%type%-go.mustache index b17610926a..cbf8dfaa11 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/object-type/Object%type%-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/object-type/Object%type%-go.mustache @@ -1,6 +1,6 @@ package types -{{#makeImports}}{{#properties}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/properties}}{{/makeImports}} +{{#makeImports}}github.com/consideritdone/polywrap-go/polywrap/msgpack,{{#properties}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/properties}}{{/makeImports}} type {{#toUpper}}{{type}}{{/toUpper}} struct { {{#stuctProps}} diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/object-type/Object%type%Serialization-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/object-type/Object%type%Serialization-go.mustache index 93bec1a7d4..27abcf921c 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/object-type/Object%type%Serialization-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/object-type/Object%type%Serialization-go.mustache @@ -1,6 +1,6 @@ package types -{{#makeImports}}{{#properties}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/properties}}{{/makeImports}} +{{#makeImports}}github.com/consideritdone/polywrap-go/polywrap/msgpack,{{#properties}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/properties}}{{/makeImports}} func serialize{{#toUpper}}{{type}}{{/toUpper}}(value *{{#toUpper}}{{type}}{{/toUpper}}) []byte { ctx := msgpack.NewContext("Serializing (encoding) env-type: {{#toUpper}}{{type}}{{/toUpper}}") diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/types/module_args.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/types/module_args.go index fba2f3ead7..57c177ee8f 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-go/types/module_args.go +++ b/packages/test-cases/cases/bind/sanity/output/wasm-go/types/module_args.go @@ -1,9 +1,5 @@ package types -import ( - "github.com/consideritdone/polywrap-go/polywrap/msgpack" -) - type ArgsModuleMethod struct { Str string OptStr *string From 6d71abd4bc8694517c8f33a78980369bbac99f70 Mon Sep 17 00:00:00 2001 From: n0cte Date: Fri, 26 Aug 2022 20:16:51 +0300 Subject: [PATCH 03/12] fix template for imported module --- .../templates/imported/module-type/%type%Wrapped-go.mustache | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Wrapped-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Wrapped-go.mustache index 74b5f3e794..14098b729f 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Wrapped-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Wrapped-go.mustache @@ -12,9 +12,9 @@ func {{#toUpper}}{{type}}{{/toUpper}}{{#toUpper}}{{name}}{{/toUpper}}(args *Args argsBuf := Serialize{{#toUpper}}{{name}}{{/toUpper}}Args(args) data, err := polywrap.WrapSubinvoke("{{uri}}", "{{name}}", argsBuf) if err != nil { - return nil, result.Error() + return nil, err } - return Deserialize{{#toUpper}}{{name}}{{/toUpper}}Result(result.unwrap()), nil + return Deserialize{{#toUpper}}{{name}}{{/toUpper}}Result(data), nil } {{^last}} From 2df7eab0c7f0e53fa972d9e2caac90a272ce6b5f Mon Sep 17 00:00:00 2001 From: n0cte Date: Tue, 30 Aug 2022 02:51:58 +0300 Subject: [PATCH 04/12] add synonym for a imports --- packages/schema/bind/src/bindings/golang/functions.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/schema/bind/src/bindings/golang/functions.ts b/packages/schema/bind/src/bindings/golang/functions.ts index c8682f469b..f91cff9742 100644 --- a/packages/schema/bind/src/bindings/golang/functions.ts +++ b/packages/schema/bind/src/bindings/golang/functions.ts @@ -99,7 +99,8 @@ export const makeImports: MustacheFn = () => { return (text: string, render: (template: string) => string): string => { const types = render(text).split(","); const exist: { [key: string]: boolean } = {}; - for (const t of types) { + for (let t of types) { + t = t.trim(); switch (t) { case "*big.Int": exist[ @@ -120,7 +121,13 @@ export const makeImports: MustacheFn = () => { imports.push(...Object.keys(exist)); const txt = imports .sort() - .map((imp) => `\t"${imp}"`) + .map((imp) => { + const parts = imp.split(" as "); + if (parts.length > 1) { + return `\t${parts[1]} "${parts[0]}"`; + } + return `\t"${imp}"`; + }) .join("\n"); return txt !== "" ? `import (\n${txt}\n)` : ""; }; From 9b59cc7c206f3c6a8854d80ea55db1691477d2e6 Mon Sep 17 00:00:00 2001 From: n0cte Date: Tue, 30 Aug 2022 02:52:47 +0300 Subject: [PATCH 05/12] fix imported modules and remove spaces --- .../module/%type%Serialization-go.mustache | 6 +-- .../module/%type%Wrapped-go.mustache | 19 ++++---- .../wasm-go/module/module_serialization.go | 46 +++++++++---------- .../output/wasm-go/module/module_wrapped.go | 3 +- 4 files changed, 36 insertions(+), 38 deletions(-) diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache index e944bcd35e..0deb6f55e9 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache @@ -3,7 +3,7 @@ package module {{#makeImports}}github.com/consideritdone/polywrap-go/polywrap/msgpack,{{goImport}}/wrap/types,{{#arguments}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/arguments}}{{/makeImports}} {{#methods}} -func deserialize{{#toUpper}}{{name}}{{/toUpper}}Args(argsBuf []byte) *types.Args{{#toUpper}}{{name}}{{/toUpper}} { +func Deserialize{{#toUpper}}{{name}}{{/toUpper}}Args(argsBuf []byte) *types.Args{{#toUpper}}{{name}}{{/toUpper}} { ctx := msgpack.NewContext("Deserializing module-type: {{#toUpper}}{{name}}{{/toUpper}}") {{#arguments.length}} reader := msgpack.NewReadDecoder(ctx, argsBuf) @@ -51,8 +51,8 @@ func deserialize{{#toUpper}}{{name}}{{/toUpper}}Args(argsBuf []byte) *types.Args reader.Context().Pop() {{/arguments}} } - reader.Context().Pop() - } + reader.Context().Pop() + } {{#arguments}} {{#required}} diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Wrapped-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Wrapped-go.mustache index f3da3b7cfe..9c3859c25e 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Wrapped-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Wrapped-go.mustache @@ -1,13 +1,10 @@ package module -{{#methods.length}} -import ( - {{#env}} - "github.com/consideritdone/polywrap-go/polywrap" - {{/env}} - methods "{{goImport}}/module" -) -{{/methods.length}} +{{#makeImports}} + {{#methods}}{{#env}}github.com/consideritdone/polywrap-go/polywrap,{{/env}}{{/methods}} + {{goImport}}/module as methods +{{/makeImports}} + {{#methods}} func {{#toUpper}}{{name}}{{/toUpper}}Wrapped(argsBuf []byte, envSize uint32) []byte { @@ -25,11 +22,13 @@ func {{#toUpper}}{{name}}{{/toUpper}}Wrapped(argsBuf []byte, envSize uint32) []b {{/env}} {{#arguments.length}} - args := deserialize{{#toUpper}}{{name}}{{/toUpper}}Args(argsBuf) + args := Deserialize{{#toUpper}}{{name}}{{/toUpper}}Args(argsBuf) {{/arguments.length}} result := methods.{{#toUpper}}{{name}}{{/toUpper}}({{#arguments.length}}args{{/arguments.length}}{{^arguments.length}}nil{{/arguments.length}}{{#env}}, env{{/env}}) return Serialize{{#toUpper}}{{name}}{{/toUpper}}Result(result) } +{{^last}} -{{/methods}} +{{/last}} +{{/methods}} \ No newline at end of file diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/module/module_serialization.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/module/module_serialization.go index b076f507c3..85b22a26ab 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-go/module/module_serialization.go +++ b/packages/test-cases/cases/bind/sanity/output/wasm-go/module/module_serialization.go @@ -32,27 +32,26 @@ func DeserializeModuleMethodArgs(argsBuf []byte) *types.ArgsModuleMethod { for i := int32(reader.ReadMapLength()); i > 0; i-- { field := reader.ReadString() reader.Context().Push(field, "unknown", "searching for property type") - reader.Context().Pop() switch field { - case "Str": + case "str": reader.Context().Push(field, "string", "type found, reading property") _str = reader.ReadString() _strSet = true reader.Context().Pop() - case "OptStr": + case "optStr": reader.Context().Push(field, "*string", "type found, reading property") if !reader.IsNil() { v := reader.ReadString() _optStr = &v } reader.Context().Pop() - case "En": + case "en": reader.Context().Push(field, "CustomEnum", "type found, reading property") _en = CustomEnum(reader.ReadI32()) SanitizeCustomEnumValue(int32(_en)) _enSet = true reader.Context().Pop() - case "OptEnum": + case "optEnum": reader.Context().Push(field, "*CustomEnum", "type found, reading property") if !reader.IsNil() { v := CustomEnum(reader.ReadI32()) @@ -60,7 +59,7 @@ func DeserializeModuleMethodArgs(argsBuf []byte) *types.ArgsModuleMethod { _optEnum = &v } reader.Context().Pop() - case "EnumArray": + case "enumArray": reader.Context().Push(field, "[]CustomEnum", "type found, reading property") if reader.IsNil() { _enumArray = nil @@ -74,7 +73,7 @@ func DeserializeModuleMethodArgs(argsBuf []byte) *types.ArgsModuleMethod { } _enumArraySet = true reader.Context().Pop() - case "OptEnumArray": + case "optEnumArray": reader.Context().Push(field, "[]*CustomEnum", "type found, reading property") if reader.IsNil() { _optEnumArray = nil @@ -90,7 +89,7 @@ func DeserializeModuleMethodArgs(argsBuf []byte) *types.ArgsModuleMethod { } } reader.Context().Pop() - case "Map": + case "map": reader.Context().Push(field, "map[string]int32", "type found, reading property") if reader.IsNil() { _map = nil @@ -104,7 +103,7 @@ func DeserializeModuleMethodArgs(argsBuf []byte) *types.ArgsModuleMethod { } _mapSet = true reader.Context().Pop() - case "MapOfArr": + case "mapOfArr": reader.Context().Push(field, "map[string][]int32", "type found, reading property") if reader.IsNil() { _mapOfArr = nil @@ -126,7 +125,7 @@ func DeserializeModuleMethodArgs(argsBuf []byte) *types.ArgsModuleMethod { } _mapOfArrSet = true reader.Context().Pop() - case "MapOfObj": + case "mapOfObj": reader.Context().Push(field, "map[string]AnotherType", "type found, reading property") if reader.IsNil() { _mapOfObj = nil @@ -142,7 +141,7 @@ func DeserializeModuleMethodArgs(argsBuf []byte) *types.ArgsModuleMethod { } _mapOfObjSet = true reader.Context().Pop() - case "MapOfArrOfObj": + case "mapOfArrOfObj": reader.Context().Push(field, "map[string][]AnotherType", "type found, reading property") if reader.IsNil() { _mapOfArrOfObj = nil @@ -167,6 +166,7 @@ func DeserializeModuleMethodArgs(argsBuf []byte) *types.ArgsModuleMethod { _mapOfArrOfObjSet = true reader.Context().Pop() } + reader.Context().Pop() } if !_strSet { @@ -237,22 +237,21 @@ func DeserializeObjectMethodArgs(argsBuf []byte) *types.ArgsObjectMethod { for i := int32(reader.ReadMapLength()); i > 0; i-- { field := reader.ReadString() reader.Context().Push(field, "unknown", "searching for property type") - reader.Context().Pop() switch field { - case "Object": + case "object": reader.Context().Push(field, "AnotherType", "type found, reading property") if v := AnotherTypeRead(reader); v != nil { _object = *v } _objectSet = true reader.Context().Pop() - case "OptObject": + case "optObject": reader.Context().Push(field, "*AnotherType", "type found, reading property") if v := AnotherTypeRead(reader); v != nil { _optObject = v } reader.Context().Pop() - case "ObjectArray": + case "objectArray": reader.Context().Push(field, "[]AnotherType", "type found, reading property") if reader.IsNil() { _objectArray = nil @@ -267,7 +266,7 @@ func DeserializeObjectMethodArgs(argsBuf []byte) *types.ArgsObjectMethod { } _objectArraySet = true reader.Context().Pop() - case "OptObjectArray": + case "optObjectArray": reader.Context().Push(field, "[]*AnotherType", "type found, reading property") if reader.IsNil() { _optObjectArray = nil @@ -282,6 +281,7 @@ func DeserializeObjectMethodArgs(argsBuf []byte) *types.ArgsObjectMethod { } reader.Context().Pop() } + reader.Context().Pop() } if !_objectSet { @@ -331,22 +331,21 @@ func DeserializeOptionalEnvMethodArgs(argsBuf []byte) *types.ArgsOptionalEnvMeth for i := int32(reader.ReadMapLength()); i > 0; i-- { field := reader.ReadString() reader.Context().Push(field, "unknown", "searching for property type") - reader.Context().Pop() switch field { - case "Object": + case "object": reader.Context().Push(field, "AnotherType", "type found, reading property") if v := AnotherTypeRead(reader); v != nil { _object = *v } _objectSet = true reader.Context().Pop() - case "OptObject": + case "optObject": reader.Context().Push(field, "*AnotherType", "type found, reading property") if v := AnotherTypeRead(reader); v != nil { _optObject = v } reader.Context().Pop() - case "ObjectArray": + case "objectArray": reader.Context().Push(field, "[]AnotherType", "type found, reading property") if reader.IsNil() { _objectArray = nil @@ -361,7 +360,7 @@ func DeserializeOptionalEnvMethodArgs(argsBuf []byte) *types.ArgsOptionalEnvMeth } _objectArraySet = true reader.Context().Pop() - case "OptObjectArray": + case "optObjectArray": reader.Context().Push(field, "[]*AnotherType", "type found, reading property") if reader.IsNil() { _optObjectArray = nil @@ -376,6 +375,7 @@ func DeserializeOptionalEnvMethodArgs(argsBuf []byte) *types.ArgsOptionalEnvMeth } reader.Context().Pop() } + reader.Context().Pop() } if !_objectSet { @@ -421,9 +421,8 @@ func DeserializeIfArgs(argsBuf []byte) *types.ArgsIf { for i := int32(reader.ReadMapLength()); i > 0; i-- { field := reader.ReadString() reader.Context().Push(field, "unknown", "searching for property type") - reader.Context().Pop() switch field { - case "M_if": + case "m_if": reader.Context().Push(field, "Else", "type found, reading property") if v := ElseRead(reader); v != nil { _if = *v @@ -431,6 +430,7 @@ func DeserializeIfArgs(argsBuf []byte) *types.ArgsIf { _ifSet = true reader.Context().Pop() } + reader.Context().Pop() } if !_ifSet { diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/module/module_wrapped.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/module/module_wrapped.go index 3e003cad4b..ddeadb1a6d 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-go/module/module_wrapped.go +++ b/packages/test-cases/cases/bind/sanity/output/wasm-go/module/module_wrapped.go @@ -2,7 +2,7 @@ package module import ( "github.com/consideritdone/polywrap-go/polywrap" - methods "github.com/testorg/testrepo" + methods "github.com/testorg/testrepo/module" ) func ModuleMethodWrapped(argsBuf []byte, envSize uint32) []byte { @@ -49,4 +49,3 @@ func IfWrapped(argsBuf []byte, envSize uint32) []byte { result := methods.If(args) return SerializeIfResult(result) } - From e3db093ff84c7b538d0d936be466dfcead260519 Mon Sep 17 00:00:00 2001 From: n0cte Date: Wed, 31 Aug 2022 20:06:11 +0300 Subject: [PATCH 06/12] fix import problem for module package in wrapper --- .../bind/src/bindings/golang/functions.ts | 15 +++++--- .../module/%type%Serialization-go.mustache | 10 +++--- .../templates/value_serialize_object.mustache | 4 +-- .../wasm-go/module/module_serialization.go | 36 +++++++++---------- 4 files changed, 36 insertions(+), 29 deletions(-) diff --git a/packages/schema/bind/src/bindings/golang/functions.ts b/packages/schema/bind/src/bindings/golang/functions.ts index f91cff9742..2638dc58b0 100644 --- a/packages/schema/bind/src/bindings/golang/functions.ts +++ b/packages/schema/bind/src/bindings/golang/functions.ts @@ -122,11 +122,18 @@ export const makeImports: MustacheFn = () => { const txt = imports .sort() .map((imp) => { - const parts = imp.split(" as "); - if (parts.length > 1) { - return `\t${parts[1]} "${parts[0]}"`; + let res = ""; + if (imp.startsWith(". ")) { + res = `. "${imp.slice(2)}"`; + } else { + const parts = imp.split(" as "); + if (parts.length > 1) { + res = `${parts[1]} "${parts[0]}"`; + } else { + res = `"${imp}"`; + } } - return `\t"${imp}"`; + return `\t${res}`; }) .join("\n"); return txt !== "" ? `import (\n${txt}\n)` : ""; diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache index 0deb6f55e9..72f188fca3 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache @@ -1,9 +1,9 @@ package module -{{#makeImports}}github.com/consideritdone/polywrap-go/polywrap/msgpack,{{goImport}}/wrap/types,{{#arguments}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/arguments}}{{/makeImports}} +{{#makeImports}}github.com/consideritdone/polywrap-go/polywrap/msgpack,. {{goImport}}/wrap/types,{{#arguments}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/arguments}}{{/makeImports}} {{#methods}} -func Deserialize{{#toUpper}}{{name}}{{/toUpper}}Args(argsBuf []byte) *types.Args{{#toUpper}}{{name}}{{/toUpper}} { +func Deserialize{{#toUpper}}{{name}}{{/toUpper}}Args(argsBuf []byte) *Args{{#toUpper}}{{name}}{{/toUpper}} { ctx := msgpack.NewContext("Deserializing module-type: {{#toUpper}}{{name}}{{/toUpper}}") {{#arguments.length}} reader := msgpack.NewReadDecoder(ctx, argsBuf) @@ -63,7 +63,7 @@ func Deserialize{{#toUpper}}{{name}}{{/toUpper}}Args(argsBuf []byte) *types.Args {{/arguments}} {{/arguments.length}} - return &types.Args{{#toUpper}}{{name}}{{/toUpper}}{ + return &Args{{#toUpper}}{{name}}{{/toUpper}}{ {{#stuctProps}} {{#arguments}} {{#toUpper}}{{#handleKeywords}}{{name}}{{/handleKeywords}}{{/toUpper}}: _{{name}}, @@ -72,14 +72,14 @@ func Deserialize{{#toUpper}}{{name}}{{/toUpper}}Args(argsBuf []byte) *types.Args } } -func Serialize{{#toUpper}}{{name}}{{/toUpper}}Result(value {{#return}}{{#typeable}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/typeable}}{{/return}}) []byte { +func Serialize{{#toUpper}}{{name}}{{/toUpper}}Result(value {{#return}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/return}}) []byte { ctx := msgpack.NewContext("Serializing module-type: {{#toUpper}}{{name}}{{/toUpper}}") encoder := msgpack.NewWriteEncoder(ctx) Write{{#toUpper}}{{name}}{{/toUpper}}Result(encoder, value); return encoder.Buffer() } -func Write{{#toUpper}}{{name}}{{/toUpper}}Result(writer msgpack.Write, value {{#return}}{{#typeable}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/typeable}}{{/return}}) { +func Write{{#toUpper}}{{name}}{{/toUpper}}Result(writer msgpack.Write, value {{#return}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/return}}) { {{#return}} writer.Context().Push("{{name}}", "{{#toWasm}}{{toGraphQLType}}{{/toWasm}}", "writing property") {{#scalar}} diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/value_serialize_object.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/value_serialize_object.mustache index b01650869d..3b6ae4d7c6 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/value_serialize_object.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/value_serialize_object.mustache @@ -1,9 +1,9 @@ { v := value{{#lastFullIter}}i{{/lastFullIter}} {{#required}} - types.{{#toUpper}}{{type}}{{/toUpper}}Write(writer, &v) + {{#toUpper}}{{type}}{{/toUpper}}Write(writer, &v) {{/required}} {{^required}} - types.{{#toUpper}}{{type}}{{/toUpper}}Write(writer, v) + {{#toUpper}}{{type}}{{/toUpper}}Write(writer, v) {{/required}} } diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/module/module_serialization.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/module/module_serialization.go index 85b22a26ab..a2b9389ef5 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-go/module/module_serialization.go +++ b/packages/test-cases/cases/bind/sanity/output/wasm-go/module/module_serialization.go @@ -1,11 +1,11 @@ package module import ( + . "github.com/testorg/testrepo/wrap/types" "github.com/consideritdone/polywrap-go/polywrap/msgpack" - "github.com/testorg/testrepo/wrap/types" ) -func DeserializeModuleMethodArgs(argsBuf []byte) *types.ArgsModuleMethod { +func DeserializeModuleMethodArgs(argsBuf []byte) *ArgsModuleMethod { ctx := msgpack.NewContext("Deserializing module-type: ModuleMethod") reader := msgpack.NewReadDecoder(ctx, argsBuf) @@ -191,7 +191,7 @@ func DeserializeModuleMethodArgs(argsBuf []byte) *types.ArgsModuleMethod { panic(reader.Context().PrintWithContext("Missing required property: 'mapOfArrOfObj: Map'")) } - return &types.ArgsModuleMethod{ + return &ArgsModuleMethod{ Str: _str, OptStr: _optStr, En: _en, @@ -221,7 +221,7 @@ func WriteModuleMethodResult(writer msgpack.Write, value int32) { writer.Context().Pop() } -func DeserializeObjectMethodArgs(argsBuf []byte) *types.ArgsObjectMethod { +func DeserializeObjectMethodArgs(argsBuf []byte) *ArgsObjectMethod { ctx := msgpack.NewContext("Deserializing module-type: ObjectMethod") reader := msgpack.NewReadDecoder(ctx, argsBuf) @@ -291,7 +291,7 @@ func DeserializeObjectMethodArgs(argsBuf []byte) *types.ArgsObjectMethod { panic(reader.Context().PrintWithContext("Missing required property: 'objectArray: [AnotherType]'")) } - return &types.ArgsObjectMethod{ + return &ArgsObjectMethod{ Object: _object, OptObject: _optObject, ObjectArray: _objectArray, @@ -299,23 +299,23 @@ func DeserializeObjectMethodArgs(argsBuf []byte) *types.ArgsObjectMethod { } } -func SerializeObjectMethodResult(value *types.AnotherType) []byte { +func SerializeObjectMethodResult(value *AnotherType) []byte { ctx := msgpack.NewContext("Serializing module-type: ObjectMethod") encoder := msgpack.NewWriteEncoder(ctx) WriteObjectMethodResult(encoder, value); return encoder.Buffer() } -func WriteObjectMethodResult(writer msgpack.Write, value *types.AnotherType) { +func WriteObjectMethodResult(writer msgpack.Write, value *AnotherType) { writer.Context().Push("objectMethod", "*AnotherType", "writing property") { v := value - types.AnotherTypeWrite(writer, v) + AnotherTypeWrite(writer, v) } writer.Context().Pop() } -func DeserializeOptionalEnvMethodArgs(argsBuf []byte) *types.ArgsOptionalEnvMethod { +func DeserializeOptionalEnvMethodArgs(argsBuf []byte) *ArgsOptionalEnvMethod { ctx := msgpack.NewContext("Deserializing module-type: OptionalEnvMethod") reader := msgpack.NewReadDecoder(ctx, argsBuf) @@ -385,7 +385,7 @@ func DeserializeOptionalEnvMethodArgs(argsBuf []byte) *types.ArgsOptionalEnvMeth panic(reader.Context().PrintWithContext("Missing required property: 'objectArray: [AnotherType]'")) } - return &types.ArgsOptionalEnvMethod{ + return &ArgsOptionalEnvMethod{ Object: _object, OptObject: _optObject, ObjectArray: _objectArray, @@ -393,23 +393,23 @@ func DeserializeOptionalEnvMethodArgs(argsBuf []byte) *types.ArgsOptionalEnvMeth } } -func SerializeOptionalEnvMethodResult(value *types.AnotherType) []byte { +func SerializeOptionalEnvMethodResult(value *AnotherType) []byte { ctx := msgpack.NewContext("Serializing module-type: OptionalEnvMethod") encoder := msgpack.NewWriteEncoder(ctx) WriteOptionalEnvMethodResult(encoder, value); return encoder.Buffer() } -func WriteOptionalEnvMethodResult(writer msgpack.Write, value *types.AnotherType) { +func WriteOptionalEnvMethodResult(writer msgpack.Write, value *AnotherType) { writer.Context().Push("optionalEnvMethod", "*AnotherType", "writing property") { v := value - types.AnotherTypeWrite(writer, v) + AnotherTypeWrite(writer, v) } writer.Context().Pop() } -func DeserializeIfArgs(argsBuf []byte) *types.ArgsIf { +func DeserializeIfArgs(argsBuf []byte) *ArgsIf { ctx := msgpack.NewContext("Deserializing module-type: If") reader := msgpack.NewReadDecoder(ctx, argsBuf) @@ -437,23 +437,23 @@ func DeserializeIfArgs(argsBuf []byte) *types.ArgsIf { panic(reader.Context().PrintWithContext("Missing required property: 'if: else'")) } - return &types.ArgsIf{ + return &ArgsIf{ M_if: _if, } } -func SerializeIfResult(value types.Else) []byte { +func SerializeIfResult(value Else) []byte { ctx := msgpack.NewContext("Serializing module-type: If") encoder := msgpack.NewWriteEncoder(ctx) WriteIfResult(encoder, value); return encoder.Buffer() } -func WriteIfResult(writer msgpack.Write, value types.Else) { +func WriteIfResult(writer msgpack.Write, value Else) { writer.Context().Push("if", "Else", "writing property") { v := value - types.ElseWrite(writer, &v) + ElseWrite(writer, &v) } writer.Context().Pop() } From 40130368719d52b494b9d147150324ea8d6d5c7c Mon Sep 17 00:00:00 2001 From: n0cte Date: Thu, 1 Sep 2022 20:10:36 +0300 Subject: [PATCH 07/12] fix import formatting --- .../bind/src/bindings/golang/functions.ts | 24 +++++++------------ .../imported/env-type/Env%type%-go.mustache | 9 ++++--- .../Env%type%Serialization-go.mustache | 9 ++++--- .../%type%Serialization-go.mustache | 9 ++++--- .../object-type/Object%type%-go.mustache | 9 ++++--- .../Object%type%Serialization-go.mustache | 9 ++++--- .../module/%type%Serialization-go.mustache | 10 +++++--- .../module/%type%Wrapped-go.mustache | 3 --- .../module-type/types/%type%Args-go.mustache | 8 ++++++- .../object-type/Object%type%-go.mustache | 9 ++++--- .../Object%type%Serialization-go.mustache | 9 ++++--- 11 files changed, 65 insertions(+), 43 deletions(-) diff --git a/packages/schema/bind/src/bindings/golang/functions.ts b/packages/schema/bind/src/bindings/golang/functions.ts index 2638dc58b0..f53dd7d830 100644 --- a/packages/schema/bind/src/bindings/golang/functions.ts +++ b/packages/schema/bind/src/bindings/golang/functions.ts @@ -101,20 +101,14 @@ export const makeImports: MustacheFn = () => { const exist: { [key: string]: boolean } = {}; for (let t of types) { t = t.trim(); - switch (t) { - case "*big.Int": - exist[ - "github.com/consideritdone/polywrap-go/polywrap/msgpack/big" - ] = true; - break; - case "*fastjson.Value": - exist["github.com/valyala/fastjson"] = true; - break; - default: - if (/([^/\s]+\/)(.*)/.test(t)) { - exist[t] = true; - } - break; + if (t.endsWith("big.Int")) { + exist[ + "github.com/consideritdone/polywrap-go/polywrap/msgpack/big" + ] = true; + } else if (t.endsWith("fastjson.Value")) { + exist["github.com/valyala/fastjson"] = true; + } else if (/([^/\s]+\/)(.*)/.test(t)) { + exist[t] = true; } } const imports: Array = []; @@ -136,7 +130,7 @@ export const makeImports: MustacheFn = () => { return `\t${res}`; }) .join("\n"); - return txt !== "" ? `import (\n${txt}\n)` : ""; + return txt !== "" ? `\nimport (\n${txt}\n)\n\n` : "\n"; }; }; diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%-go.mustache index c2baa3b34e..9e9ce77a92 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%-go.mustache @@ -1,7 +1,10 @@ package {{#toSnakeCase}}{{namespace}}{{/toSnakeCase}} - -{{#makeImports}}github.com/consideritdone/polywrap-go/polywrap/msgpack,{{#properties}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/properties}}{{/makeImports}} - +{{#makeImports}} + github.com/consideritdone/polywrap-go/polywrap/msgpack, + {{#properties}} + {{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}} + {{/properties}} +{{/makeImports}} type {{#toUpper}}{{type}}{{/toUpper}} struct { {{#stuctProps}} {{#properties}} diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%Serialization-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%Serialization-go.mustache index 4e6c9dd790..f901ff4e87 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%Serialization-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%Serialization-go.mustache @@ -1,7 +1,10 @@ package {{#toSnakeCase}}{{namespace}}{{/toSnakeCase}} - -{{#makeImports}}github.com/consideritdone/polywrap-go/polywrap/msgpack,{{#properties}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/properties}}{{/makeImports}} - +{{#makeImports}} + github.com/consideritdone/polywrap-go/polywrap/msgpack, + {{#properties}} + {{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}} + {{/properties}} +{{/makeImports}} func serialize{{#toUpper}}{{type}}{{/toUpper}}(value *{{#toUpper}}{{type}}{{/toUpper}}) []byte { ctx := msgpack.NewContext("Serializing (encoding) env-type: {{#toUpper}}{{type}}{{/toUpper}}") encoder := msgpack.NewWriteEncoder(ctx) diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Serialization-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Serialization-go.mustache index aac4f5059c..02230ea816 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Serialization-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Serialization-go.mustache @@ -1,7 +1,10 @@ package {{#toSnakeCase}}{{namespace}}{{/toSnakeCase}} - -{{#makeImports}}github.com/consideritdone/polywrap-go/polywrap/msgpack,{{#arguments}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/arguments}}{{/makeImports}} - +{{#makeImports}} + github.com/consideritdone/polywrap-go/polywrap/msgpack, + {{#arguments}} + {{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}} + {{/arguments}} +{{/makeImports}} {{#methods}} type Args{{#toUpper}}{{name}}{{/toUpper}} struct { {{#stuctProps}} diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%-go.mustache index c2baa3b34e..9e9ce77a92 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%-go.mustache @@ -1,7 +1,10 @@ package {{#toSnakeCase}}{{namespace}}{{/toSnakeCase}} - -{{#makeImports}}github.com/consideritdone/polywrap-go/polywrap/msgpack,{{#properties}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/properties}}{{/makeImports}} - +{{#makeImports}} + github.com/consideritdone/polywrap-go/polywrap/msgpack, + {{#properties}} + {{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}} + {{/properties}} +{{/makeImports}} type {{#toUpper}}{{type}}{{/toUpper}} struct { {{#stuctProps}} {{#properties}} diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%Serialization-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%Serialization-go.mustache index 7fab6d87f5..23727487bf 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%Serialization-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%Serialization-go.mustache @@ -1,7 +1,10 @@ package {{#toSnakeCase}}{{namespace}}{{/toSnakeCase}} - -{{#makeImports}}github.com/consideritdone/polywrap-go/polywrap/msgpack,{{#properties}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/properties}}{{/makeImports}} - +{{#makeImports}} + github.com/consideritdone/polywrap-go/polywrap/msgpack, + {{#properties}} + {{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}} + {{/properties}} +{{/makeImports}} func serialize{{#toUpper}}{{type}}{{/toUpper}}(value *{{#toUpper}}{{type}}{{/toUpper}}) []byte { ctx := msgpack.NewContext("Serializing (encoding) env-type: {{#toUpper}}{{type}}{{/toUpper}}") encoder := msgpack.NewWriteEncoder(ctx) diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache index 72f188fca3..39aef5cf8b 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache @@ -1,7 +1,11 @@ package module - -{{#makeImports}}github.com/consideritdone/polywrap-go/polywrap/msgpack,. {{goImport}}/wrap/types,{{#arguments}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/arguments}}{{/makeImports}} - +{{#makeImports}} + github.com/consideritdone/polywrap-go/polywrap/msgpack, + . {{goImport}}/wrap/types, + {{#methods}} + {{#return}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/return}}, + {{/methods}} +{{/makeImports}} {{#methods}} func Deserialize{{#toUpper}}{{name}}{{/toUpper}}Args(argsBuf []byte) *Args{{#toUpper}}{{name}}{{/toUpper}} { ctx := msgpack.NewContext("Deserializing module-type: {{#toUpper}}{{name}}{{/toUpper}}") diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Wrapped-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Wrapped-go.mustache index 9c3859c25e..2382abb6e6 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Wrapped-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Wrapped-go.mustache @@ -1,11 +1,8 @@ package module - {{#makeImports}} {{#methods}}{{#env}}github.com/consideritdone/polywrap-go/polywrap,{{/env}}{{/methods}} {{goImport}}/module as methods {{/makeImports}} - - {{#methods}} func {{#toUpper}}{{name}}{{/toUpper}}Wrapped(argsBuf []byte, envSize uint32) []byte { {{#env}} diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/types/%type%Args-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/types/%type%Args-go.mustache index 0d91b68ac7..6fd7c3a7e4 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/types/%type%Args-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/types/%type%Args-go.mustache @@ -1,5 +1,11 @@ package types -{{#makeImports}}{{#arguments}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/arguments}}{{/makeImports}} +{{#makeImports}} + {{#methods}} + {{#arguments}} + {{#toWasm}}{{toGraphQLType}}{{/toWasm}}, + {{/arguments}} + {{/methods}} +{{/makeImports}} {{#methods}} type Args{{#toUpper}}{{name}}{{/toUpper}} struct { {{#stuctProps}} diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/object-type/Object%type%-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/object-type/Object%type%-go.mustache index cbf8dfaa11..ad2d15cd14 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/object-type/Object%type%-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/object-type/Object%type%-go.mustache @@ -1,7 +1,10 @@ package types - -{{#makeImports}}github.com/consideritdone/polywrap-go/polywrap/msgpack,{{#properties}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/properties}}{{/makeImports}} - +{{#makeImports}} + github.com/consideritdone/polywrap-go/polywrap/msgpack, + {{#properties}} + {{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}} + {{/properties}} +{{/makeImports}} type {{#toUpper}}{{type}}{{/toUpper}} struct { {{#stuctProps}} {{#properties}} diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/object-type/Object%type%Serialization-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/object-type/Object%type%Serialization-go.mustache index 27abcf921c..f5964d5008 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/object-type/Object%type%Serialization-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/object-type/Object%type%Serialization-go.mustache @@ -1,7 +1,10 @@ package types - -{{#makeImports}}github.com/consideritdone/polywrap-go/polywrap/msgpack,{{#properties}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}}{{/properties}}{{/makeImports}} - +{{#makeImports}} + github.com/consideritdone/polywrap-go/polywrap/msgpack, + {{#properties}} + {{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{^last}},{{/last}} + {{/properties}} +{{/makeImports}} func serialize{{#toUpper}}{{type}}{{/toUpper}}(value *{{#toUpper}}{{type}}{{/toUpper}}) []byte { ctx := msgpack.NewContext("Serializing (encoding) env-type: {{#toUpper}}{{type}}{{/toUpper}}") encoder := msgpack.NewWriteEncoder(ctx) From 150aeee904a4813852a0e938366092b850451f15 Mon Sep 17 00:00:00 2001 From: n0cte Date: Thu, 1 Sep 2022 21:32:41 +0300 Subject: [PATCH 08/12] remove unused var from generated code --- .../module-type/module/%type%Serialization-go.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache index 39aef5cf8b..ef507fb37b 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache @@ -8,8 +8,8 @@ package module {{/makeImports}} {{#methods}} func Deserialize{{#toUpper}}{{name}}{{/toUpper}}Args(argsBuf []byte) *Args{{#toUpper}}{{name}}{{/toUpper}} { - ctx := msgpack.NewContext("Deserializing module-type: {{#toUpper}}{{name}}{{/toUpper}}") {{#arguments.length}} + ctx := msgpack.NewContext("Deserializing module-type: {{#toUpper}}{{name}}{{/toUpper}}") reader := msgpack.NewReadDecoder(ctx, argsBuf) var ( From 5cefa96cb2dea30915f21f9cb5c7f0491b82c8b9 Mon Sep 17 00:00:00 2001 From: n0cte Date: Thu, 1 Sep 2022 21:33:00 +0300 Subject: [PATCH 09/12] import types if env used --- .../templates/module-type/module/%type%Wrapped-go.mustache | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Wrapped-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Wrapped-go.mustache index 2382abb6e6..d7569b8454 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Wrapped-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Wrapped-go.mustache @@ -1,7 +1,7 @@ package module {{#makeImports}} - {{#methods}}{{#env}}github.com/consideritdone/polywrap-go/polywrap,{{/env}}{{/methods}} - {{goImport}}/module as methods + {{#methods}}{{#env}}github.com/consideritdone/polywrap-go/polywrap,. {{goImport}}/wrap/types,{{/env}}{{/methods}} + {{goImport}}/module as methods, {{/makeImports}} {{#methods}} func {{#toUpper}}{{name}}{{/toUpper}}Wrapped(argsBuf []byte, envSize uint32) []byte { From 0fe9986d5bfeab97680520b445dd531d470aa0ad Mon Sep 17 00:00:00 2001 From: n0cte Date: Mon, 5 Sep 2022 16:39:12 +0300 Subject: [PATCH 10/12] fix module deserialization in go-codegen --- .../%type%Serialization-go.mustache | 2 ++ .../module-type/%type%Wrapped-go.mustache | 26 ++++++++++----- .../test_import__module_wrapped.go | 23 ------------- .../test_import/enum_test_import__enum.go | 0 .../test_import/env_test_import__env.go | 0 .../env_test_import__env_serialization.go | 0 .../object_test_import__another_object.go | 0 ...st_import__another_object_serialization.go | 0 .../test_import/object_test_import__object.go | 0 ...bject_test_import__object_serialization.go | 0 .../test_import__module_serialization.go | 0 .../test_import__module_wrapped.go | 33 +++++++++++++++++++ .../interfaces/test_import.go | 0 .../output/{wasm-go => wasm.go}/main.go | 0 .../module/module_serialization.go | 0 .../module/module_wrapped.go | 1 + .../types/enum_custom_enum.go | 0 .../{wasm-go => wasm.go}/types/enumwhile.go | 0 .../{wasm-go => wasm.go}/types/module_args.go | 0 .../types/object_another_type.go | 0 .../object_another_type_serialization.go | 0 .../types/object_custom_map_value.go | 0 .../object_custom_map_value_serialization.go | 0 .../types/object_custom_type.go | 0 .../types/object_custom_type_serialization.go | 0 .../{wasm-go => wasm.go}/types/object_env.go | 0 .../types/object_env_serialization.go | 0 .../{wasm-go => wasm.go}/types/objectelse.go | 0 .../types/objectelse_serialization.go | 0 29 files changed, 54 insertions(+), 31 deletions(-) delete mode 100644 packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/test_import__module_wrapped.go rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/imported/test_import/enum_test_import__enum.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/imported/test_import/env_test_import__env.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/imported/test_import/env_test_import__env_serialization.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/imported/test_import/object_test_import__another_object.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/imported/test_import/object_test_import__another_object_serialization.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/imported/test_import/object_test_import__object.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/imported/test_import/object_test_import__object_serialization.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/imported/test_import/test_import__module_serialization.go (100%) create mode 100644 packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/test_import__module_wrapped.go rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/interfaces/test_import.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/main.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/module/module_serialization.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/module/module_wrapped.go (96%) rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/types/enum_custom_enum.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/types/enumwhile.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/types/module_args.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/types/object_another_type.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/types/object_another_type_serialization.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/types/object_custom_map_value.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/types/object_custom_map_value_serialization.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/types/object_custom_type.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/types/object_custom_type_serialization.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/types/object_env.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/types/object_env_serialization.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/types/objectelse.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm-go => wasm.go}/types/objectelse_serialization.go (100%) diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Serialization-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Serialization-go.mustache index 02230ea816..a821550a32 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Serialization-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Serialization-go.mustache @@ -22,6 +22,7 @@ func Serialize{{#toUpper}}{{name}}{{/toUpper}}Args(value *Args{{#toUpper}}{{name } func Write{{#toUpper}}{{name}}{{/toUpper}}Args(writer msgpack.Write, value *Args{{#toUpper}}{{name}}{{/toUpper}}) { + {{#arguments.length}} writer.WriteMapLength({{arguments.length}}) {{#arguments}} writer.Context().Push("{{name}}", "{{#toWasm}}{{toGraphQLType}}{{/toWasm}}", "writing property") @@ -47,6 +48,7 @@ func Write{{#toUpper}}{{name}}{{/toUpper}}Args(writer msgpack.Write, value *Args {{/enum}} writer.Context().Pop() {{/arguments}} + {{/arguments.length}} } func Deserialize{{#toUpper}}{{name}}{{/toUpper}}Result(argsBuf []byte) {{#return}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/return}} { diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Wrapped-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Wrapped-go.mustache index 14098b729f..0052a26b34 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Wrapped-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Wrapped-go.mustache @@ -10,11 +10,16 @@ import ( {{#methods}} func {{#toUpper}}{{type}}{{/toUpper}}{{#toUpper}}{{name}}{{/toUpper}}(args *Args{{#toUpper}}{{name}}{{/toUpper}}) ({{#return}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/return}}, error) { argsBuf := Serialize{{#toUpper}}{{name}}{{/toUpper}}Args(args) - data, err := polywrap.WrapSubinvoke("{{uri}}", "{{name}}", argsBuf) - if err != nil { - return nil, err + var ( + err error + raw []byte + data {{#return}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/return}} + ) + raw, err = polywrap.WrapSubinvoke("{{uri}}", "{{name}}", argsBuf) + if err == nil { + data = Deserialize{{#toUpper}}{{name}}{{/toUpper}}Result(raw) } - return Deserialize{{#toUpper}}{{name}}{{/toUpper}}Result(data), nil + return data, err } {{^last}} @@ -25,11 +30,16 @@ func {{#toUpper}}{{type}}{{/toUpper}}{{#toUpper}}{{name}}{{/toUpper}}(args *Args {{#methods}} func {{#toUpper}}{{type}}{{/toUpper}}{{#toUpper}}{{name}}{{/toUpper}}(uri string, args *Args{{#toUpper}}{{name}}{{/toUpper}}) ({{#return}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/return}}, error) { argsBuf := Serialize{{#toUpper}}{{name}}{{/toUpper}}Args(args) - data, err := polywrap.WrapSubinvokeImplementation("{{uri}}", uri, "{{name}}", argsBuf) - if err != nil { - return nil, err + var ( + err error + raw []byte + data {{#return}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/return}} + ) + raw, err := polywrap.WrapSubinvokeImplementation("{{uri}}", uri, "{{name}}", argsBuf) + if err == nil { + data = Deserialize{{#toUpper}}{{name}}{{/toUpper}}Result(raw) } - return Deserialize{{#toUpper}}{{name}}{{/toUpper}}Result(data), nil + return data, err } {{^last}} diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/test_import__module_wrapped.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/test_import__module_wrapped.go deleted file mode 100644 index 9273cd4e30..0000000000 --- a/packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/test_import__module_wrapped.go +++ /dev/null @@ -1,23 +0,0 @@ -package test_import - -import ( - "github.com/consideritdone/polywrap-go/polywrap" -) - -func MethodImportedMethod(uri string, args *ArgsImportedMethod) (*TestImport_Object, error) { - argsBuf := SerializeImportedMethodArgs(args) - data, err := polywrap.WrapSubinvokeImplementation("testimport.uri.eth", uri, "importedMethod", argsBuf) - if err != nil { - return nil, err - } - return DeserializeImportedMethodResult(data), nil -} - -func MethodAnotherMethod(uri string, args *ArgsAnotherMethod) (int32, error) { - argsBuf := SerializeAnotherMethodArgs(args) - data, err := polywrap.WrapSubinvokeImplementation("testimport.uri.eth", uri, "anotherMethod", argsBuf) - if err != nil { - return nil, err - } - return DeserializeAnotherMethodResult(data), nil -} diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/enum_test_import__enum.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/enum_test_import__enum.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/enum_test_import__enum.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/enum_test_import__enum.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/env_test_import__env.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/env_test_import__env.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/env_test_import__env.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/env_test_import__env.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/env_test_import__env_serialization.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/env_test_import__env_serialization.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/env_test_import__env_serialization.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/env_test_import__env_serialization.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/object_test_import__another_object.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/object_test_import__another_object.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/object_test_import__another_object.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/object_test_import__another_object.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/object_test_import__another_object_serialization.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/object_test_import__another_object_serialization.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/object_test_import__another_object_serialization.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/object_test_import__another_object_serialization.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/object_test_import__object.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/object_test_import__object.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/object_test_import__object.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/object_test_import__object.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/object_test_import__object_serialization.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/object_test_import__object_serialization.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/object_test_import__object_serialization.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/object_test_import__object_serialization.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/test_import__module_serialization.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/test_import__module_serialization.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/test_import__module_serialization.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/test_import__module_serialization.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/test_import__module_wrapped.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/test_import__module_wrapped.go new file mode 100644 index 0000000000..0b03e2ceac --- /dev/null +++ b/packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/test_import__module_wrapped.go @@ -0,0 +1,33 @@ +package test_import + +import ( + "github.com/consideritdone/polywrap-go/polywrap" +) + +func MethodImportedMethod(uri string, args *ArgsImportedMethod) (*TestImport_Object, error) { + argsBuf := SerializeImportedMethodArgs(args) + var ( + err error + raw []byte + data *TestImport_Object + ) + raw, err := polywrap.WrapSubinvokeImplementation("testimport.uri.eth", uri, "importedMethod", argsBuf) + if err == nil { + data = DeserializeImportedMethodResult(raw) + } + return data, err +} + +func MethodAnotherMethod(uri string, args *ArgsAnotherMethod) (int32, error) { + argsBuf := SerializeAnotherMethodArgs(args) + var ( + err error + raw []byte + data int32 + ) + raw, err := polywrap.WrapSubinvokeImplementation("testimport.uri.eth", uri, "anotherMethod", argsBuf) + if err == nil { + data = DeserializeAnotherMethodResult(raw) + } + return data, err +} diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/interfaces/test_import.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/interfaces/test_import.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/interfaces/test_import.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/interfaces/test_import.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/main.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/main.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/main.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/main.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/module/module_serialization.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/module/module_serialization.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/module/module_serialization.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/module/module_serialization.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/module/module_wrapped.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/module/module_wrapped.go similarity index 96% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/module/module_wrapped.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/module/module_wrapped.go index ddeadb1a6d..1fa22f7056 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm-go/module/module_wrapped.go +++ b/packages/test-cases/cases/bind/sanity/output/wasm.go/module/module_wrapped.go @@ -1,6 +1,7 @@ package module import ( + . "github.com/testorg/testrepo/wrap/types" "github.com/consideritdone/polywrap-go/polywrap" methods "github.com/testorg/testrepo/module" ) diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/types/enum_custom_enum.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/types/enum_custom_enum.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/types/enum_custom_enum.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/types/enum_custom_enum.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/types/enumwhile.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/types/enumwhile.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/types/enumwhile.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/types/enumwhile.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/types/module_args.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/types/module_args.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/types/module_args.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/types/module_args.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_another_type.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_another_type.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_another_type.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_another_type.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_another_type_serialization.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_another_type_serialization.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_another_type_serialization.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_another_type_serialization.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_custom_map_value.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_custom_map_value.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_custom_map_value.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_custom_map_value.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_custom_map_value_serialization.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_custom_map_value_serialization.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_custom_map_value_serialization.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_custom_map_value_serialization.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_custom_type.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_custom_type.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_custom_type.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_custom_type.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_custom_type_serialization.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_custom_type_serialization.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_custom_type_serialization.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_custom_type_serialization.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_env.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_env.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_env.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_env.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_env_serialization.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_env_serialization.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_env_serialization.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_env_serialization.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/types/objectelse.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/types/objectelse.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/types/objectelse.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/types/objectelse.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm-go/types/objectelse_serialization.go b/packages/test-cases/cases/bind/sanity/output/wasm.go/types/objectelse_serialization.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm-go/types/objectelse_serialization.go rename to packages/test-cases/cases/bind/sanity/output/wasm.go/types/objectelse_serialization.go From a86b45efb81350c2d1a9c70d6ef9816a02131914 Mon Sep 17 00:00:00 2001 From: n0cte Date: Tue, 6 Sep 2022 15:38:33 +0300 Subject: [PATCH 11/12] add sanitization for imported pkgs names and fix problem with similar struct's names --- .../bind/src/bindings/golang/functions.ts | 92 +++---------------- .../bind/src/bindings/golang/reservedWords.ts | 25 +++++ .../bind/src/bindings/golang/wasm/index.ts | 31 +++++-- .../imported/enum-type/Enum%type%-go.mustache | 2 +- .../imported/env-type/Env%type%-go.mustache | 2 +- .../Env%type%Serialization-go.mustache | 2 +- .../interface-type/%type%-go.mustache | 2 +- .../%type%Serialization-go.mustache | 2 +- .../module-type/%type%Wrapped-go.mustache | 4 +- .../object-type/Object%type%-go.mustache | 2 +- .../Object%type%Serialization-go.mustache | 2 +- .../module/%type%Serialization-go.mustache | 11 ++- .../module/%type%Wrapped-go.mustache | 2 +- .../module-type/types/%type%Args-go.mustache | 7 +- 14 files changed, 87 insertions(+), 99 deletions(-) diff --git a/packages/schema/bind/src/bindings/golang/functions.ts b/packages/schema/bind/src/bindings/golang/functions.ts index f53dd7d830..6c5e836981 100644 --- a/packages/schema/bind/src/bindings/golang/functions.ts +++ b/packages/schema/bind/src/bindings/golang/functions.ts @@ -217,33 +217,6 @@ export const toMsgPack: MustacheFn = () => { }; }; -export const typeable: MustacheFn = () => { - return (value: string, render: (template: string) => string) => { - const type = render(value); - switch (type) { - case "int8": - case "int16": - case "int32": - case "int64": - case "uint8": - case "uint16": - case "uint32": - case "uint64": - case "string": - case "bool": - case "[]byte": - case "*big.Int": - case "*fastjson.Value": - return type; - default: - if (type.startsWith("*")) { - return `*types.${type.slice(1)}`; - } - return `types.${type}`; - } - }; -}; - export const toWasm: MustacheFn = () => { return (value: string, render: (template: string) => string) => { let type = render(value); @@ -373,69 +346,32 @@ const applyOptional = (type: string, optional: boolean, _: boolean): string => { } }; -function replaceAt(str: string, index: number, replacement: string): string { - return ( - str.substr(0, index) + replacement + str.substr(index + replacement.length) - ); -} - export const toLower: MustacheFn = () => { return (value: string, render: (template: string) => string) => { - let type = render(value); - - for (let i = 0; i < type.length; ++i) { - const char = type.charAt(i); - const lower = char.toLowerCase(); - - if (char !== lower) { - // Replace the uppercase char w/ the lowercase version - type = replaceAt(type, i, lower); - - // if (i !== 0 && type[i - 1] !== "_") { - // // Make sure all lowercase conversions have an underscore before them - // type = insertAt(type, i, "_"); - // } - } - } - - return type; + return render(value) + .split("") + .map((v) => v.toLowerCase()) + .join(""); }; }; export const toFirstLower: MustacheFn = () => { return (value: string, render: (template: string) => string) => { - let type = render(value); - - // First character must always be upper case - const firstChar = type.charAt(0); - const firstLower = firstChar.toLowerCase(); - type = replaceAt(type, 0, firstLower); - - return type; + const type = render(value); + return type.charAt(0).toLowerCase() + type.slice(1); }; }; export const toUpper: MustacheFn = () => { return (value: string, render: (template: string) => string) => { - let type = render(value); - - // First character must always be upper case - const firstChar = type.charAt(0); - const firstUpper = firstChar.toUpperCase(); - type = replaceAt(type, 0, firstUpper); - - // Look for any underscores, remove them if they exist, and make next letter uppercase - // for (let i = 0; i < type.length; ++i) { - // const char = type.charAt(i); - // - // if (char === "_") { - // const nextChar = type.charAt(i + 1); - // const nextCharUpper = nextChar.toUpperCase(); - // type = replaceAt(type, i + 1, nextCharUpper); - // type = removeAt(type, i); - // } - // } + const type = render(value); + return type.charAt(0).toUpperCase() + type.slice(1); + }; +}; - return type; +export const pkgName: MustacheFn = () => { + return (text: string, render: (template: string) => string): string => { + const name = render(text); + return reservedWordsAS.has(name) ? `pkg${name}` : name; }; }; diff --git a/packages/schema/bind/src/bindings/golang/reservedWords.ts b/packages/schema/bind/src/bindings/golang/reservedWords.ts index f962c6f7b5..696a767cb4 100644 --- a/packages/schema/bind/src/bindings/golang/reservedWords.ts +++ b/packages/schema/bind/src/bindings/golang/reservedWords.ts @@ -198,4 +198,29 @@ export const reservedWordsAS: Set = new Set([ "__visit", "__newBuffer", "__newArray", + "break", + "default", + "func", + "interface", + "select", + "case", + "defer", + "go", + "map", + "struct", + "chan", + "else", + "goto", + "package", + "switch", + "const", + "fallthrough", + "if", + "range", + "type", + "continue", + "for", + "import", + "return", + "var", ]); diff --git a/packages/schema/bind/src/bindings/golang/wasm/index.ts b/packages/schema/bind/src/bindings/golang/wasm/index.ts index 3102d038b3..8eb30576ad 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/index.ts +++ b/packages/schema/bind/src/bindings/golang/wasm/index.ts @@ -3,6 +3,7 @@ import { GenerateBindingFn } from "../.."; import { renderTemplates } from "../.."; import { loadSubTemplates } from "../../utils"; import { BindOptions, BindOutput } from "../../.."; +import { reservedWordsAS } from "../reservedWords"; import { Abi, @@ -19,6 +20,10 @@ const subTemplates = loadSubTemplates(templatesDir.entries); const templatePath = (subpath: string) => path.join(__dirname, "./templates", subpath); +function pkgName(str: string): string { + return reservedWordsAS.has(str) ? `pkg${str}` : str; +} + function camel2snake(str: string): string { str = str.replace(/([A-Z])/g, "_$1"); str = str.startsWith("_") ? str.slice(1) : str; @@ -61,7 +66,7 @@ export const generateBinding: GenerateBindingFn = ( for (const importedModuleType of abi.importedModuleTypes) { importEntries.push({ type: "Directory", - name: `${camel2snake(importedModuleType.namespace)}`, + name: `${pkgName(camel2snake(importedModuleType.namespace))}`, data: renderTemplates( templatePath("imported/module-type"), importedModuleType, @@ -76,7 +81,7 @@ export const generateBinding: GenerateBindingFn = ( for (const importedEnvType of abi.importedEnvTypes) { importEntries.push({ type: "Directory", - name: `${camel2snake(importedEnvType.namespace)}`, + name: `${pkgName(camel2snake(importedEnvType.namespace))}`, data: renderTemplates( templatePath("imported/env-type"), importedEnvType, @@ -91,7 +96,7 @@ export const generateBinding: GenerateBindingFn = ( for (const importedEnumType of abi.importedEnumTypes) { importEntries.push({ type: "Directory", - name: `${camel2snake(importedEnumType.namespace)}`, + name: `${pkgName(camel2snake(importedEnumType.namespace))}`, data: renderTemplates( templatePath("imported/enum-type"), importedEnumType, @@ -106,7 +111,7 @@ export const generateBinding: GenerateBindingFn = ( for (const importedObectType of abi.importedObjectTypes) { importEntries.push({ type: "Directory", - name: `${camel2snake(importedObectType.namespace)}`, + name: `${pkgName(camel2snake(importedObectType.namespace))}`, data: renderTemplates( templatePath("imported/object-type"), importedObectType, @@ -144,12 +149,26 @@ export const generateBinding: GenerateBindingFn = ( // Generate module type folders if (abi.moduleType) { + const imports: { [key: string]: boolean } = {}; + abi.moduleType.methods?.forEach(function (method) { + method.arguments?.forEach(function (arg) { + const tp = abi.importedObjectTypes?.find(function (mt) { + return mt.type === arg.type; + }); + if (tp) { + imports[tp.namespace] = true; + } + }); + }); + const importedTypes = Object.keys(imports).map((namespace) => ({ + namespace, + })); output.entries.push({ type: "Directory", name: "types", data: renderTemplates( templatePath("module-type/types"), - { goImport, ...abi.moduleType }, + { importedTypes, goImport, ...abi.moduleType }, subTemplates ), }); @@ -158,7 +177,7 @@ export const generateBinding: GenerateBindingFn = ( name: "module", data: renderTemplates( templatePath("module-type/module"), - { goImport, ...abi.moduleType }, + { importedTypes, goImport, ...abi.moduleType }, subTemplates ), }); diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/enum-type/Enum%type%-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/enum-type/Enum%type%-go.mustache index 1bd32360c5..72cd7bfeb6 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/enum-type/Enum%type%-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/enum-type/Enum%type%-go.mustache @@ -1,4 +1,4 @@ -package {{#toSnakeCase}}{{namespace}}{{/toSnakeCase}} +package {{#pkgName}}{{#toSnakeCase}}{{namespace}}{{/toSnakeCase}}{{/pkgName}} type {{#toUpper}}{{type}}{{/toUpper}} int32 diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%-go.mustache index 9e9ce77a92..b650c91755 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%-go.mustache @@ -1,4 +1,4 @@ -package {{#toSnakeCase}}{{namespace}}{{/toSnakeCase}} +package {{#pkgName}}{{#toSnakeCase}}{{namespace}}{{/toSnakeCase}}{{/pkgName}} {{#makeImports}} github.com/consideritdone/polywrap-go/polywrap/msgpack, {{#properties}} diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%Serialization-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%Serialization-go.mustache index f901ff4e87..af9a965b12 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%Serialization-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/env-type/Env%type%Serialization-go.mustache @@ -1,4 +1,4 @@ -package {{#toSnakeCase}}{{namespace}}{{/toSnakeCase}} +package {{#pkgName}}{{#toSnakeCase}}{{namespace}}{{/toSnakeCase}}{{/pkgName}} {{#makeImports}} github.com/consideritdone/polywrap-go/polywrap/msgpack, {{#properties}} diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/interface-type/%type%-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/interface-type/%type%-go.mustache index c63551016a..c433d42468 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/interface-type/%type%-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/interface-type/%type%-go.mustache @@ -1,4 +1,4 @@ -package {{#toSnakeCase}}{{namespace}}{{/toSnakeCase}} +package {{#pkgName}}{{#toSnakeCase}}{{namespace}}{{/toSnakeCase}}{{/pkgName}} {{#capabilities}} {{#getImplementations}} diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Serialization-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Serialization-go.mustache index a821550a32..c30f7d21ec 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Serialization-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Serialization-go.mustache @@ -1,4 +1,4 @@ -package {{#toSnakeCase}}{{namespace}}{{/toSnakeCase}} +package {{#pkgName}}{{#toSnakeCase}}{{namespace}}{{/toSnakeCase}}{{/pkgName}} {{#makeImports}} github.com/consideritdone/polywrap-go/polywrap/msgpack, {{#arguments}} diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Wrapped-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Wrapped-go.mustache index 0052a26b34..3f4fe38bd8 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Wrapped-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/module-type/%type%Wrapped-go.mustache @@ -1,4 +1,4 @@ -package {{#toSnakeCase}}{{namespace}}{{/toSnakeCase}} +package {{#pkgName}}{{#toSnakeCase}}{{namespace}}{{/toSnakeCase}}{{/pkgName}} {{#methods.length}} import ( @@ -35,7 +35,7 @@ func {{#toUpper}}{{type}}{{/toUpper}}{{#toUpper}}{{name}}{{/toUpper}}(uri string raw []byte data {{#return}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/return}} ) - raw, err := polywrap.WrapSubinvokeImplementation("{{uri}}", uri, "{{name}}", argsBuf) + raw, err = polywrap.WrapSubinvokeImplementation("{{uri}}", uri, "{{name}}", argsBuf) if err == nil { data = Deserialize{{#toUpper}}{{name}}{{/toUpper}}Result(raw) } diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%-go.mustache index 9e9ce77a92..b650c91755 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%-go.mustache @@ -1,4 +1,4 @@ -package {{#toSnakeCase}}{{namespace}}{{/toSnakeCase}} +package {{#pkgName}}{{#toSnakeCase}}{{namespace}}{{/toSnakeCase}}{{/pkgName}} {{#makeImports}} github.com/consideritdone/polywrap-go/polywrap/msgpack, {{#properties}} diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%Serialization-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%Serialization-go.mustache index 23727487bf..8623350c71 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%Serialization-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/imported/object-type/Object%type%Serialization-go.mustache @@ -1,4 +1,4 @@ -package {{#toSnakeCase}}{{namespace}}{{/toSnakeCase}} +package {{#pkgName}}{{#toSnakeCase}}{{namespace}}{{/toSnakeCase}}{{/pkgName}} {{#makeImports}} github.com/consideritdone/polywrap-go/polywrap/msgpack, {{#properties}} diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache index ef507fb37b..2cc45f280f 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Serialization-go.mustache @@ -2,13 +2,16 @@ package module {{#makeImports}} github.com/consideritdone/polywrap-go/polywrap/msgpack, . {{goImport}}/wrap/types, + {{#importedTypes}} + . {{goImport}}/wrap/imported/{{#pkgName}}{{#toSnakeCase}}{{namespace}}{{/toSnakeCase}}{{/pkgName}}, + {{/importedTypes}} {{#methods}} {{#return}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/return}}, {{/methods}} {{/makeImports}} {{#methods}} -func Deserialize{{#toUpper}}{{name}}{{/toUpper}}Args(argsBuf []byte) *Args{{#toUpper}}{{name}}{{/toUpper}} { - {{#arguments.length}} +{{#arguments.length}} +func Deserialize{{#toUpper}}{{name}}{{/toUpper}}Args(argsBuf []byte) *MethodArgs{{#toUpper}}{{name}}{{/toUpper}} { ctx := msgpack.NewContext("Deserializing module-type: {{#toUpper}}{{name}}{{/toUpper}}") reader := msgpack.NewReadDecoder(ctx, argsBuf) @@ -65,9 +68,8 @@ func Deserialize{{#toUpper}}{{name}}{{/toUpper}}Args(argsBuf []byte) *Args{{#toU } {{/required}} {{/arguments}} - {{/arguments.length}} - return &Args{{#toUpper}}{{name}}{{/toUpper}}{ + return &MethodArgs{{#toUpper}}{{name}}{{/toUpper}}{ {{#stuctProps}} {{#arguments}} {{#toUpper}}{{#handleKeywords}}{{name}}{{/handleKeywords}}{{/toUpper}}: _{{name}}, @@ -75,6 +77,7 @@ func Deserialize{{#toUpper}}{{name}}{{/toUpper}}Args(argsBuf []byte) *Args{{#toU {{/stuctProps}} } } +{{/arguments.length}} func Serialize{{#toUpper}}{{name}}{{/toUpper}}Result(value {{#return}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/return}}) []byte { ctx := msgpack.NewContext("Serializing module-type: {{#toUpper}}{{name}}{{/toUpper}}") diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Wrapped-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Wrapped-go.mustache index d7569b8454..65dd8ec082 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Wrapped-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/module/%type%Wrapped-go.mustache @@ -22,7 +22,7 @@ func {{#toUpper}}{{name}}{{/toUpper}}Wrapped(argsBuf []byte, envSize uint32) []b args := Deserialize{{#toUpper}}{{name}}{{/toUpper}}Args(argsBuf) {{/arguments.length}} - result := methods.{{#toUpper}}{{name}}{{/toUpper}}({{#arguments.length}}args{{/arguments.length}}{{^arguments.length}}nil{{/arguments.length}}{{#env}}, env{{/env}}) + result := methods.{{#toUpper}}{{name}}{{/toUpper}}({{#arguments.length}}args{{#env}},{{/env}}{{/arguments.length}}{{#env}}env{{/env}}) return Serialize{{#toUpper}}{{name}}{{/toUpper}}Result(result) } {{^last}} diff --git a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/types/%type%Args-go.mustache b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/types/%type%Args-go.mustache index 6fd7c3a7e4..cfcdeba108 100644 --- a/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/types/%type%Args-go.mustache +++ b/packages/schema/bind/src/bindings/golang/wasm/templates/module-type/types/%type%Args-go.mustache @@ -1,5 +1,8 @@ package types {{#makeImports}} + {{#importedTypes}} + . {{goImport}}/wrap/imported/{{#pkgName}}{{#toSnakeCase}}{{namespace}}{{/toSnakeCase}}{{/pkgName}}, + {{/importedTypes}} {{#methods}} {{#arguments}} {{#toWasm}}{{toGraphQLType}}{{/toWasm}}, @@ -7,13 +10,15 @@ package types {{/methods}} {{/makeImports}} {{#methods}} -type Args{{#toUpper}}{{name}}{{/toUpper}} struct { +{{#arguments.length}} +type MethodArgs{{#toUpper}}{{name}}{{/toUpper}} struct { {{#stuctProps}} {{#arguments}} {{#toUpper}}{{#handleKeywords}}{{name}}{{/handleKeywords}}{{/toUpper}} {{#toWasm}}{{toGraphQLType}}{{/toWasm}} {{/arguments}} {{/stuctProps}} } +{{/arguments.length}} {{^last}} {{/last}} From 0203274dc028c49946cbef89eb1b4aeb93d3fd34 Mon Sep 17 00:00:00 2001 From: n0cte Date: Tue, 6 Sep 2022 15:46:29 +0300 Subject: [PATCH 12/12] fix schema testcase location --- .../test_import/enum_test_import__enum.go | 0 .../test_import/env_test_import__env.go | 0 .../env_test_import__env_serialization.go | 0 .../object_test_import__another_object.go | 0 ...st_import__another_object_serialization.go | 0 .../test_import/object_test_import__object.go | 0 ...bject_test_import__object_serialization.go | 0 .../test_import__module_serialization.go | 0 .../test_import__module_wrapped.go | 4 ++-- .../interfaces/test_import.go | 0 .../output/{wasm.go => wasm-go}/main.go | 0 .../module/module_serialization.go | 20 +++++++++---------- .../module/module_wrapped.go | 4 ++-- .../types/enum_custom_enum.go | 0 .../{wasm.go => wasm-go}/types/enumwhile.go | 0 .../{wasm.go => wasm-go}/types/module_args.go | 10 +++++----- .../types/object_another_type.go | 0 .../object_another_type_serialization.go | 0 .../types/object_custom_map_value.go | 0 .../object_custom_map_value_serialization.go | 0 .../types/object_custom_type.go | 2 +- .../types/object_custom_type_serialization.go | 16 +++++++-------- .../{wasm.go => wasm-go}/types/object_env.go | 0 .../types/object_env_serialization.go | 0 .../{wasm.go => wasm-go}/types/objectelse.go | 0 .../types/objectelse_serialization.go | 0 26 files changed, 28 insertions(+), 28 deletions(-) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/imported/test_import/enum_test_import__enum.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/imported/test_import/env_test_import__env.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/imported/test_import/env_test_import__env_serialization.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/imported/test_import/object_test_import__another_object.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/imported/test_import/object_test_import__another_object_serialization.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/imported/test_import/object_test_import__object.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/imported/test_import/object_test_import__object_serialization.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/imported/test_import/test_import__module_serialization.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/imported/test_import/test_import__module_wrapped.go (75%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/interfaces/test_import.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/main.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/module/module_serialization.go (96%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/module/module_wrapped.go (92%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/types/enum_custom_enum.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/types/enumwhile.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/types/module_args.go (75%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/types/object_another_type.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/types/object_another_type_serialization.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/types/object_custom_map_value.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/types/object_custom_map_value_serialization.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/types/object_custom_type.go (98%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/types/object_custom_type_serialization.go (99%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/types/object_env.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/types/object_env_serialization.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/types/objectelse.go (100%) rename packages/test-cases/cases/bind/sanity/output/{wasm.go => wasm-go}/types/objectelse_serialization.go (100%) diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/enum_test_import__enum.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/enum_test_import__enum.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/enum_test_import__enum.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/enum_test_import__enum.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/env_test_import__env.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/env_test_import__env.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/env_test_import__env.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/env_test_import__env.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/env_test_import__env_serialization.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/env_test_import__env_serialization.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/env_test_import__env_serialization.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/env_test_import__env_serialization.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/object_test_import__another_object.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/object_test_import__another_object.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/object_test_import__another_object.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/object_test_import__another_object.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/object_test_import__another_object_serialization.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/object_test_import__another_object_serialization.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/object_test_import__another_object_serialization.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/object_test_import__another_object_serialization.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/object_test_import__object.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/object_test_import__object.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/object_test_import__object.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/object_test_import__object.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/object_test_import__object_serialization.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/object_test_import__object_serialization.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/object_test_import__object_serialization.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/object_test_import__object_serialization.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/test_import__module_serialization.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/test_import__module_serialization.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/test_import__module_serialization.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/test_import__module_serialization.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/test_import__module_wrapped.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/test_import__module_wrapped.go similarity index 75% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/test_import__module_wrapped.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/test_import__module_wrapped.go index 0b03e2ceac..4a46374cc5 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm.go/imported/test_import/test_import__module_wrapped.go +++ b/packages/test-cases/cases/bind/sanity/output/wasm-go/imported/test_import/test_import__module_wrapped.go @@ -11,7 +11,7 @@ func MethodImportedMethod(uri string, args *ArgsImportedMethod) (*TestImport_Obj raw []byte data *TestImport_Object ) - raw, err := polywrap.WrapSubinvokeImplementation("testimport.uri.eth", uri, "importedMethod", argsBuf) + raw, err = polywrap.WrapSubinvokeImplementation("testimport.uri.eth", uri, "importedMethod", argsBuf) if err == nil { data = DeserializeImportedMethodResult(raw) } @@ -25,7 +25,7 @@ func MethodAnotherMethod(uri string, args *ArgsAnotherMethod) (int32, error) { raw []byte data int32 ) - raw, err := polywrap.WrapSubinvokeImplementation("testimport.uri.eth", uri, "anotherMethod", argsBuf) + raw, err = polywrap.WrapSubinvokeImplementation("testimport.uri.eth", uri, "anotherMethod", argsBuf) if err == nil { data = DeserializeAnotherMethodResult(raw) } diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/interfaces/test_import.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/interfaces/test_import.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/interfaces/test_import.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/interfaces/test_import.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/main.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/main.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/main.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/main.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/module/module_serialization.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/module/module_serialization.go similarity index 96% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/module/module_serialization.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/module/module_serialization.go index a2b9389ef5..2bc6f24e14 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm.go/module/module_serialization.go +++ b/packages/test-cases/cases/bind/sanity/output/wasm-go/module/module_serialization.go @@ -5,7 +5,7 @@ import ( "github.com/consideritdone/polywrap-go/polywrap/msgpack" ) -func DeserializeModuleMethodArgs(argsBuf []byte) *ArgsModuleMethod { +func DeserializeModuleMethodArgs(argsBuf []byte) *MethodArgsModuleMethod { ctx := msgpack.NewContext("Deserializing module-type: ModuleMethod") reader := msgpack.NewReadDecoder(ctx, argsBuf) @@ -89,7 +89,7 @@ func DeserializeModuleMethodArgs(argsBuf []byte) *ArgsModuleMethod { } } reader.Context().Pop() - case "map": + case "m_map": reader.Context().Push(field, "map[string]int32", "type found, reading property") if reader.IsNil() { _map = nil @@ -191,14 +191,14 @@ func DeserializeModuleMethodArgs(argsBuf []byte) *ArgsModuleMethod { panic(reader.Context().PrintWithContext("Missing required property: 'mapOfArrOfObj: Map'")) } - return &ArgsModuleMethod{ + return &MethodArgsModuleMethod{ Str: _str, OptStr: _optStr, En: _en, OptEnum: _optEnum, EnumArray: _enumArray, OptEnumArray: _optEnumArray, - Map: _map, + M_map: _map, MapOfArr: _mapOfArr, MapOfObj: _mapOfObj, MapOfArrOfObj: _mapOfArrOfObj, @@ -221,7 +221,7 @@ func WriteModuleMethodResult(writer msgpack.Write, value int32) { writer.Context().Pop() } -func DeserializeObjectMethodArgs(argsBuf []byte) *ArgsObjectMethod { +func DeserializeObjectMethodArgs(argsBuf []byte) *MethodArgsObjectMethod { ctx := msgpack.NewContext("Deserializing module-type: ObjectMethod") reader := msgpack.NewReadDecoder(ctx, argsBuf) @@ -291,7 +291,7 @@ func DeserializeObjectMethodArgs(argsBuf []byte) *ArgsObjectMethod { panic(reader.Context().PrintWithContext("Missing required property: 'objectArray: [AnotherType]'")) } - return &ArgsObjectMethod{ + return &MethodArgsObjectMethod{ Object: _object, OptObject: _optObject, ObjectArray: _objectArray, @@ -315,7 +315,7 @@ func WriteObjectMethodResult(writer msgpack.Write, value *AnotherType) { writer.Context().Pop() } -func DeserializeOptionalEnvMethodArgs(argsBuf []byte) *ArgsOptionalEnvMethod { +func DeserializeOptionalEnvMethodArgs(argsBuf []byte) *MethodArgsOptionalEnvMethod { ctx := msgpack.NewContext("Deserializing module-type: OptionalEnvMethod") reader := msgpack.NewReadDecoder(ctx, argsBuf) @@ -385,7 +385,7 @@ func DeserializeOptionalEnvMethodArgs(argsBuf []byte) *ArgsOptionalEnvMethod { panic(reader.Context().PrintWithContext("Missing required property: 'objectArray: [AnotherType]'")) } - return &ArgsOptionalEnvMethod{ + return &MethodArgsOptionalEnvMethod{ Object: _object, OptObject: _optObject, ObjectArray: _objectArray, @@ -409,7 +409,7 @@ func WriteOptionalEnvMethodResult(writer msgpack.Write, value *AnotherType) { writer.Context().Pop() } -func DeserializeIfArgs(argsBuf []byte) *ArgsIf { +func DeserializeIfArgs(argsBuf []byte) *MethodArgsIf { ctx := msgpack.NewContext("Deserializing module-type: If") reader := msgpack.NewReadDecoder(ctx, argsBuf) @@ -437,7 +437,7 @@ func DeserializeIfArgs(argsBuf []byte) *ArgsIf { panic(reader.Context().PrintWithContext("Missing required property: 'if: else'")) } - return &ArgsIf{ + return &MethodArgsIf{ M_if: _if, } } diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/module/module_wrapped.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/module/module_wrapped.go similarity index 92% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/module/module_wrapped.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/module/module_wrapped.go index 1fa22f7056..286449f746 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm.go/module/module_wrapped.go +++ b/packages/test-cases/cases/bind/sanity/output/wasm-go/module/module_wrapped.go @@ -26,7 +26,7 @@ func ObjectMethodWrapped(argsBuf []byte, envSize uint32) []byte { args := DeserializeObjectMethodArgs(argsBuf) - result := methods.ObjectMethod(args, env) + result := methods.ObjectMethod(args,env) return SerializeObjectMethodResult(result) } @@ -39,7 +39,7 @@ func OptionalEnvMethodWrapped(argsBuf []byte, envSize uint32) []byte { args := DeserializeOptionalEnvMethodArgs(argsBuf) - result := methods.OptionalEnvMethod(args, env) + result := methods.OptionalEnvMethod(args,env) return SerializeOptionalEnvMethodResult(result) } diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/types/enum_custom_enum.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/types/enum_custom_enum.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/types/enum_custom_enum.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/types/enum_custom_enum.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/types/enumwhile.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/types/enumwhile.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/types/enumwhile.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/types/enumwhile.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/types/module_args.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/types/module_args.go similarity index 75% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/types/module_args.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/types/module_args.go index 57c177ee8f..2ec6424513 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm.go/types/module_args.go +++ b/packages/test-cases/cases/bind/sanity/output/wasm-go/types/module_args.go @@ -1,32 +1,32 @@ package types -type ArgsModuleMethod struct { +type MethodArgsModuleMethod struct { Str string OptStr *string En CustomEnum OptEnum *CustomEnum EnumArray []CustomEnum OptEnumArray []*CustomEnum - Map map[string]int32 + M_map map[string]int32 MapOfArr map[string][]int32 MapOfObj map[string]AnotherType MapOfArrOfObj map[string][]AnotherType } -type ArgsObjectMethod struct { +type MethodArgsObjectMethod struct { Object AnotherType OptObject *AnotherType ObjectArray []AnotherType OptObjectArray []*AnotherType } -type ArgsOptionalEnvMethod struct { +type MethodArgsOptionalEnvMethod struct { Object AnotherType OptObject *AnotherType ObjectArray []AnotherType OptObjectArray []*AnotherType } -type ArgsIf struct { +type MethodArgsIf struct { M_if Else } diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_another_type.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_another_type.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_another_type.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_another_type.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_another_type_serialization.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_another_type_serialization.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_another_type_serialization.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_another_type_serialization.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_custom_map_value.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_custom_map_value.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_custom_map_value.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_custom_map_value.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_custom_map_value_serialization.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_custom_map_value_serialization.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_custom_map_value_serialization.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_custom_map_value_serialization.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_custom_type.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_custom_type.go similarity index 98% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_custom_type.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_custom_type.go index 129eedcb94..ae268082e8 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_custom_type.go +++ b/packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_custom_type.go @@ -44,7 +44,7 @@ type CustomType struct { OptEnum *CustomEnum EnumArray []CustomEnum OptEnumArray []*CustomEnum - Map map[string]int32 + M_map map[string]int32 MapOfArr map[string][]int32 MapOfObj map[string]AnotherType MapOfArrOfObj map[string][]AnotherType diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_custom_type_serialization.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_custom_type_serialization.go similarity index 99% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_custom_type_serialization.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_custom_type_serialization.go index 743b468443..67a836ae91 100644 --- a/packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_custom_type_serialization.go +++ b/packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_custom_type_serialization.go @@ -474,17 +474,17 @@ func writeCustomType(writer msgpack.Write, value *CustomType) { } } writer.Context().Pop() - writer.Context().Push("Map", "map[string]int32", "writing property") - writer.WriteString("Map") - if value.Map == nil { + writer.Context().Push("M_map", "map[string]int32", "writing property") + writer.WriteString("M_map") + if value.M_map == nil { writer.WriteNil() - } else if len(value.Map) == 0 { + } else if len(value.M_map) == 0 { writer.WriteNil() } else { - for i0 := range value.Map { + for i0 := range value.M_map { writer.WriteString(i0) { - v := value.Map[i0] + v := value.M_map[i0] writer.WriteI32(v) } } @@ -1025,7 +1025,7 @@ func readCustomType(reader msgpack.Read) *CustomType { } } reader.Context().Pop() - case "Map": + case "M_map": reader.Context().Push(field, "map[string]int32", "type found, reading property") if reader.IsNil() { _map = nil @@ -1240,7 +1240,7 @@ func readCustomType(reader msgpack.Read) *CustomType { OptEnum: _optEnum, EnumArray: _enumArray, OptEnumArray: _optEnumArray, - Map: _map, + M_map: _map, MapOfArr: _mapOfArr, MapOfObj: _mapOfObj, MapOfArrOfObj: _mapOfArrOfObj, diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_env.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_env.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_env.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_env.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_env_serialization.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_env_serialization.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/types/object_env_serialization.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/types/object_env_serialization.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/types/objectelse.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/types/objectelse.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/types/objectelse.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/types/objectelse.go diff --git a/packages/test-cases/cases/bind/sanity/output/wasm.go/types/objectelse_serialization.go b/packages/test-cases/cases/bind/sanity/output/wasm-go/types/objectelse_serialization.go similarity index 100% rename from packages/test-cases/cases/bind/sanity/output/wasm.go/types/objectelse_serialization.go rename to packages/test-cases/cases/bind/sanity/output/wasm-go/types/objectelse_serialization.go