mirror of
https://github.com/navidrome/navidrome.git
synced 2026-03-04 06:35:52 +00:00
* fix(plugins): add base64 handling for []byte and remove raw=true Go's json.Marshal automatically base64-encodes []byte fields, but Rust's serde_json serializes Vec<u8> as a JSON array and Python's json.dumps raises TypeError on bytes. This fixes both directions of plugin communication by adding proper base64 encoding/decoding in generated client code. For Rust templates (client and capability): adds a base64_bytes serde helper module with #[serde(with = "base64_bytes")] on all Vec<u8> fields, and adds base64 as a dependency. For Python templates: wraps bytes params with base64.b64encode() and responses with base64.b64decode(). Also removes the raw=true binary framing protocol from all templates, the parser, and the Method type. The raw mechanism added complexity that is no longer needed once []byte works properly over JSON. * fix(plugins): update production code and tests for base64 migration Remove raw=true annotation from SubsonicAPI.CallRaw, delete all raw test fixtures, remove raw-related test cases from parser, generator, and integration tests, and add new test cases validating base64 handling for Rust and Python templates. * fix(plugins): update golden files and regenerate production code Update golden test fixtures for codec and comprehensive services to include base64 handling for []byte fields. Regenerate all production PDK code (Go, Rust, Python) and host wrappers to use standard JSON with base64-encoded byte fields instead of binary framing protocol. * refactor: remove base64 helper duplication from rust template Signed-off-by: Deluan <deluan@navidrome.org> * fix(plugins): add base64 dependency to capabilities' Cargo.toml Signed-off-by: Deluan <deluan@navidrome.org> --------- Signed-off-by: Deluan <deluan@navidrome.org>
343 lines
9.7 KiB
Python
343 lines
9.7 KiB
Python
# Code generated by ndpgen. DO NOT EDIT.
|
|
#
|
|
# This file contains client wrappers for the Comprehensive host service.
|
|
# It is intended for use in Navidrome plugins built with extism-py.
|
|
#
|
|
# IMPORTANT: Due to a limitation in extism-py, you cannot import this file directly.
|
|
# The @extism.import_fn decorators are only detected when defined in the plugin's
|
|
# main __init__.py file. Copy the needed functions from this file into your plugin.
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Any
|
|
|
|
import extism
|
|
import json
|
|
import base64
|
|
|
|
|
|
class HostFunctionError(Exception):
|
|
"""Raised when a host function returns an error."""
|
|
pass
|
|
|
|
|
|
@extism.import_fn("extism:host/user", "comprehensive_simpleparams")
|
|
def _comprehensive_simpleparams(offset: int) -> int:
|
|
"""Raw host function - do not call directly."""
|
|
...
|
|
|
|
|
|
@extism.import_fn("extism:host/user", "comprehensive_structparam")
|
|
def _comprehensive_structparam(offset: int) -> int:
|
|
"""Raw host function - do not call directly."""
|
|
...
|
|
|
|
|
|
@extism.import_fn("extism:host/user", "comprehensive_mixedparams")
|
|
def _comprehensive_mixedparams(offset: int) -> int:
|
|
"""Raw host function - do not call directly."""
|
|
...
|
|
|
|
|
|
@extism.import_fn("extism:host/user", "comprehensive_noerror")
|
|
def _comprehensive_noerror(offset: int) -> int:
|
|
"""Raw host function - do not call directly."""
|
|
...
|
|
|
|
|
|
@extism.import_fn("extism:host/user", "comprehensive_noparams")
|
|
def _comprehensive_noparams(offset: int) -> int:
|
|
"""Raw host function - do not call directly."""
|
|
...
|
|
|
|
|
|
@extism.import_fn("extism:host/user", "comprehensive_noparamsnoreturns")
|
|
def _comprehensive_noparamsnoreturns(offset: int) -> int:
|
|
"""Raw host function - do not call directly."""
|
|
...
|
|
|
|
|
|
@extism.import_fn("extism:host/user", "comprehensive_pointerparams")
|
|
def _comprehensive_pointerparams(offset: int) -> int:
|
|
"""Raw host function - do not call directly."""
|
|
...
|
|
|
|
|
|
@extism.import_fn("extism:host/user", "comprehensive_mapparams")
|
|
def _comprehensive_mapparams(offset: int) -> int:
|
|
"""Raw host function - do not call directly."""
|
|
...
|
|
|
|
|
|
@extism.import_fn("extism:host/user", "comprehensive_multiplereturns")
|
|
def _comprehensive_multiplereturns(offset: int) -> int:
|
|
"""Raw host function - do not call directly."""
|
|
...
|
|
|
|
|
|
@extism.import_fn("extism:host/user", "comprehensive_byteslice")
|
|
def _comprehensive_byteslice(offset: int) -> int:
|
|
"""Raw host function - do not call directly."""
|
|
...
|
|
|
|
|
|
@dataclass
|
|
class ComprehensiveMultipleReturnsResult:
|
|
"""Result type for comprehensive_multiple_returns."""
|
|
results: Any
|
|
total: int
|
|
|
|
|
|
def comprehensive_simple_params(name: str, count: int) -> str:
|
|
"""Call the comprehensive_simpleparams host function.
|
|
|
|
Args:
|
|
name: str parameter.
|
|
count: int parameter.
|
|
|
|
Returns:
|
|
str: The result value.
|
|
|
|
Raises:
|
|
HostFunctionError: If the host function returns an error.
|
|
"""
|
|
request = {
|
|
"name": name,
|
|
"count": count,
|
|
}
|
|
request_bytes = json.dumps(request).encode("utf-8")
|
|
request_mem = extism.memory.alloc(request_bytes)
|
|
response_offset = _comprehensive_simpleparams(request_mem.offset)
|
|
response_mem = extism.memory.find(response_offset)
|
|
response = json.loads(extism.memory.string(response_mem))
|
|
|
|
if response.get("error"):
|
|
raise HostFunctionError(response["error"])
|
|
|
|
return response.get("result", "")
|
|
|
|
|
|
def comprehensive_struct_param(user: Any) -> None:
|
|
"""Call the comprehensive_structparam host function.
|
|
|
|
Args:
|
|
user: Any parameter.
|
|
|
|
Raises:
|
|
HostFunctionError: If the host function returns an error.
|
|
"""
|
|
request = {
|
|
"user": user,
|
|
}
|
|
request_bytes = json.dumps(request).encode("utf-8")
|
|
request_mem = extism.memory.alloc(request_bytes)
|
|
response_offset = _comprehensive_structparam(request_mem.offset)
|
|
response_mem = extism.memory.find(response_offset)
|
|
response = json.loads(extism.memory.string(response_mem))
|
|
|
|
if response.get("error"):
|
|
raise HostFunctionError(response["error"])
|
|
|
|
|
|
|
|
def comprehensive_mixed_params(id: str, filter: Any) -> int:
|
|
"""Call the comprehensive_mixedparams host function.
|
|
|
|
Args:
|
|
id: str parameter.
|
|
filter: Any parameter.
|
|
|
|
Returns:
|
|
int: The result value.
|
|
|
|
Raises:
|
|
HostFunctionError: If the host function returns an error.
|
|
"""
|
|
request = {
|
|
"id": id,
|
|
"filter": filter,
|
|
}
|
|
request_bytes = json.dumps(request).encode("utf-8")
|
|
request_mem = extism.memory.alloc(request_bytes)
|
|
response_offset = _comprehensive_mixedparams(request_mem.offset)
|
|
response_mem = extism.memory.find(response_offset)
|
|
response = json.loads(extism.memory.string(response_mem))
|
|
|
|
if response.get("error"):
|
|
raise HostFunctionError(response["error"])
|
|
|
|
return response.get("result", 0)
|
|
|
|
|
|
def comprehensive_no_error(name: str) -> str:
|
|
"""Call the comprehensive_noerror host function.
|
|
|
|
Args:
|
|
name: str parameter.
|
|
|
|
Returns:
|
|
str: The result value.
|
|
|
|
Raises:
|
|
HostFunctionError: If the host function returns an error.
|
|
"""
|
|
request = {
|
|
"name": name,
|
|
}
|
|
request_bytes = json.dumps(request).encode("utf-8")
|
|
request_mem = extism.memory.alloc(request_bytes)
|
|
response_offset = _comprehensive_noerror(request_mem.offset)
|
|
response_mem = extism.memory.find(response_offset)
|
|
response = json.loads(extism.memory.string(response_mem))
|
|
|
|
if response.get("error"):
|
|
raise HostFunctionError(response["error"])
|
|
|
|
return response.get("result", "")
|
|
|
|
|
|
def comprehensive_no_params() -> None:
|
|
"""Call the comprehensive_noparams host function.
|
|
|
|
Raises:
|
|
HostFunctionError: If the host function returns an error.
|
|
"""
|
|
request_bytes = b"{}"
|
|
request_mem = extism.memory.alloc(request_bytes)
|
|
response_offset = _comprehensive_noparams(request_mem.offset)
|
|
response_mem = extism.memory.find(response_offset)
|
|
response = json.loads(extism.memory.string(response_mem))
|
|
|
|
if response.get("error"):
|
|
raise HostFunctionError(response["error"])
|
|
|
|
|
|
|
|
def comprehensive_no_params_no_returns() -> None:
|
|
"""Call the comprehensive_noparamsnoreturns host function.
|
|
|
|
Raises:
|
|
HostFunctionError: If the host function returns an error.
|
|
"""
|
|
request_bytes = b"{}"
|
|
request_mem = extism.memory.alloc(request_bytes)
|
|
response_offset = _comprehensive_noparamsnoreturns(request_mem.offset)
|
|
response_mem = extism.memory.find(response_offset)
|
|
response = json.loads(extism.memory.string(response_mem))
|
|
|
|
if response.get("error"):
|
|
raise HostFunctionError(response["error"])
|
|
|
|
|
|
|
|
def comprehensive_pointer_params(id: Any, user: Any) -> Any:
|
|
"""Call the comprehensive_pointerparams host function.
|
|
|
|
Args:
|
|
id: Any parameter.
|
|
user: Any parameter.
|
|
|
|
Returns:
|
|
Any: The result value.
|
|
|
|
Raises:
|
|
HostFunctionError: If the host function returns an error.
|
|
"""
|
|
request = {
|
|
"id": id,
|
|
"user": user,
|
|
}
|
|
request_bytes = json.dumps(request).encode("utf-8")
|
|
request_mem = extism.memory.alloc(request_bytes)
|
|
response_offset = _comprehensive_pointerparams(request_mem.offset)
|
|
response_mem = extism.memory.find(response_offset)
|
|
response = json.loads(extism.memory.string(response_mem))
|
|
|
|
if response.get("error"):
|
|
raise HostFunctionError(response["error"])
|
|
|
|
return response.get("result", None)
|
|
|
|
|
|
def comprehensive_map_params(data: Any) -> Any:
|
|
"""Call the comprehensive_mapparams host function.
|
|
|
|
Args:
|
|
data: Any parameter.
|
|
|
|
Returns:
|
|
Any: The result value.
|
|
|
|
Raises:
|
|
HostFunctionError: If the host function returns an error.
|
|
"""
|
|
request = {
|
|
"data": data,
|
|
}
|
|
request_bytes = json.dumps(request).encode("utf-8")
|
|
request_mem = extism.memory.alloc(request_bytes)
|
|
response_offset = _comprehensive_mapparams(request_mem.offset)
|
|
response_mem = extism.memory.find(response_offset)
|
|
response = json.loads(extism.memory.string(response_mem))
|
|
|
|
if response.get("error"):
|
|
raise HostFunctionError(response["error"])
|
|
|
|
return response.get("result", None)
|
|
|
|
|
|
def comprehensive_multiple_returns(query: str) -> ComprehensiveMultipleReturnsResult:
|
|
"""Call the comprehensive_multiplereturns host function.
|
|
|
|
Args:
|
|
query: str parameter.
|
|
|
|
Returns:
|
|
ComprehensiveMultipleReturnsResult containing results, total,.
|
|
|
|
Raises:
|
|
HostFunctionError: If the host function returns an error.
|
|
"""
|
|
request = {
|
|
"query": query,
|
|
}
|
|
request_bytes = json.dumps(request).encode("utf-8")
|
|
request_mem = extism.memory.alloc(request_bytes)
|
|
response_offset = _comprehensive_multiplereturns(request_mem.offset)
|
|
response_mem = extism.memory.find(response_offset)
|
|
response = json.loads(extism.memory.string(response_mem))
|
|
|
|
if response.get("error"):
|
|
raise HostFunctionError(response["error"])
|
|
|
|
return ComprehensiveMultipleReturnsResult(
|
|
results=response.get("results", None),
|
|
total=response.get("total", 0),
|
|
)
|
|
|
|
|
|
def comprehensive_byte_slice(data: bytes) -> bytes:
|
|
"""Call the comprehensive_byteslice host function.
|
|
|
|
Args:
|
|
data: bytes parameter.
|
|
|
|
Returns:
|
|
bytes: The result value.
|
|
|
|
Raises:
|
|
HostFunctionError: If the host function returns an error.
|
|
"""
|
|
request = {
|
|
"data": base64.b64encode(data).decode("ascii"),
|
|
}
|
|
request_bytes = json.dumps(request).encode("utf-8")
|
|
request_mem = extism.memory.alloc(request_bytes)
|
|
response_offset = _comprehensive_byteslice(request_mem.offset)
|
|
response_mem = extism.memory.find(response_offset)
|
|
response = json.loads(extism.memory.string(response_mem))
|
|
|
|
if response.get("error"):
|
|
raise HostFunctionError(response["error"])
|
|
|
|
return base64.b64decode(response.get("result", ""))
|