Skip to content

Events: support any kind of objectSpec #342

@tpluscode

Description

@tpluscode

Right now only types are matched to find event handler to execute.

Here's an improved query which could be used to find handlers which can support any kind of eventSpec and only find such handlers which satisfy all conditions

PREFIX as: <https://www.w3.org/ns/activitystreams#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX hydra: <http://www.w3.org/ns/hydra/core#>
prefix event: <https://hypermedia.app/events#>
prefix code: <https://code.described.at/>

DESCRIBE ?handler
WHERE {
    {
        select ?handler (count(?spec) as ?allSpecs) (count(?match) as ?matchedSpecs) {
            VALUES ?activity { as:Activity as:Create }
            BIND (<https://creta-todos.lndo.site/todos/item/Ride%20Corbet%27s%20couloir> as ?object)

            ?handler a event:EventHandler ;
                event:eventSpec
                    [
                        rdf:predicate rdf:type ;
                        rdf:object ?activity
                    ] ;
                event:objectSpec ?spec ;
                code:implementedBy ?impl ;
                hydra:apiDocumentation <https://creta-todos.lndo.site/todos/api> .

            optional {
                ?spec rdf:predicate ?p ;
                    rdf:object ?o .
                ?object ?p ?o .
                BIND(?spec as ?match)
            }
        }
        group by ?handler
        having (count(?spec) = count(?match))
    }
}

Thus, if a handler was defined as

<>
  events:objectSpec
    [
      rdf:predicate rdf:type ;
      rdf:object </api/TodoItem> ;
    ],
    [
      rdf:predicate schema:status ;
      rdf:object "IN PROGRESS" ; 
    ] .

it would only execute when the resource above was

<https://creta-todos.lndo.site/todos/item/Ride%20Corbet%27s%20couloir>
  a </api/TodoItem> ;
  schema:status "IN PROGRESS" ;
.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions