Relatude Help

Modules

Commands of your own are registered the way the built-in ones are. A module adds them with Command(…) on its builder, named after the module (chapter 18). Host code registers them on CmsApiCommands:

var commands = app.Services.GetRequiredService<CmsApiCommands>();
commands.Register("shop-stock", ctx => {
    var p = ctx.Payload<StockRequest>();
    return ctx.Db.Query<IProduct>().Where(x => x.Sku == p.Sku).Execute().Select(x => x.Stock);
}, readOnly: true);
CmsApiContext Is
Db the store as the caller, in the payload's context
Root the whole store, for checks the server makes on its own behalf; never answer the user from it
Payload<T>() the payload, read from camelCase JSON
UserId, IsAdmin, IsInGroup(id) who is asking; IsInGroup checks direct membership
Changed(id, typeId, kind) adds a node to the nodes-changed event once the command succeeds
StartProcess(start, work) starts a process (below)
  • Throw CmsApiException(status, message) to answer with an error.
  • readOnly: true marks a command that changes nothing. Only those run for an anonymous caller.
  • Register replaces any command of the same type, a built-in one included, so give yours names of their own.
  • CmsApiEvents.Broadcast(name, payload) sends an event of your own to every connection. The SDK hears it with store.channel.subscribe(name, handler).