From 3dba572ce7fecc5970b4a0dc34dcd98122c29ada Mon Sep 17 00:00:00 2001 From: Deluan Date: Fri, 2 Jan 2026 14:08:26 -0500 Subject: [PATCH] refactor: rename List method to Keys for clarity in configuration management Signed-off-by: Deluan --- plugins/README.md | 6 +++--- plugins/host/config.go | 4 ++-- plugins/host/config_gen.go | 20 +++++++++---------- plugins/host_config.go | 6 +++--- plugins/host_config_test.go | 10 +++++----- plugins/pdk/go/host/nd_host_config.go | 20 +++++++++---------- plugins/pdk/go/host/nd_host_config_stub.go | 10 +++++----- plugins/pdk/python/host/nd_host_config.py | 8 ++++---- .../rust/nd-pdk-host/src/nd_host_config.rs | 10 +++++----- plugins/testdata/test-config/main.go | 2 +- 10 files changed, 48 insertions(+), 48 deletions(-) diff --git a/plugins/README.md b/plugins/README.md index 477b5cf34..ff53ce36d 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -683,7 +683,7 @@ Access plugin configuration values programmatically. Unlike `pdk.GetConfig()` wh |-----------------|------------|-----------------------------| | `config_get` | `key` | `value, exists` | | `config_getint` | `key` | `value, exists` | -| `config_list` | `prefix` | Array of matching key names | +| `config_keys` | `prefix` | Array of matching key names | **Usage (with generated SDK):** @@ -700,13 +700,13 @@ if exists { count, exists := host.ConfigGetInt("max_retries") // List all keys with a prefix (useful for user-specific config) -keys := host.ConfigList("user:") +keys := host.ConfigKeys("user:") for _, key := range keys { // key might be "user:john", "user:jane", etc. } // List all configuration keys -allKeys := host.ConfigList("") +allKeys := host.ConfigKeys("") ``` --- diff --git a/plugins/host/config.go b/plugins/host/config.go index fca730642..0a0a62ca7 100644 --- a/plugins/host/config.go +++ b/plugins/host/config.go @@ -33,12 +33,12 @@ type ConfigService interface { //nd:hostfunc GetInt(ctx context.Context, key string) (value int64, exists bool) - // List returns configuration keys matching the given prefix. + // Keys returns configuration keys matching the given prefix. // // Parameters: // - prefix: Key prefix to filter by. If empty, returns all keys. // // Returns a sorted slice of matching configuration keys. //nd:hostfunc - List(ctx context.Context, prefix string) (keys []string) + Keys(ctx context.Context, prefix string) (keys []string) } diff --git a/plugins/host/config_gen.go b/plugins/host/config_gen.go index 936c45d67..0fd1b6ef4 100644 --- a/plugins/host/config_gen.go +++ b/plugins/host/config_gen.go @@ -31,13 +31,13 @@ type ConfigGetIntResponse struct { Exists bool `json:"exists,omitempty"` } -// ConfigListRequest is the request type for Config.List. -type ConfigListRequest struct { +// ConfigKeysRequest is the request type for Config.Keys. +type ConfigKeysRequest struct { Prefix string `json:"prefix"` } -// ConfigListResponse is the response type for Config.List. -type ConfigListResponse struct { +// ConfigKeysResponse is the response type for Config.Keys. +type ConfigKeysResponse struct { Keys []string `json:"keys,omitempty"` } @@ -47,7 +47,7 @@ func RegisterConfigHostFunctions(service ConfigService) []extism.HostFunction { return []extism.HostFunction{ newConfigGetHostFunction(service), newConfigGetIntHostFunction(service), - newConfigListHostFunction(service), + newConfigKeysHostFunction(service), } } @@ -113,9 +113,9 @@ func newConfigGetIntHostFunction(service ConfigService) extism.HostFunction { ) } -func newConfigListHostFunction(service ConfigService) extism.HostFunction { +func newConfigKeysHostFunction(service ConfigService) extism.HostFunction { return extism.NewHostFunctionWithStack( - "config_list", + "config_keys", func(ctx context.Context, p *extism.CurrentPlugin, stack []uint64) { // Read JSON request from plugin memory reqBytes, err := p.ReadBytes(stack[0]) @@ -123,17 +123,17 @@ func newConfigListHostFunction(service ConfigService) extism.HostFunction { configWriteError(p, stack, err) return } - var req ConfigListRequest + var req ConfigKeysRequest if err := json.Unmarshal(reqBytes, &req); err != nil { configWriteError(p, stack, err) return } // Call the service method - keys := service.List(ctx, req.Prefix) + keys := service.Keys(ctx, req.Prefix) // Write JSON response to plugin memory - resp := ConfigListResponse{ + resp := ConfigKeysResponse{ Keys: keys, } configWriteResponse(p, stack, resp) diff --git a/plugins/host_config.go b/plugins/host_config.go index d2d94880d..9e71db72f 100644 --- a/plugins/host_config.go +++ b/plugins/host_config.go @@ -53,8 +53,8 @@ func (s *configServiceImpl) GetInt(ctx context.Context, key string) (int64, bool return intValue, true } -// List returns configuration keys matching the given prefix. -func (s *configServiceImpl) List(ctx context.Context, prefix string) []string { +// Keys returns configuration keys matching the given prefix. +func (s *configServiceImpl) Keys(ctx context.Context, prefix string) []string { keys := make([]string, 0, len(s.config)) for k := range s.config { if prefix == "" || strings.HasPrefix(k, prefix) { @@ -62,7 +62,7 @@ func (s *configServiceImpl) List(ctx context.Context, prefix string) []string { } } sort.Strings(keys) - log.Trace(ctx, "Config.List", "plugin", s.pluginName, "prefix", prefix, "keyCount", len(keys)) + log.Trace(ctx, "Config.Keys", "plugin", s.pluginName, "prefix", prefix, "keyCount", len(keys)) return keys } diff --git a/plugins/host_config_test.go b/plugins/host_config_test.go index 9261e899e..b49c5c7dc 100644 --- a/plugins/host_config_test.go +++ b/plugins/host_config_test.go @@ -107,7 +107,7 @@ var _ = Describe("ConfigService", func() { }) }) - Describe("List", func() { + Describe("Keys", func() { BeforeEach(func() { service = newConfigService("test_plugin", map[string]string{ "zebra": "z", @@ -120,23 +120,23 @@ var _ = Describe("ConfigService", func() { }) It("returns all keys in sorted order when prefix is empty", func() { - keys := service.List(ctx, "") + keys := service.Keys(ctx, "") Expect(keys).To(Equal([]string{"apple", "banana", "user_alice", "user_bob", "user_charlie", "zebra"})) }) It("returns only keys matching prefix", func() { - keys := service.List(ctx, "user_") + keys := service.Keys(ctx, "user_") Expect(keys).To(Equal([]string{"user_alice", "user_bob", "user_charlie"})) }) It("returns empty slice when no keys match prefix", func() { - keys := service.List(ctx, "nonexistent_") + keys := service.Keys(ctx, "nonexistent_") Expect(keys).To(BeEmpty()) }) It("returns empty slice for empty config", func() { service = newConfigService("test_plugin", nil) - keys := service.List(ctx, "") + keys := service.Keys(ctx, "") Expect(keys).To(BeEmpty()) }) }) diff --git a/plugins/pdk/go/host/nd_host_config.go b/plugins/pdk/go/host/nd_host_config.go index f435cd1c6..b4f258c62 100644 --- a/plugins/pdk/go/host/nd_host_config.go +++ b/plugins/pdk/go/host/nd_host_config.go @@ -23,10 +23,10 @@ func config_get(uint64) uint64 //go:wasmimport extism:host/user config_getint func config_getint(uint64) uint64 -// config_list is the host function provided by Navidrome. +// config_keys is the host function provided by Navidrome. // -//go:wasmimport extism:host/user config_list -func config_list(uint64) uint64 +//go:wasmimport extism:host/user config_keys +func config_keys(uint64) uint64 type configGetRequest struct { Key string `json:"key"` @@ -46,11 +46,11 @@ type configGetIntResponse struct { Exists bool `json:"exists,omitempty"` } -type configListRequest struct { +type configKeysRequest struct { Prefix string `json:"prefix"` } -type configListResponse struct { +type configKeysResponse struct { Keys []string `json:"keys,omitempty"` } @@ -125,16 +125,16 @@ func ConfigGetInt(key string) (int64, bool) { return response.Value, response.Exists } -// ConfigList calls the config_list host function. +// ConfigKeys calls the config_keys host function. // List returns configuration keys matching the given prefix. // // Parameters: // - prefix: Key prefix to filter by. If empty, returns all keys. // // Returns a sorted slice of matching configuration keys. -func ConfigList(prefix string) []string { +func ConfigKeys(prefix string) []string { // Marshal request to JSON - req := configListRequest{ + req := configKeysRequest{ Prefix: prefix, } reqBytes, err := json.Marshal(req) @@ -145,14 +145,14 @@ func ConfigList(prefix string) []string { defer reqMem.Free() // Call the host function - responsePtr := config_list(reqMem.Offset()) + responsePtr := config_keys(reqMem.Offset()) // Read the response from memory responseMem := pdk.FindMemory(responsePtr) responseBytes := responseMem.ReadBytes() // Parse the response - var response configListResponse + var response configKeysResponse if err := json.Unmarshal(responseBytes, &response); err != nil { return nil } diff --git a/plugins/pdk/go/host/nd_host_config_stub.go b/plugins/pdk/go/host/nd_host_config_stub.go index df9ae1a6d..6b47348cc 100644 --- a/plugins/pdk/go/host/nd_host_config_stub.go +++ b/plugins/pdk/go/host/nd_host_config_stub.go @@ -54,19 +54,19 @@ func ConfigGetInt(key string) (int64, bool) { return ConfigMock.GetInt(key) } -// List is the mock method for ConfigList. -func (m *mockConfigService) List(prefix string) []string { +// Keys is the mock method for ConfigKeys. +func (m *mockConfigService) Keys(prefix string) []string { args := m.Called(prefix) return args.Get(0).([]string) } -// ConfigList delegates to the mock instance. +// ConfigKeys delegates to the mock instance. // List returns configuration keys matching the given prefix. // // Parameters: // - prefix: Key prefix to filter by. If empty, returns all keys. // // Returns a sorted slice of matching configuration keys. -func ConfigList(prefix string) []string { - return ConfigMock.List(prefix) +func ConfigKeys(prefix string) []string { + return ConfigMock.Keys(prefix) } diff --git a/plugins/pdk/python/host/nd_host_config.py b/plugins/pdk/python/host/nd_host_config.py index ca5bf89de..ae015fc2a 100644 --- a/plugins/pdk/python/host/nd_host_config.py +++ b/plugins/pdk/python/host/nd_host_config.py @@ -31,8 +31,8 @@ def _config_getint(offset: int) -> int: ... -@extism.import_fn("extism:host/user", "config_list") -def _config_list(offset: int) -> int: +@extism.import_fn("extism:host/user", "config_keys") +def _config_keys(offset: int) -> int: """Raw host function - do not call directly.""" ... @@ -116,7 +116,7 @@ value cannot be parsed as an integer, exists will be false. ) -def config_list(prefix: str) -> Any: +def config_keys(prefix: str) -> Any: """List returns configuration keys matching the given prefix. Parameters: @@ -138,7 +138,7 @@ Returns a sorted slice of matching configuration keys. } request_bytes = json.dumps(request).encode("utf-8") request_mem = extism.memory.alloc(request_bytes) - response_offset = _config_list(request_mem.offset) + response_offset = _config_keys(request_mem.offset) response_mem = extism.memory.find(response_offset) response = json.loads(extism.memory.string(response_mem)) diff --git a/plugins/pdk/rust/nd-pdk-host/src/nd_host_config.rs b/plugins/pdk/rust/nd-pdk-host/src/nd_host_config.rs index 99a302968..d2359255f 100644 --- a/plugins/pdk/rust/nd-pdk-host/src/nd_host_config.rs +++ b/plugins/pdk/rust/nd-pdk-host/src/nd_host_config.rs @@ -38,13 +38,13 @@ struct ConfigGetIntResponse { #[derive(Debug, Clone, Serialize)] #[serde(rename_all = "camelCase")] -struct ConfigListRequest { +struct ConfigKeysRequest { prefix: String, } #[derive(Debug, Clone, Deserialize)] #[serde(rename_all = "camelCase")] -struct ConfigListResponse { +struct ConfigKeysResponse { #[serde(default)] keys: Vec, } @@ -53,7 +53,7 @@ struct ConfigListResponse { extern "ExtismHost" { fn config_get(input: Json) -> Json; fn config_getint(input: Json) -> Json; - fn config_list(input: Json) -> Json; + fn config_keys(input: Json) -> Json; } /// Get retrieves a configuration value as a string. @@ -122,9 +122,9 @@ pub fn get_int(key: &str) -> Result<(i64, bool), Error> { /// /// # Errors /// Returns an error if the host function call fails. -pub fn list(prefix: &str) -> Result, Error> { +pub fn keys(prefix: &str) -> Result, Error> { let response = unsafe { - config_list(Json(ConfigListRequest { + config_keys(Json(ConfigKeysRequest { prefix: prefix.to_owned(), }))? }; diff --git a/plugins/testdata/test-config/main.go b/plugins/testdata/test-config/main.go index 24a4e59f2..1d058db11 100644 --- a/plugins/testdata/test-config/main.go +++ b/plugins/testdata/test-config/main.go @@ -46,7 +46,7 @@ func ndTestConfig() int32 { return 0 case "list": - keys := host.ConfigList(input.Prefix) + keys := host.ConfigKeys(input.Prefix) pdk.OutputJSON(TestConfigOutput{Keys: keys}) return 0