diff --git a/plugins/cmd/ndpgen/internal/templates/client.go.tmpl b/plugins/cmd/ndpgen/internal/templates/client.go.tmpl index dc199b64a..cbc79dcc1 100644 --- a/plugins/cmd/ndpgen/internal/templates/client.go.tmpl +++ b/plugins/cmd/ndpgen/internal/templates/client.go.tmpl @@ -67,11 +67,7 @@ type {{responseType .}} struct { {{- if .Doc}} {{formatDoc .Doc}} {{- end}} -{{- if .IsErrorOnly}} -func {{$.Service.Name}}{{.Name}}({{range $i, $p := .Params}}{{if $i}}, {{end}}{{$p.Name}} {{$p.Type}}{{end}}) error { -{{- else}} -func {{$.Service.Name}}{{.Name}}({{range $i, $p := .Params}}{{if $i}}, {{end}}{{$p.Name}} {{$p.Type}}{{end}}) (*{{responseType .}}, error) { -{{- end}} +func {{$.Service.Name}}{{.Name}}({{range $i, $p := .Params}}{{if $i}}, {{end}}{{$p.Name}} {{$p.Type}}{{end}}) {{.ReturnSignature}} { {{- if .HasParams}} // Marshal request to JSON req := {{requestType .}}{ @@ -81,7 +77,7 @@ func {{$.Service.Name}}{{.Name}}({{range $i, $p := .Params}}{{if $i}}, {{end}}{{ } reqBytes, err := json.Marshal(req) if err != nil { - return {{if not .IsErrorOnly}}nil, {{end}}err + return {{if .HasReturns}}{{.ZeroValues}}{{end}}{{if and .HasReturns .HasError}}, {{end}}{{if .HasError}}err{{end}} } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() @@ -115,15 +111,17 @@ func {{$.Service.Name}}{{.Name}}({{range $i, $p := .Params}}{{if $i}}, {{end}}{{ // Parse the response var response {{responseType .}} if err := json.Unmarshal(responseBytes, &response); err != nil { - return nil, err + return {{if .HasReturns}}{{.ZeroValues}}{{end}}{{if and .HasReturns .HasError}}, {{end}}{{if .HasError}}err{{end}} } +{{- if .HasError}} // Convert Error field to Go error if response.Error != "" { - return nil, errors.New(response.Error) + return {{if .HasReturns}}{{.ZeroValues}}, {{end}}errors.New(response.Error) } +{{- end}} - return &response, nil + return {{range $i, $r := .Returns}}{{if $i}}, {{end}}response.{{title $r.Name}}{{end}}{{if and .HasReturns .HasError}}, {{end}}{{if .HasError}}nil{{end}} {{- end}} } {{- end}} diff --git a/plugins/cmd/ndpgen/internal/templates/client_stub.go.tmpl b/plugins/cmd/ndpgen/internal/templates/client_stub.go.tmpl index 81389dc11..038c94116 100644 --- a/plugins/cmd/ndpgen/internal/templates/client_stub.go.tmpl +++ b/plugins/cmd/ndpgen/internal/templates/client_stub.go.tmpl @@ -52,13 +52,7 @@ type {{responseType .}} struct { {{- if .Doc}} {{formatDoc .Doc}} {{- end}} -{{- if .IsErrorOnly}} -func {{$.Service.Name}}{{.Name}}({{range $i, $p := .Params}}{{if $i}}, {{end}}{{$p.Name}} {{$p.Type}}{{end}}) error { - panic("{{$.Package}}: {{$.Service.Name}}{{.Name}} is only available in WASM plugins") -} -{{- else}} -func {{$.Service.Name}}{{.Name}}({{range $i, $p := .Params}}{{if $i}}, {{end}}{{$p.Name}} {{$p.Type}}{{end}}) (*{{responseType .}}, error) { +func {{$.Service.Name}}{{.Name}}({{range $i, $p := .Params}}{{if $i}}, {{end}}{{$p.Name}} {{$p.Type}}{{end}}) {{.ReturnSignature}} { panic("{{$.Package}}: {{$.Service.Name}}{{.Name}} is only available in WASM plugins") } {{- end}} -{{- end}} diff --git a/plugins/cmd/ndpgen/internal/types.go b/plugins/cmd/ndpgen/internal/types.go index cc10d3080..b312551a9 100644 --- a/plugins/cmd/ndpgen/internal/types.go +++ b/plugins/cmd/ndpgen/internal/types.go @@ -206,6 +206,76 @@ func (m Method) IsErrorOnly() bool { return m.HasError && !m.HasReturns() } +// IsSingleReturn returns true if the method has exactly one return value (excluding error). +func (m Method) IsSingleReturn() bool { + return len(m.Returns) == 1 +} + +// IsMultiReturn returns true if the method has multiple return values (excluding error). +func (m Method) IsMultiReturn() bool { + return len(m.Returns) > 1 +} + +// ReturnSignature returns the Go return type signature for the wrapper function. +// For error-only: "error" +// For single return with error: "(Type, error)" +// For single return no error: "Type" +// For multi return: "(Type1, Type2, ..., error)" +func (m Method) ReturnSignature() string { + if m.IsErrorOnly() { + return "error" + } + var parts []string + for _, r := range m.Returns { + parts = append(parts, r.Type) + } + if m.HasError { + parts = append(parts, "error") + } + // Single return without error doesn't need parentheses + if len(parts) == 1 { + return parts[0] + } + return "(" + strings.Join(parts, ", ") + ")" +} + +// ZeroValues returns the zero value expressions for all return types (excluding error). +// Used for error return statements like "return "", false, err". +func (m Method) ZeroValues() string { + var zeros []string + for _, r := range m.Returns { + zeros = append(zeros, zeroValue(r.Type)) + } + return strings.Join(zeros, ", ") +} + +// zeroValue returns the zero value for a Go type. +func zeroValue(typ string) string { + switch { + case typ == "string": + return `""` + case typ == "bool": + return "false" + case typ == "int", typ == "int8", typ == "int16", typ == "int32", typ == "int64", + typ == "uint", typ == "uint8", typ == "uint16", typ == "uint32", typ == "uint64", + typ == "float32", typ == "float64": + return "0" + case typ == "[]byte": + return "nil" + case strings.HasPrefix(typ, "[]"): + return "nil" + case strings.HasPrefix(typ, "map["): + return "nil" + case strings.HasPrefix(typ, "*"): + return "nil" + case typ == "any", typ == "interface{}": + return "nil" + default: + // For custom struct types, return empty struct + return typ + "{}" + } +} + // Param represents a method parameter or return value. type Param struct { Name string // Parameter name diff --git a/plugins/cmd/ndpgen/testdata/codec_client_expected.go.txt b/plugins/cmd/ndpgen/testdata/codec_client_expected.go.txt index 04a349ad4..950781767 100644 --- a/plugins/cmd/ndpgen/testdata/codec_client_expected.go.txt +++ b/plugins/cmd/ndpgen/testdata/codec_client_expected.go.txt @@ -31,7 +31,7 @@ type CodecEncodeResponse struct { } // CodecEncode calls the codec_encode host function. -func CodecEncode(data []byte) (*CodecEncodeResponse, error) { +func CodecEncode(data []byte) ([]byte, error) { // Marshal request to JSON req := CodecEncodeRequest{ Data: data, @@ -61,5 +61,5 @@ func CodecEncode(data []byte) (*CodecEncodeResponse, error) { return nil, errors.New(response.Error) } - return &response, nil + return response.Result, nil } diff --git a/plugins/cmd/ndpgen/testdata/counter_client_expected.go.txt b/plugins/cmd/ndpgen/testdata/counter_client_expected.go.txt index 73ca80085..caaf4d09e 100644 --- a/plugins/cmd/ndpgen/testdata/counter_client_expected.go.txt +++ b/plugins/cmd/ndpgen/testdata/counter_client_expected.go.txt @@ -31,14 +31,14 @@ type CounterCountResponse struct { } // CounterCount calls the counter_count host function. -func CounterCount(name string) (*CounterCountResponse, error) { +func CounterCount(name string) int32 { // Marshal request to JSON req := CounterCountRequest{ Name: name, } reqBytes, err := json.Marshal(req) if err != nil { - return nil, err + return 0 } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() @@ -53,13 +53,8 @@ func CounterCount(name string) (*CounterCountResponse, error) { // Parse the response var response CounterCountResponse if err := json.Unmarshal(responseBytes, &response); err != nil { - return nil, err + return 0 } - // Convert Error field to Go error - if response.Error != "" { - return nil, errors.New(response.Error) - } - - return &response, nil + return response.Value } diff --git a/plugins/cmd/ndpgen/testdata/echo_client_expected.go.txt b/plugins/cmd/ndpgen/testdata/echo_client_expected.go.txt index 4858488bf..9507bf5f8 100644 --- a/plugins/cmd/ndpgen/testdata/echo_client_expected.go.txt +++ b/plugins/cmd/ndpgen/testdata/echo_client_expected.go.txt @@ -31,14 +31,14 @@ type EchoEchoResponse struct { } // EchoEcho calls the echo_echo host function. -func EchoEcho(message string) (*EchoEchoResponse, error) { +func EchoEcho(message string) (string, error) { // Marshal request to JSON req := EchoEchoRequest{ Message: message, } reqBytes, err := json.Marshal(req) if err != nil { - return nil, err + return "", err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() @@ -53,13 +53,13 @@ func EchoEcho(message string) (*EchoEchoResponse, error) { // Parse the response var response EchoEchoResponse if err := json.Unmarshal(responseBytes, &response); err != nil { - return nil, err + return "", err } // Convert Error field to Go error if response.Error != "" { - return nil, errors.New(response.Error) + return "", errors.New(response.Error) } - return &response, nil + return response.Reply, nil } diff --git a/plugins/cmd/ndpgen/testdata/list_client_expected.go.txt b/plugins/cmd/ndpgen/testdata/list_client_expected.go.txt index b0f76a013..c8257aeb4 100644 --- a/plugins/cmd/ndpgen/testdata/list_client_expected.go.txt +++ b/plugins/cmd/ndpgen/testdata/list_client_expected.go.txt @@ -37,7 +37,7 @@ type ListItemsResponse struct { } // ListItems calls the list_items host function. -func ListItems(name string, filter Filter) (*ListItemsResponse, error) { +func ListItems(name string, filter Filter) (int32, error) { // Marshal request to JSON req := ListItemsRequest{ Name: name, @@ -45,7 +45,7 @@ func ListItems(name string, filter Filter) (*ListItemsResponse, error) { } reqBytes, err := json.Marshal(req) if err != nil { - return nil, err + return 0, err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() @@ -60,13 +60,13 @@ func ListItems(name string, filter Filter) (*ListItemsResponse, error) { // Parse the response var response ListItemsResponse if err := json.Unmarshal(responseBytes, &response); err != nil { - return nil, err + return 0, err } // Convert Error field to Go error if response.Error != "" { - return nil, errors.New(response.Error) + return 0, errors.New(response.Error) } - return &response, nil + return response.Count, nil } diff --git a/plugins/cmd/ndpgen/testdata/math_client_expected.go.txt b/plugins/cmd/ndpgen/testdata/math_client_expected.go.txt index 455cc8f41..0c6ab276f 100644 --- a/plugins/cmd/ndpgen/testdata/math_client_expected.go.txt +++ b/plugins/cmd/ndpgen/testdata/math_client_expected.go.txt @@ -32,7 +32,7 @@ type MathAddResponse struct { } // MathAdd calls the math_add host function. -func MathAdd(a int32, b int32) (*MathAddResponse, error) { +func MathAdd(a int32, b int32) (int32, error) { // Marshal request to JSON req := MathAddRequest{ A: a, @@ -40,7 +40,7 @@ func MathAdd(a int32, b int32) (*MathAddResponse, error) { } reqBytes, err := json.Marshal(req) if err != nil { - return nil, err + return 0, err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() @@ -55,13 +55,13 @@ func MathAdd(a int32, b int32) (*MathAddResponse, error) { // Parse the response var response MathAddResponse if err := json.Unmarshal(responseBytes, &response); err != nil { - return nil, err + return 0, err } // Convert Error field to Go error if response.Error != "" { - return nil, errors.New(response.Error) + return 0, errors.New(response.Error) } - return &response, nil + return response.Result, nil } diff --git a/plugins/cmd/ndpgen/testdata/meta_client_expected.go.txt b/plugins/cmd/ndpgen/testdata/meta_client_expected.go.txt index d855fed73..bcec4b701 100644 --- a/plugins/cmd/ndpgen/testdata/meta_client_expected.go.txt +++ b/plugins/cmd/ndpgen/testdata/meta_client_expected.go.txt @@ -41,7 +41,7 @@ type MetaSetRequest struct { } // MetaGet calls the meta_get host function. -func MetaGet(key string) (*MetaGetResponse, error) { +func MetaGet(key string) (any, error) { // Marshal request to JSON req := MetaGetRequest{ Key: key, @@ -71,7 +71,7 @@ func MetaGet(key string) (*MetaGetResponse, error) { return nil, errors.New(response.Error) } - return &response, nil + return response.Value, nil } // MetaSet calls the meta_set host function. diff --git a/plugins/cmd/ndpgen/testdata/search_client_expected.go.txt b/plugins/cmd/ndpgen/testdata/search_client_expected.go.txt index c4d707bef..13ffba439 100644 --- a/plugins/cmd/ndpgen/testdata/search_client_expected.go.txt +++ b/plugins/cmd/ndpgen/testdata/search_client_expected.go.txt @@ -37,14 +37,14 @@ type SearchFindResponse struct { } // SearchFind calls the search_find host function. -func SearchFind(query string) (*SearchFindResponse, error) { +func SearchFind(query string) ([]Result, int32, error) { // Marshal request to JSON req := SearchFindRequest{ Query: query, } reqBytes, err := json.Marshal(req) if err != nil { - return nil, err + return nil, 0, err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() @@ -59,13 +59,13 @@ func SearchFind(query string) (*SearchFindResponse, error) { // Parse the response var response SearchFindResponse if err := json.Unmarshal(responseBytes, &response); err != nil { - return nil, err + return nil, 0, err } // Convert Error field to Go error if response.Error != "" { - return nil, errors.New(response.Error) + return nil, 0, errors.New(response.Error) } - return &response, nil + return response.Results, response.Total, nil } diff --git a/plugins/cmd/ndpgen/testdata/store_client_expected.go.txt b/plugins/cmd/ndpgen/testdata/store_client_expected.go.txt index eec5156d6..790eee7bf 100644 --- a/plugins/cmd/ndpgen/testdata/store_client_expected.go.txt +++ b/plugins/cmd/ndpgen/testdata/store_client_expected.go.txt @@ -37,14 +37,14 @@ type StoreSaveResponse struct { } // StoreSave calls the store_save host function. -func StoreSave(item Item) (*StoreSaveResponse, error) { +func StoreSave(item Item) (string, error) { // Marshal request to JSON req := StoreSaveRequest{ Item: item, } reqBytes, err := json.Marshal(req) if err != nil { - return nil, err + return "", err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() @@ -59,13 +59,13 @@ func StoreSave(item Item) (*StoreSaveResponse, error) { // Parse the response var response StoreSaveResponse if err := json.Unmarshal(responseBytes, &response); err != nil { - return nil, err + return "", err } // Convert Error field to Go error if response.Error != "" { - return nil, errors.New(response.Error) + return "", errors.New(response.Error) } - return &response, nil + return response.Id, nil } diff --git a/plugins/cmd/ndpgen/testdata/users_client_expected.go.txt b/plugins/cmd/ndpgen/testdata/users_client_expected.go.txt index 43769d890..9dad6d00c 100644 --- a/plugins/cmd/ndpgen/testdata/users_client_expected.go.txt +++ b/plugins/cmd/ndpgen/testdata/users_client_expected.go.txt @@ -38,7 +38,7 @@ type UsersGetResponse struct { } // UsersGet calls the users_get host function. -func UsersGet(id *string, filter *User) (*UsersGetResponse, error) { +func UsersGet(id *string, filter *User) (*User, error) { // Marshal request to JSON req := UsersGetRequest{ Id: id, @@ -69,5 +69,5 @@ func UsersGet(id *string, filter *User) (*UsersGetResponse, error) { return nil, errors.New(response.Error) } - return &response, nil + return response.Result, nil } diff --git a/plugins/examples/crypto-ticker/main.go b/plugins/examples/crypto-ticker/main.go index 08eb1f713..b197430f2 100755 --- a/plugins/examples/crypto-ticker/main.go +++ b/plugins/examples/crypto-ticker/main.go @@ -109,11 +109,11 @@ func parseTickerSymbols(tickerConfig string) []string { // connectAndSubscribe connects to Coinbase WebSocket and subscribes to tickers func connectAndSubscribe(tickers []string) error { // Connect to WebSocket using host function - resp, err := host.WebSocketConnect(coinbaseWSEndpoint, nil, connectionID) + newConnID, err := host.WebSocketConnect(coinbaseWSEndpoint, nil, connectionID) if err != nil { return fmt.Errorf("WebSocket connection error: %w", err) } - pdk.Log(pdk.LogInfo, fmt.Sprintf("Connected to Coinbase WebSocket API (connection: %s)", resp.NewConnectionID)) + pdk.Log(pdk.LogInfo, fmt.Sprintf("Connected to Coinbase WebSocket API (connection: %s)", newConnID)) // Subscribe to ticker channel subscription := CoinbaseSubscription{ diff --git a/plugins/examples/discord-rich-presence/main.go b/plugins/examples/discord-rich-presence/main.go index 3a69443ba..f702f708f 100644 --- a/plugins/examples/discord-rich-presence/main.go +++ b/plugins/examples/discord-rich-presence/main.go @@ -75,17 +75,17 @@ func getConfig() (clientID string, users map[string]string, err error) { // getImageURL retrieves the track artwork URL. func getImageURL(trackID string) string { - resp, err := host.ArtworkGetTrackUrl(trackID, 300) + artworkURL, err := host.ArtworkGetTrackUrl(trackID, 300) if err != nil { pdk.Log(pdk.LogWarn, fmt.Sprintf("Failed to get artwork URL: %v", err)) return "" } // Don't use localhost URLs - if strings.HasPrefix(resp.Url, "http://localhost") { + if strings.HasPrefix(artworkURL, "http://localhost") { return "" } - return resp.Url + return artworkURL } // ============================================================================ diff --git a/plugins/examples/discord-rich-presence/rpc.go b/plugins/examples/discord-rich-presence/rpc.go index 9db371a03..20a24e165 100644 --- a/plugins/examples/discord-rich-presence/rpc.go +++ b/plugins/examples/discord-rich-presence/rpc.go @@ -89,10 +89,10 @@ func processImage(imageURL, clientID, token string, isDefaultImage bool) (string // Check cache first cacheKey := fmt.Sprintf("discord.image.%x", imageURL) - cacheResp, err := host.CacheGetString(cacheKey) - if err == nil && cacheResp.Exists { + cachedValue, exists, err := host.CacheGetString(cacheKey) + if err == nil && exists { pdk.Log(pdk.LogDebug, fmt.Sprintf("Cache hit for image URL: %s", imageURL)) - return cacheResp.Value, nil + return cachedValue, nil } // Process via Discord API @@ -208,13 +208,13 @@ func getDiscordGateway() (string, error) { // sendHeartbeat sends a heartbeat to Discord. func sendHeartbeat(username string) error { - cacheResp, err := host.CacheGetInt(fmt.Sprintf("discord.seq.%s", username)) + seqNum, _, err := host.CacheGetInt(fmt.Sprintf("discord.seq.%s", username)) if err != nil { return fmt.Errorf("failed to get sequence number: %w", err) } - pdk.Log(pdk.LogDebug, fmt.Sprintf("Sending heartbeat for user %s: %d", username, cacheResp.Value)) - return sendMessage(username, heartbeatOpCode, cacheResp.Value) + pdk.Log(pdk.LogDebug, fmt.Sprintf("Sending heartbeat for user %s: %d", username, seqNum)) + return sendMessage(username, heartbeatOpCode, seqNum) } // cleanupFailedConnection cleans up a failed Discord connection. @@ -284,11 +284,11 @@ func connect(username, token string) error { // Schedule heartbeats for this user/connection cronExpr := fmt.Sprintf("@every %ds", heartbeatInterval) - schedResp, err := host.SchedulerScheduleRecurring(cronExpr, payloadHeartbeat, username) + scheduleID, err := host.SchedulerScheduleRecurring(cronExpr, payloadHeartbeat, username) if err != nil { return fmt.Errorf("failed to schedule heartbeat: %w", err) } - pdk.Log(pdk.LogInfo, fmt.Sprintf("Scheduled heartbeat for user %s with ID %s", username, schedResp.NewScheduleID)) + pdk.Log(pdk.LogInfo, fmt.Sprintf("Scheduled heartbeat for user %s with ID %s", username, scheduleID)) pdk.Log(pdk.LogInfo, fmt.Sprintf("Successfully authenticated user %s", username)) return nil diff --git a/plugins/host_cache_test.go b/plugins/host_cache_test.go index 40ec24e2c..298aa7e97 100644 --- a/plugins/host_cache_test.go +++ b/plugins/host_cache_test.go @@ -519,6 +519,31 @@ var _ = Describe("CacheService Integration", Ordered, func() { Expect(output.BytesVal).To(Equal(testBytes)) }) + It("should handle binary data with null bytes through WASM", func() { + ctx := GinkgoT().Context() + + // Binary data with null bytes, high bytes, and other edge cases + binaryData := []byte{0x00, 0x01, 0x02, 0xFF, 0xFE, 0x00, 0x80, 0x7F} + + // Set binary bytes + _, err := callTestCache(ctx, testCacheInput{ + Operation: "set_bytes", + Key: "binary_test", + BytesVal: binaryData, + TTLSeconds: 300, + }) + Expect(err).ToNot(HaveOccurred()) + + // Get binary bytes and verify exact match + output, err := callTestCache(ctx, testCacheInput{ + Operation: "get_bytes", + Key: "binary_test", + }) + Expect(err).ToNot(HaveOccurred()) + Expect(output.Exists).To(BeTrue()) + Expect(output.BytesVal).To(Equal(binaryData)) + }) + It("should check if key exists", func() { ctx := GinkgoT().Context() diff --git a/plugins/host_kvstore_test.go b/plugins/host_kvstore_test.go index 1c863ebea..f8eae0395 100644 --- a/plugins/host_kvstore_test.go +++ b/plugins/host_kvstore_test.go @@ -570,6 +570,30 @@ var _ = Describe("KVStoreService Integration", Ordered, func() { Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("storage limit exceeded")) }) + + It("should handle binary data with null bytes through WASM", func() { + ctx := GinkgoT().Context() + + // Binary data with null bytes, high bytes, and other edge cases + binaryData := []byte{0x00, 0x01, 0x02, 0xFF, 0xFE, 0x00, 0x80, 0x7F} + + // Set binary value + _, err := callTestKVStore(ctx, testKVStoreInput{ + Operation: "set", + Key: "binary_test", + Value: binaryData, + }) + Expect(err).ToNot(HaveOccurred()) + + // Get binary value and verify exact match + output, err := callTestKVStore(ctx, testKVStoreInput{ + Operation: "get", + Key: "binary_test", + }) + Expect(err).ToNot(HaveOccurred()) + Expect(output.Exists).To(BeTrue()) + Expect(output.Value).To(Equal(binaryData)) + }) }) Describe("Database Isolation", func() { diff --git a/plugins/pdk/go/host/nd_host_artwork.go b/plugins/pdk/go/host/nd_host_artwork.go index e2db87ff4..2cf06346c 100644 --- a/plugins/pdk/go/host/nd_host_artwork.go +++ b/plugins/pdk/go/host/nd_host_artwork.go @@ -90,7 +90,7 @@ type ArtworkGetPlaylistUrlResponse struct { // - size: Desired image size in pixels (0 for original size) // // Returns the public URL for the artwork, or an error if generation fails. -func ArtworkGetArtistUrl(id string, size int32) (*ArtworkGetArtistUrlResponse, error) { +func ArtworkGetArtistUrl(id string, size int32) (string, error) { // Marshal request to JSON req := ArtworkGetArtistUrlRequest{ Id: id, @@ -98,7 +98,7 @@ func ArtworkGetArtistUrl(id string, size int32) (*ArtworkGetArtistUrlResponse, e } reqBytes, err := json.Marshal(req) if err != nil { - return nil, err + return "", err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() @@ -113,15 +113,15 @@ func ArtworkGetArtistUrl(id string, size int32) (*ArtworkGetArtistUrlResponse, e // Parse the response var response ArtworkGetArtistUrlResponse if err := json.Unmarshal(responseBytes, &response); err != nil { - return nil, err + return "", err } // Convert Error field to Go error if response.Error != "" { - return nil, errors.New(response.Error) + return "", errors.New(response.Error) } - return &response, nil + return response.Url, nil } // ArtworkGetAlbumUrl calls the artwork_getalbumurl host function. @@ -132,7 +132,7 @@ func ArtworkGetArtistUrl(id string, size int32) (*ArtworkGetArtistUrlResponse, e // - size: Desired image size in pixels (0 for original size) // // Returns the public URL for the artwork, or an error if generation fails. -func ArtworkGetAlbumUrl(id string, size int32) (*ArtworkGetAlbumUrlResponse, error) { +func ArtworkGetAlbumUrl(id string, size int32) (string, error) { // Marshal request to JSON req := ArtworkGetAlbumUrlRequest{ Id: id, @@ -140,7 +140,7 @@ func ArtworkGetAlbumUrl(id string, size int32) (*ArtworkGetAlbumUrlResponse, err } reqBytes, err := json.Marshal(req) if err != nil { - return nil, err + return "", err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() @@ -155,15 +155,15 @@ func ArtworkGetAlbumUrl(id string, size int32) (*ArtworkGetAlbumUrlResponse, err // Parse the response var response ArtworkGetAlbumUrlResponse if err := json.Unmarshal(responseBytes, &response); err != nil { - return nil, err + return "", err } // Convert Error field to Go error if response.Error != "" { - return nil, errors.New(response.Error) + return "", errors.New(response.Error) } - return &response, nil + return response.Url, nil } // ArtworkGetTrackUrl calls the artwork_gettrackurl host function. @@ -174,7 +174,7 @@ func ArtworkGetAlbumUrl(id string, size int32) (*ArtworkGetAlbumUrlResponse, err // - size: Desired image size in pixels (0 for original size) // // Returns the public URL for the artwork, or an error if generation fails. -func ArtworkGetTrackUrl(id string, size int32) (*ArtworkGetTrackUrlResponse, error) { +func ArtworkGetTrackUrl(id string, size int32) (string, error) { // Marshal request to JSON req := ArtworkGetTrackUrlRequest{ Id: id, @@ -182,7 +182,7 @@ func ArtworkGetTrackUrl(id string, size int32) (*ArtworkGetTrackUrlResponse, err } reqBytes, err := json.Marshal(req) if err != nil { - return nil, err + return "", err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() @@ -197,15 +197,15 @@ func ArtworkGetTrackUrl(id string, size int32) (*ArtworkGetTrackUrlResponse, err // Parse the response var response ArtworkGetTrackUrlResponse if err := json.Unmarshal(responseBytes, &response); err != nil { - return nil, err + return "", err } // Convert Error field to Go error if response.Error != "" { - return nil, errors.New(response.Error) + return "", errors.New(response.Error) } - return &response, nil + return response.Url, nil } // ArtworkGetPlaylistUrl calls the artwork_getplaylisturl host function. @@ -216,7 +216,7 @@ func ArtworkGetTrackUrl(id string, size int32) (*ArtworkGetTrackUrlResponse, err // - size: Desired image size in pixels (0 for original size) // // Returns the public URL for the artwork, or an error if generation fails. -func ArtworkGetPlaylistUrl(id string, size int32) (*ArtworkGetPlaylistUrlResponse, error) { +func ArtworkGetPlaylistUrl(id string, size int32) (string, error) { // Marshal request to JSON req := ArtworkGetPlaylistUrlRequest{ Id: id, @@ -224,7 +224,7 @@ func ArtworkGetPlaylistUrl(id string, size int32) (*ArtworkGetPlaylistUrlRespons } reqBytes, err := json.Marshal(req) if err != nil { - return nil, err + return "", err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() @@ -239,13 +239,13 @@ func ArtworkGetPlaylistUrl(id string, size int32) (*ArtworkGetPlaylistUrlRespons // Parse the response var response ArtworkGetPlaylistUrlResponse if err := json.Unmarshal(responseBytes, &response); err != nil { - return nil, err + return "", err } // Convert Error field to Go error if response.Error != "" { - return nil, errors.New(response.Error) + return "", errors.New(response.Error) } - return &response, nil + return response.Url, nil } diff --git a/plugins/pdk/go/host/nd_host_artwork_stub.go b/plugins/pdk/go/host/nd_host_artwork_stub.go index 522f63259..956b05cce 100644 --- a/plugins/pdk/go/host/nd_host_artwork_stub.go +++ b/plugins/pdk/go/host/nd_host_artwork_stub.go @@ -64,7 +64,7 @@ type ArtworkGetPlaylistUrlResponse struct { // - size: Desired image size in pixels (0 for original size) // // Returns the public URL for the artwork, or an error if generation fails. -func ArtworkGetArtistUrl(id string, size int32) (*ArtworkGetArtistUrlResponse, error) { +func ArtworkGetArtistUrl(id string, size int32) (string, error) { panic("host: ArtworkGetArtistUrl is only available in WASM plugins") } @@ -76,7 +76,7 @@ func ArtworkGetArtistUrl(id string, size int32) (*ArtworkGetArtistUrlResponse, e // - size: Desired image size in pixels (0 for original size) // // Returns the public URL for the artwork, or an error if generation fails. -func ArtworkGetAlbumUrl(id string, size int32) (*ArtworkGetAlbumUrlResponse, error) { +func ArtworkGetAlbumUrl(id string, size int32) (string, error) { panic("host: ArtworkGetAlbumUrl is only available in WASM plugins") } @@ -88,7 +88,7 @@ func ArtworkGetAlbumUrl(id string, size int32) (*ArtworkGetAlbumUrlResponse, err // - size: Desired image size in pixels (0 for original size) // // Returns the public URL for the artwork, or an error if generation fails. -func ArtworkGetTrackUrl(id string, size int32) (*ArtworkGetTrackUrlResponse, error) { +func ArtworkGetTrackUrl(id string, size int32) (string, error) { panic("host: ArtworkGetTrackUrl is only available in WASM plugins") } @@ -100,6 +100,6 @@ func ArtworkGetTrackUrl(id string, size int32) (*ArtworkGetTrackUrlResponse, err // - size: Desired image size in pixels (0 for original size) // // Returns the public URL for the artwork, or an error if generation fails. -func ArtworkGetPlaylistUrl(id string, size int32) (*ArtworkGetPlaylistUrlResponse, error) { +func ArtworkGetPlaylistUrl(id string, size int32) (string, error) { panic("host: ArtworkGetPlaylistUrl is only available in WASM plugins") } diff --git a/plugins/pdk/go/host/nd_host_cache.go b/plugins/pdk/go/host/nd_host_cache.go index 1b1d93fc6..572eb49b9 100644 --- a/plugins/pdk/go/host/nd_host_cache.go +++ b/plugins/pdk/go/host/nd_host_cache.go @@ -207,14 +207,14 @@ func CacheSetString(key string, value string, ttlSeconds int64) error { // // Returns the value and whether the key exists. If the key doesn't exist // or the stored value is not a string, exists will be false. -func CacheGetString(key string) (*CacheGetStringResponse, error) { +func CacheGetString(key string) (string, bool, error) { // Marshal request to JSON req := CacheGetStringRequest{ Key: key, } reqBytes, err := json.Marshal(req) if err != nil { - return nil, err + return "", false, err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() @@ -229,15 +229,15 @@ func CacheGetString(key string) (*CacheGetStringResponse, error) { // Parse the response var response CacheGetStringResponse if err := json.Unmarshal(responseBytes, &response); err != nil { - return nil, err + return "", false, err } // Convert Error field to Go error if response.Error != "" { - return nil, errors.New(response.Error) + return "", false, errors.New(response.Error) } - return &response, nil + return response.Value, response.Exists, nil } // CacheSetInt calls the cache_setint host function. @@ -291,14 +291,14 @@ func CacheSetInt(key string, value int64, ttlSeconds int64) error { // // Returns the value and whether the key exists. If the key doesn't exist // or the stored value is not an integer, exists will be false. -func CacheGetInt(key string) (*CacheGetIntResponse, error) { +func CacheGetInt(key string) (int64, bool, error) { // Marshal request to JSON req := CacheGetIntRequest{ Key: key, } reqBytes, err := json.Marshal(req) if err != nil { - return nil, err + return 0, false, err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() @@ -313,15 +313,15 @@ func CacheGetInt(key string) (*CacheGetIntResponse, error) { // Parse the response var response CacheGetIntResponse if err := json.Unmarshal(responseBytes, &response); err != nil { - return nil, err + return 0, false, err } // Convert Error field to Go error if response.Error != "" { - return nil, errors.New(response.Error) + return 0, false, errors.New(response.Error) } - return &response, nil + return response.Value, response.Exists, nil } // CacheSetFloat calls the cache_setfloat host function. @@ -375,14 +375,14 @@ func CacheSetFloat(key string, value float64, ttlSeconds int64) error { // // Returns the value and whether the key exists. If the key doesn't exist // or the stored value is not a float, exists will be false. -func CacheGetFloat(key string) (*CacheGetFloatResponse, error) { +func CacheGetFloat(key string) (float64, bool, error) { // Marshal request to JSON req := CacheGetFloatRequest{ Key: key, } reqBytes, err := json.Marshal(req) if err != nil { - return nil, err + return 0, false, err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() @@ -397,15 +397,15 @@ func CacheGetFloat(key string) (*CacheGetFloatResponse, error) { // Parse the response var response CacheGetFloatResponse if err := json.Unmarshal(responseBytes, &response); err != nil { - return nil, err + return 0, false, err } // Convert Error field to Go error if response.Error != "" { - return nil, errors.New(response.Error) + return 0, false, errors.New(response.Error) } - return &response, nil + return response.Value, response.Exists, nil } // CacheSetBytes calls the cache_setbytes host function. @@ -459,14 +459,14 @@ func CacheSetBytes(key string, value []byte, ttlSeconds int64) error { // // Returns the value and whether the key exists. If the key doesn't exist // or the stored value is not a byte slice, exists will be false. -func CacheGetBytes(key string) (*CacheGetBytesResponse, error) { +func CacheGetBytes(key string) ([]byte, bool, error) { // Marshal request to JSON req := CacheGetBytesRequest{ Key: key, } reqBytes, err := json.Marshal(req) if err != nil { - return nil, err + return nil, false, err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() @@ -481,15 +481,15 @@ func CacheGetBytes(key string) (*CacheGetBytesResponse, error) { // Parse the response var response CacheGetBytesResponse if err := json.Unmarshal(responseBytes, &response); err != nil { - return nil, err + return nil, false, err } // Convert Error field to Go error if response.Error != "" { - return nil, errors.New(response.Error) + return nil, false, errors.New(response.Error) } - return &response, nil + return response.Value, response.Exists, nil } // CacheHas calls the cache_has host function. @@ -499,14 +499,14 @@ func CacheGetBytes(key string) (*CacheGetBytesResponse, error) { // - key: The cache key (will be namespaced with plugin ID) // // Returns true if the key exists and has not expired. -func CacheHas(key string) (*CacheHasResponse, error) { +func CacheHas(key string) (bool, error) { // Marshal request to JSON req := CacheHasRequest{ Key: key, } reqBytes, err := json.Marshal(req) if err != nil { - return nil, err + return false, err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() @@ -521,15 +521,15 @@ func CacheHas(key string) (*CacheHasResponse, error) { // Parse the response var response CacheHasResponse if err := json.Unmarshal(responseBytes, &response); err != nil { - return nil, err + return false, err } // Convert Error field to Go error if response.Error != "" { - return nil, errors.New(response.Error) + return false, errors.New(response.Error) } - return &response, nil + return response.Exists, nil } // CacheRemove calls the cache_remove host function. diff --git a/plugins/pdk/go/host/nd_host_cache_stub.go b/plugins/pdk/go/host/nd_host_cache_stub.go index 4d6b1eed1..d2430aa89 100644 --- a/plugins/pdk/go/host/nd_host_cache_stub.go +++ b/plugins/pdk/go/host/nd_host_cache_stub.go @@ -121,7 +121,7 @@ func CacheSetString(key string, value string, ttlSeconds int64) error { // // Returns the value and whether the key exists. If the key doesn't exist // or the stored value is not a string, exists will be false. -func CacheGetString(key string) (*CacheGetStringResponse, error) { +func CacheGetString(key string) (string, bool, error) { panic("host: CacheGetString is only available in WASM plugins") } @@ -146,7 +146,7 @@ func CacheSetInt(key string, value int64, ttlSeconds int64) error { // // Returns the value and whether the key exists. If the key doesn't exist // or the stored value is not an integer, exists will be false. -func CacheGetInt(key string) (*CacheGetIntResponse, error) { +func CacheGetInt(key string) (int64, bool, error) { panic("host: CacheGetInt is only available in WASM plugins") } @@ -171,7 +171,7 @@ func CacheSetFloat(key string, value float64, ttlSeconds int64) error { // // Returns the value and whether the key exists. If the key doesn't exist // or the stored value is not a float, exists will be false. -func CacheGetFloat(key string) (*CacheGetFloatResponse, error) { +func CacheGetFloat(key string) (float64, bool, error) { panic("host: CacheGetFloat is only available in WASM plugins") } @@ -196,7 +196,7 @@ func CacheSetBytes(key string, value []byte, ttlSeconds int64) error { // // Returns the value and whether the key exists. If the key doesn't exist // or the stored value is not a byte slice, exists will be false. -func CacheGetBytes(key string) (*CacheGetBytesResponse, error) { +func CacheGetBytes(key string) ([]byte, bool, error) { panic("host: CacheGetBytes is only available in WASM plugins") } @@ -207,7 +207,7 @@ func CacheGetBytes(key string) (*CacheGetBytesResponse, error) { // - key: The cache key (will be namespaced with plugin ID) // // Returns true if the key exists and has not expired. -func CacheHas(key string) (*CacheHasResponse, error) { +func CacheHas(key string) (bool, error) { panic("host: CacheHas is only available in WASM plugins") } diff --git a/plugins/pdk/go/host/nd_host_kvstore.go b/plugins/pdk/go/host/nd_host_kvstore.go index c482ffcc3..2e4c57eaf 100644 --- a/plugins/pdk/go/host/nd_host_kvstore.go +++ b/plugins/pdk/go/host/nd_host_kvstore.go @@ -143,14 +143,14 @@ func KVStoreSet(key string, value []byte) error { // - key: The storage key // // Returns the value and whether the key exists. -func KVStoreGet(key string) (*KVStoreGetResponse, error) { +func KVStoreGet(key string) ([]byte, bool, error) { // Marshal request to JSON req := KVStoreGetRequest{ Key: key, } reqBytes, err := json.Marshal(req) if err != nil { - return nil, err + return nil, false, err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() @@ -165,15 +165,15 @@ func KVStoreGet(key string) (*KVStoreGetResponse, error) { // Parse the response var response KVStoreGetResponse if err := json.Unmarshal(responseBytes, &response); err != nil { - return nil, err + return nil, false, err } // Convert Error field to Go error if response.Error != "" { - return nil, errors.New(response.Error) + return nil, false, errors.New(response.Error) } - return &response, nil + return response.Value, response.Exists, nil } // KVStoreDelete calls the kvstore_delete host function. @@ -222,14 +222,14 @@ func KVStoreDelete(key string) error { // - key: The storage key // // Returns true if the key exists. -func KVStoreHas(key string) (*KVStoreHasResponse, error) { +func KVStoreHas(key string) (bool, error) { // Marshal request to JSON req := KVStoreHasRequest{ Key: key, } reqBytes, err := json.Marshal(req) if err != nil { - return nil, err + return false, err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() @@ -244,15 +244,15 @@ func KVStoreHas(key string) (*KVStoreHasResponse, error) { // Parse the response var response KVStoreHasResponse if err := json.Unmarshal(responseBytes, &response); err != nil { - return nil, err + return false, err } // Convert Error field to Go error if response.Error != "" { - return nil, errors.New(response.Error) + return false, errors.New(response.Error) } - return &response, nil + return response.Exists, nil } // KVStoreList calls the kvstore_list host function. @@ -262,7 +262,7 @@ func KVStoreHas(key string) (*KVStoreHasResponse, error) { // - prefix: Key prefix to filter by (empty string returns all keys) // // Returns a slice of matching keys. -func KVStoreList(prefix string) (*KVStoreListResponse, error) { +func KVStoreList(prefix string) ([]string, error) { // Marshal request to JSON req := KVStoreListRequest{ Prefix: prefix, @@ -292,12 +292,12 @@ func KVStoreList(prefix string) (*KVStoreListResponse, error) { return nil, errors.New(response.Error) } - return &response, nil + return response.Keys, nil } // KVStoreGetStorageUsed calls the kvstore_getstorageused host function. // GetStorageUsed returns the total storage used by this plugin in bytes. -func KVStoreGetStorageUsed() (*KVStoreGetStorageUsedResponse, error) { +func KVStoreGetStorageUsed() (int64, error) { // No parameters - allocate empty JSON object reqMem := pdk.AllocateBytes([]byte("{}")) defer reqMem.Free() @@ -312,13 +312,13 @@ func KVStoreGetStorageUsed() (*KVStoreGetStorageUsedResponse, error) { // Parse the response var response KVStoreGetStorageUsedResponse if err := json.Unmarshal(responseBytes, &response); err != nil { - return nil, err + return 0, err } // Convert Error field to Go error if response.Error != "" { - return nil, errors.New(response.Error) + return 0, errors.New(response.Error) } - return &response, nil + return response.Bytes, nil } diff --git a/plugins/pdk/go/host/nd_host_kvstore_stub.go b/plugins/pdk/go/host/nd_host_kvstore_stub.go index a3a83f634..c55921554 100644 --- a/plugins/pdk/go/host/nd_host_kvstore_stub.go +++ b/plugins/pdk/go/host/nd_host_kvstore_stub.go @@ -78,7 +78,7 @@ func KVStoreSet(key string, value []byte) error { // - key: The storage key // // Returns the value and whether the key exists. -func KVStoreGet(key string) (*KVStoreGetResponse, error) { +func KVStoreGet(key string) ([]byte, bool, error) { panic("host: KVStoreGet is only available in WASM plugins") } @@ -100,7 +100,7 @@ func KVStoreDelete(key string) error { // - key: The storage key // // Returns true if the key exists. -func KVStoreHas(key string) (*KVStoreHasResponse, error) { +func KVStoreHas(key string) (bool, error) { panic("host: KVStoreHas is only available in WASM plugins") } @@ -111,12 +111,12 @@ func KVStoreHas(key string) (*KVStoreHasResponse, error) { // - prefix: Key prefix to filter by (empty string returns all keys) // // Returns a slice of matching keys. -func KVStoreList(prefix string) (*KVStoreListResponse, error) { +func KVStoreList(prefix string) ([]string, error) { panic("host: KVStoreList is only available in WASM plugins") } // KVStoreGetStorageUsed is a stub that panics on non-WASM platforms. // GetStorageUsed returns the total storage used by this plugin in bytes. -func KVStoreGetStorageUsed() (*KVStoreGetStorageUsedResponse, error) { +func KVStoreGetStorageUsed() (int64, error) { panic("host: KVStoreGetStorageUsed is only available in WASM plugins") } diff --git a/plugins/pdk/go/host/nd_host_library.go b/plugins/pdk/go/host/nd_host_library.go index 047b97407..870892802 100644 --- a/plugins/pdk/go/host/nd_host_library.go +++ b/plugins/pdk/go/host/nd_host_library.go @@ -63,7 +63,7 @@ type LibraryGetAllLibrariesResponse struct { // - id: The library's unique identifier // // Returns the library metadata, or an error if the library is not found. -func LibraryGetLibrary(id int32) (*LibraryGetLibraryResponse, error) { +func LibraryGetLibrary(id int32) (*Library, error) { // Marshal request to JSON req := LibraryGetLibraryRequest{ Id: id, @@ -93,14 +93,14 @@ func LibraryGetLibrary(id int32) (*LibraryGetLibraryResponse, error) { return nil, errors.New(response.Error) } - return &response, nil + return response.Result, nil } // LibraryGetAllLibraries calls the library_getalllibraries host function. // GetAllLibraries retrieves metadata for all configured libraries. // // Returns a slice of all libraries with their metadata. -func LibraryGetAllLibraries() (*LibraryGetAllLibrariesResponse, error) { +func LibraryGetAllLibraries() ([]Library, error) { // No parameters - allocate empty JSON object reqMem := pdk.AllocateBytes([]byte("{}")) defer reqMem.Free() @@ -123,5 +123,5 @@ func LibraryGetAllLibraries() (*LibraryGetAllLibrariesResponse, error) { return nil, errors.New(response.Error) } - return &response, nil + return response.Result, nil } diff --git a/plugins/pdk/go/host/nd_host_library_stub.go b/plugins/pdk/go/host/nd_host_library_stub.go index 6c2f004ec..e79dbf8d7 100644 --- a/plugins/pdk/go/host/nd_host_library_stub.go +++ b/plugins/pdk/go/host/nd_host_library_stub.go @@ -47,7 +47,7 @@ type LibraryGetAllLibrariesResponse struct { // - id: The library's unique identifier // // Returns the library metadata, or an error if the library is not found. -func LibraryGetLibrary(id int32) (*LibraryGetLibraryResponse, error) { +func LibraryGetLibrary(id int32) (*Library, error) { panic("host: LibraryGetLibrary is only available in WASM plugins") } @@ -55,6 +55,6 @@ func LibraryGetLibrary(id int32) (*LibraryGetLibraryResponse, error) { // GetAllLibraries retrieves metadata for all configured libraries. // // Returns a slice of all libraries with their metadata. -func LibraryGetAllLibraries() (*LibraryGetAllLibrariesResponse, error) { +func LibraryGetAllLibraries() ([]Library, error) { panic("host: LibraryGetAllLibraries is only available in WASM plugins") } diff --git a/plugins/pdk/go/host/nd_host_scheduler.go b/plugins/pdk/go/host/nd_host_scheduler.go index f1bfd3129..ef2acae9c 100644 --- a/plugins/pdk/go/host/nd_host_scheduler.go +++ b/plugins/pdk/go/host/nd_host_scheduler.go @@ -70,7 +70,7 @@ type SchedulerCancelScheduleRequest struct { // - scheduleID: Optional unique identifier for the scheduled job. If empty, one will be generated // // Returns the schedule ID that can be used to cancel the job, or an error if scheduling fails. -func SchedulerScheduleOneTime(delaySeconds int32, payload string, scheduleID string) (*SchedulerScheduleOneTimeResponse, error) { +func SchedulerScheduleOneTime(delaySeconds int32, payload string, scheduleID string) (string, error) { // Marshal request to JSON req := SchedulerScheduleOneTimeRequest{ DelaySeconds: delaySeconds, @@ -79,7 +79,7 @@ func SchedulerScheduleOneTime(delaySeconds int32, payload string, scheduleID str } reqBytes, err := json.Marshal(req) if err != nil { - return nil, err + return "", err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() @@ -94,15 +94,15 @@ func SchedulerScheduleOneTime(delaySeconds int32, payload string, scheduleID str // Parse the response var response SchedulerScheduleOneTimeResponse if err := json.Unmarshal(responseBytes, &response); err != nil { - return nil, err + return "", err } // Convert Error field to Go error if response.Error != "" { - return nil, errors.New(response.Error) + return "", errors.New(response.Error) } - return &response, nil + return response.NewScheduleID, nil } // SchedulerScheduleRecurring calls the scheduler_schedulerecurring host function. @@ -115,7 +115,7 @@ func SchedulerScheduleOneTime(delaySeconds int32, payload string, scheduleID str // - scheduleID: Optional unique identifier for the scheduled job. If empty, one will be generated // // Returns the schedule ID that can be used to cancel the job, or an error if scheduling fails. -func SchedulerScheduleRecurring(cronExpression string, payload string, scheduleID string) (*SchedulerScheduleRecurringResponse, error) { +func SchedulerScheduleRecurring(cronExpression string, payload string, scheduleID string) (string, error) { // Marshal request to JSON req := SchedulerScheduleRecurringRequest{ CronExpression: cronExpression, @@ -124,7 +124,7 @@ func SchedulerScheduleRecurring(cronExpression string, payload string, scheduleI } reqBytes, err := json.Marshal(req) if err != nil { - return nil, err + return "", err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() @@ -139,15 +139,15 @@ func SchedulerScheduleRecurring(cronExpression string, payload string, scheduleI // Parse the response var response SchedulerScheduleRecurringResponse if err := json.Unmarshal(responseBytes, &response); err != nil { - return nil, err + return "", err } // Convert Error field to Go error if response.Error != "" { - return nil, errors.New(response.Error) + return "", errors.New(response.Error) } - return &response, nil + return response.NewScheduleID, nil } // SchedulerCancelSchedule calls the scheduler_cancelschedule host function. diff --git a/plugins/pdk/go/host/nd_host_scheduler_stub.go b/plugins/pdk/go/host/nd_host_scheduler_stub.go index 37a67c55e..8e55274d1 100644 --- a/plugins/pdk/go/host/nd_host_scheduler_stub.go +++ b/plugins/pdk/go/host/nd_host_scheduler_stub.go @@ -49,7 +49,7 @@ type SchedulerCancelScheduleRequest struct { // - scheduleID: Optional unique identifier for the scheduled job. If empty, one will be generated // // Returns the schedule ID that can be used to cancel the job, or an error if scheduling fails. -func SchedulerScheduleOneTime(delaySeconds int32, payload string, scheduleID string) (*SchedulerScheduleOneTimeResponse, error) { +func SchedulerScheduleOneTime(delaySeconds int32, payload string, scheduleID string) (string, error) { panic("host: SchedulerScheduleOneTime is only available in WASM plugins") } @@ -63,7 +63,7 @@ func SchedulerScheduleOneTime(delaySeconds int32, payload string, scheduleID str // - scheduleID: Optional unique identifier for the scheduled job. If empty, one will be generated // // Returns the schedule ID that can be used to cancel the job, or an error if scheduling fails. -func SchedulerScheduleRecurring(cronExpression string, payload string, scheduleID string) (*SchedulerScheduleRecurringResponse, error) { +func SchedulerScheduleRecurring(cronExpression string, payload string, scheduleID string) (string, error) { panic("host: SchedulerScheduleRecurring is only available in WASM plugins") } diff --git a/plugins/pdk/go/host/nd_host_subsonicapi.go b/plugins/pdk/go/host/nd_host_subsonicapi.go index 70fbf9db9..d7569759e 100644 --- a/plugins/pdk/go/host/nd_host_subsonicapi.go +++ b/plugins/pdk/go/host/nd_host_subsonicapi.go @@ -35,14 +35,14 @@ type SubsonicAPICallResponse struct { // // The uri parameter should be the Subsonic API path without the server prefix, // e.g., "getAlbumList2?type=random&size=10". The response is returned as raw JSON. -func SubsonicAPICall(uri string) (*SubsonicAPICallResponse, error) { +func SubsonicAPICall(uri string) (string, error) { // Marshal request to JSON req := SubsonicAPICallRequest{ Uri: uri, } reqBytes, err := json.Marshal(req) if err != nil { - return nil, err + return "", err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() @@ -57,13 +57,13 @@ func SubsonicAPICall(uri string) (*SubsonicAPICallResponse, error) { // Parse the response var response SubsonicAPICallResponse if err := json.Unmarshal(responseBytes, &response); err != nil { - return nil, err + return "", err } // Convert Error field to Go error if response.Error != "" { - return nil, errors.New(response.Error) + return "", errors.New(response.Error) } - return &response, nil + return response.ResponseJSON, nil } diff --git a/plugins/pdk/go/host/nd_host_subsonicapi_stub.go b/plugins/pdk/go/host/nd_host_subsonicapi_stub.go index 47c1c8db0..1b069c8e8 100644 --- a/plugins/pdk/go/host/nd_host_subsonicapi_stub.go +++ b/plugins/pdk/go/host/nd_host_subsonicapi_stub.go @@ -24,6 +24,6 @@ type SubsonicAPICallResponse struct { // // The uri parameter should be the Subsonic API path without the server prefix, // e.g., "getAlbumList2?type=random&size=10". The response is returned as raw JSON. -func SubsonicAPICall(uri string) (*SubsonicAPICallResponse, error) { +func SubsonicAPICall(uri string) (string, error) { panic("host: SubsonicAPICall is only available in WASM plugins") } diff --git a/plugins/pdk/go/host/nd_host_websocket.go b/plugins/pdk/go/host/nd_host_websocket.go index cea22712f..9b229c1b3 100644 --- a/plugins/pdk/go/host/nd_host_websocket.go +++ b/plugins/pdk/go/host/nd_host_websocket.go @@ -79,7 +79,7 @@ type WebSocketCloseConnectionRequest struct { // // Returns the connection ID that can be used to send messages or close the connection, // or an error if the connection fails. -func WebSocketConnect(url string, headers map[string]string, connectionID string) (*WebSocketConnectResponse, error) { +func WebSocketConnect(url string, headers map[string]string, connectionID string) (string, error) { // Marshal request to JSON req := WebSocketConnectRequest{ Url: url, @@ -88,7 +88,7 @@ func WebSocketConnect(url string, headers map[string]string, connectionID string } reqBytes, err := json.Marshal(req) if err != nil { - return nil, err + return "", err } reqMem := pdk.AllocateBytes(reqBytes) defer reqMem.Free() @@ -103,15 +103,15 @@ func WebSocketConnect(url string, headers map[string]string, connectionID string // Parse the response var response WebSocketConnectResponse if err := json.Unmarshal(responseBytes, &response); err != nil { - return nil, err + return "", err } // Convert Error field to Go error if response.Error != "" { - return nil, errors.New(response.Error) + return "", errors.New(response.Error) } - return &response, nil + return response.NewConnectionID, nil } // WebSocketSendText calls the websocket_sendtext host function. diff --git a/plugins/pdk/go/host/nd_host_websocket_stub.go b/plugins/pdk/go/host/nd_host_websocket_stub.go index 42f86421a..138b1a14e 100644 --- a/plugins/pdk/go/host/nd_host_websocket_stub.go +++ b/plugins/pdk/go/host/nd_host_websocket_stub.go @@ -53,7 +53,7 @@ type WebSocketCloseConnectionRequest struct { // // Returns the connection ID that can be used to send messages or close the connection, // or an error if the connection fails. -func WebSocketConnect(url string, headers map[string]string, connectionID string) (*WebSocketConnectResponse, error) { +func WebSocketConnect(url string, headers map[string]string, connectionID string) (string, error) { panic("host: WebSocketConnect is only available in WASM plugins") } diff --git a/plugins/testdata/test-artwork/main.go b/plugins/testdata/test-artwork/main.go index ae52efb77..e7da56cfa 100644 --- a/plugins/testdata/test-artwork/main.go +++ b/plugins/testdata/test-artwork/main.go @@ -38,33 +38,13 @@ func ndTestArtwork() int32 { switch strings.ToLower(input.ArtworkType) { case "artist": - resp, e := host.ArtworkGetArtistUrl(input.ID, input.Size) - if e != nil { - err = e - } else { - url = resp.Url - } + url, err = host.ArtworkGetArtistUrl(input.ID, input.Size) case "album": - resp, e := host.ArtworkGetAlbumUrl(input.ID, input.Size) - if e != nil { - err = e - } else { - url = resp.Url - } + url, err = host.ArtworkGetAlbumUrl(input.ID, input.Size) case "track": - resp, e := host.ArtworkGetTrackUrl(input.ID, input.Size) - if e != nil { - err = e - } else { - url = resp.Url - } + url, err = host.ArtworkGetTrackUrl(input.ID, input.Size) case "playlist": - resp, e := host.ArtworkGetPlaylistUrl(input.ID, input.Size) - if e != nil { - err = e - } else { - url = resp.Url - } + url, err = host.ArtworkGetPlaylistUrl(input.ID, input.Size) default: errStr := "unknown artwork type: " + input.ArtworkType pdk.OutputJSON(TestOutput{Error: &errStr}) diff --git a/plugins/testdata/test-cache-plugin/main.go b/plugins/testdata/test-cache-plugin/main.go index 13aa12ecb..f2538f48d 100644 --- a/plugins/testdata/test-cache-plugin/main.go +++ b/plugins/testdata/test-cache-plugin/main.go @@ -51,13 +51,13 @@ func ndTestCache() int32 { return 0 case "get_string": - resp, err := host.CacheGetString(input.Key) + value, exists, err := host.CacheGetString(input.Key) if err != nil { errStr := err.Error() pdk.OutputJSON(TestCacheOutput{Error: &errStr}) return 0 } - pdk.OutputJSON(TestCacheOutput{StringVal: resp.Value, Exists: resp.Exists}) + pdk.OutputJSON(TestCacheOutput{StringVal: value, Exists: exists}) return 0 case "set_int": @@ -71,13 +71,13 @@ func ndTestCache() int32 { return 0 case "get_int": - resp, err := host.CacheGetInt(input.Key) + value, exists, err := host.CacheGetInt(input.Key) if err != nil { errStr := err.Error() pdk.OutputJSON(TestCacheOutput{Error: &errStr}) return 0 } - pdk.OutputJSON(TestCacheOutput{IntVal: resp.Value, Exists: resp.Exists}) + pdk.OutputJSON(TestCacheOutput{IntVal: value, Exists: exists}) return 0 case "set_float": @@ -91,13 +91,13 @@ func ndTestCache() int32 { return 0 case "get_float": - resp, err := host.CacheGetFloat(input.Key) + value, exists, err := host.CacheGetFloat(input.Key) if err != nil { errStr := err.Error() pdk.OutputJSON(TestCacheOutput{Error: &errStr}) return 0 } - pdk.OutputJSON(TestCacheOutput{FloatVal: resp.Value, Exists: resp.Exists}) + pdk.OutputJSON(TestCacheOutput{FloatVal: value, Exists: exists}) return 0 case "set_bytes": @@ -111,23 +111,23 @@ func ndTestCache() int32 { return 0 case "get_bytes": - resp, err := host.CacheGetBytes(input.Key) + value, exists, err := host.CacheGetBytes(input.Key) if err != nil { errStr := err.Error() pdk.OutputJSON(TestCacheOutput{Error: &errStr}) return 0 } - pdk.OutputJSON(TestCacheOutput{BytesVal: resp.Value, Exists: resp.Exists}) + pdk.OutputJSON(TestCacheOutput{BytesVal: value, Exists: exists}) return 0 case "has": - resp, err := host.CacheHas(input.Key) + exists, err := host.CacheHas(input.Key) if err != nil { errStr := err.Error() pdk.OutputJSON(TestCacheOutput{Error: &errStr}) return 0 } - pdk.OutputJSON(TestCacheOutput{Exists: resp.Exists}) + pdk.OutputJSON(TestCacheOutput{Exists: exists}) return 0 case "remove": diff --git a/plugins/testdata/test-kvstore/main.go b/plugins/testdata/test-kvstore/main.go index cef5afc2c..8bfe45d4f 100644 --- a/plugins/testdata/test-kvstore/main.go +++ b/plugins/testdata/test-kvstore/main.go @@ -47,13 +47,13 @@ func ndTestKVStore() int32 { return 0 case "get": - resp, err := host.KVStoreGet(input.Key) + value, exists, err := host.KVStoreGet(input.Key) if err != nil { errStr := err.Error() pdk.OutputJSON(TestKVStoreOutput{Error: &errStr}) return 0 } - pdk.OutputJSON(TestKVStoreOutput{Value: resp.Value, Exists: resp.Exists}) + pdk.OutputJSON(TestKVStoreOutput{Value: value, Exists: exists}) return 0 case "delete": @@ -67,33 +67,33 @@ func ndTestKVStore() int32 { return 0 case "has": - resp, err := host.KVStoreHas(input.Key) + exists, err := host.KVStoreHas(input.Key) if err != nil { errStr := err.Error() pdk.OutputJSON(TestKVStoreOutput{Error: &errStr}) return 0 } - pdk.OutputJSON(TestKVStoreOutput{Exists: resp.Exists}) + pdk.OutputJSON(TestKVStoreOutput{Exists: exists}) return 0 case "list": - resp, err := host.KVStoreList(input.Prefix) + keys, err := host.KVStoreList(input.Prefix) if err != nil { errStr := err.Error() pdk.OutputJSON(TestKVStoreOutput{Error: &errStr}) return 0 } - pdk.OutputJSON(TestKVStoreOutput{Keys: resp.Keys}) + pdk.OutputJSON(TestKVStoreOutput{Keys: keys}) return 0 case "get_storage_used": - resp, err := host.KVStoreGetStorageUsed() + bytesUsed, err := host.KVStoreGetStorageUsed() if err != nil { errStr := err.Error() pdk.OutputJSON(TestKVStoreOutput{Error: &errStr}) return 0 } - pdk.OutputJSON(TestKVStoreOutput{StorageUsed: resp.Bytes}) + pdk.OutputJSON(TestKVStoreOutput{StorageUsed: bytesUsed}) return 0 default: diff --git a/plugins/testdata/test-library/main.go b/plugins/testdata/test-library/main.go index 7291ed9ff..084a71450 100644 --- a/plugins/testdata/test-library/main.go +++ b/plugins/testdata/test-library/main.go @@ -42,23 +42,23 @@ func ndTestLibrary() int32 { switch input.Operation { case "get_library": - resp, err := host.LibraryGetLibrary(input.LibraryID) + library, err := host.LibraryGetLibrary(input.LibraryID) if err != nil { errStr := err.Error() pdk.OutputJSON(TestLibraryOutput{Error: &errStr}) return 0 } - pdk.OutputJSON(TestLibraryOutput{Library: resp.Result}) + pdk.OutputJSON(TestLibraryOutput{Library: library}) return 0 case "get_all_libraries": - resp, err := host.LibraryGetAllLibraries() + libraries, err := host.LibraryGetAllLibraries() if err != nil { errStr := err.Error() pdk.OutputJSON(TestLibraryOutput{Error: &errStr}) return 0 } - pdk.OutputJSON(TestLibraryOutput{Libraries: resp.Result}) + pdk.OutputJSON(TestLibraryOutput{Libraries: libraries}) return 0 case "read_file": diff --git a/plugins/testdata/test-subsonicapi-plugin/main.go b/plugins/testdata/test-subsonicapi-plugin/main.go index 9192fc325..c442c050e 100644 --- a/plugins/testdata/test-subsonicapi-plugin/main.go +++ b/plugins/testdata/test-subsonicapi-plugin/main.go @@ -17,14 +17,14 @@ func callSubsonicAPIExport() int32 { uri := pdk.InputString() // Call the Subsonic API via host function - response, err := host.SubsonicAPICall(uri) + responseJSON, err := host.SubsonicAPICall(uri) if err != nil { pdk.SetErrorString("failed to call SubsonicAPI: " + err.Error()) return 1 } // Return the response - pdk.OutputString(response.ResponseJSON) + pdk.OutputString(responseJSON) return 0 }