From 4e32f1802fcc98175f249c41da2bee65c9387c77 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Fri, 7 Nov 2025 17:24:54 +0100 Subject: [PATCH] Service API docs fixes --- website/API/service.md | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/website/API/service.md b/website/API/service.md index 8ec6938f..26c53cc5 100644 --- a/website/API/service.md +++ b/website/API/service.md @@ -5,11 +5,8 @@ Exposes a simple service registry API leveraged by various parts of SilverBullet ```space-lua service.define { selector = "greeter-service", - name = "generic-greeter", - match = function(name) - -- fallback option, priority undefined (so: low) - return {} - end, + -- no priority set + match = {}, run = function(name) return "Hello " .. name end @@ -17,7 +14,6 @@ service.define { service.define { selector = "greeter-service", - name = "pete-greeter", match = function(name) if name == "Pete" then -- takes precendence with an exact match @@ -40,18 +36,18 @@ Defines a service matching a selector. Spec arguments: * `selector`: service selector, can contain wildcards (e.g. `hello:*`) -* `name`: globally unique service name -* `name` (gid for invocation) -* `match(data)`: callback (`data` argument), returns a match table if this service is a match or `nil` otherwise. A match table is service specific, but at least contains a `priority` key to set the service priority (used for sorting by `service.discover` and `service.invokeBestMatch`). +* `match(data)`: callback (`data` argument), returns a match table if this service is a match or `nil` otherwise. A match table is service specific, but at least contains a `priority` key to set the service priority (used for sorting by `service.discover` and `service.invokeBestMatch`). Instead of a function can also simply be a match object directly. * `run(data)`: callback to be invoked when the service is invoked ### service.discover(selector, data) -Discovers previously defined service matching a given selector. Return value is a list of tables (can be empty) with keys: -* `name`: name of the service +Discovers previously defined service matching a given selector. + +Return value is a list of tables (can be empty) with keys: +* `id`: guid of the service (automatically generated) * `priority`: priority of service match (list will already be pre-sorted based on this key if present) -### service.invoke(name, data) -Invokes a service by name (as returned by [[#service.discover(selector, options)]]). +### service.invoke(match, data) +Invokes a service match (as returned by [[#service.discover(selector, options)]]). ### service.invokeBest(selector, options) Performs a `discover` based on the selector, then immediately performs and `invoke` on the best match (based on priority). \ No newline at end of file