Adjust to Syndicate API

This commit is contained in:
Emery Hemingway 2023-10-10 09:04:59 +01:00
parent c77c1cb8ac
commit bb773e10b9
4 changed files with 28 additions and 22 deletions

View File

@ -2,10 +2,20 @@
# SPDX-License-Identifier: Unlicense
import std/[asyncdispatch, os, uri]
import preserves, syndicate, syndicate/capabilities
import preserves, syndicate, syndicate/relays, syndicate/capabilities
import ./protocol, ./common
proc publishUri(turn: var Turn; ds: Ref) =
proc unixSocketPath: Unix =
result.path = getEnv("SYNDICATE_SOCK")
if result.path == "":
result.path = getEnv("XDG_RUNTIME_DIR", "/run/user/1000") / "dataspace"
proc envStep: Assertion =
var s = getEnv("SYNDICATE_STEP")
if s != "": parsePreserves(s, Cap)
else: capabilities.mint().toPreserve(Cap)
proc publishUri(turn: var Turn; ds: Cap) =
for arg in commandLineParams():
if fileExists(arg):
message(turn, ds, Open(uri: protocol.Uri(
@ -14,14 +24,12 @@ proc publishUri(turn: var Turn; ds: Ref) =
message(turn, ds, initRecord("open", arg.parseUri.toPreserve))
stop(turn)
proc unixSocketPath: Unix =
result.path = getEnv("SYNDICATE_SOCK")
if result.path == "":
result.path = getEnv("XDG_RUNTIME_DIR", "/run/user/1000") / "dataspace"
proc main =
let step = envStep()
discard bootDataspace("open") do (root: Cap; turn: var Turn):
connect(turn, unixSocketPath(), step, publishUri)
discard bootDataspace("open") do (root: Ref; turn: var Turn):
let cap = mint().toPreserve(Ref)
connect(turn, unixSocketPath(), cap, publishUri)
for i in 0..4: poll(20)
# A hack to exit
for i in 0..4: poll(20)
# A hack to exit
main()

View File

@ -2,29 +2,29 @@
# SPDX-License-Identifier: Unlicense
import std/[re, tables, uri]
import preserves, syndicate, syndicate/patterns
import preserves, syndicate, syndicate/relays, syndicate/patterns
import ./protocol, ./common
# importing std/re doesn't actually link against PCRE
{.passC: staticExec("pkg-config --cflags libpcre").}
{.passL: staticExec("pkg-config --libs libpcre").}
type RegexAction = tuple[regex: Regex, entity: Ref, action: Assertion]
type RegexAction = tuple[regex: Regex, entity: Cap, action: Assertion]
proc rewrite(result: var Assertion; uri: string; regex: Regex) =
proc op(pr: var Assertion) =
proc rewrite(result: var Assertion; uri: string; regex: Regex) {.gcsafe.} =
proc op(pr: var Assertion) {.gcsafe.} =
if pr.isString:
pr.string = replacef(uri, regex, pr.string)
apply(result, op)
runActor("main") do (root: Ref; turn: var Turn):
runActor("main") do (root: Cap; turn: var Turn):
connectStdio(root, turn)
var handlers: Table[Handle, RegexAction]
during(turn, root, ?UriRunnerConfig) do (handlerspace: Ref, urispace: Ref):
let handlers = newTable[Handle, RegexAction]()
during(turn, root, ?UriRunnerConfig) do (handlerspace: Cap, urispace: Cap):
during(turn, handlerspace, dropType(ActionHandler)) do:
during(turn, handlerspace, ?ActionHandler) do (pat: string; entity: Ref; act: Assertion):
during(turn, handlerspace, ?ActionHandler) do (pat: string; entity: Cap; act: Assertion):
# `duringHandle` is a symbol exposed by the `during` macro
handlers[duringHandle] = (re(pat, {reIgnoreCase, reStudy}), entity, act,)
do:

View File

@ -1,6 +1,6 @@
# Package
version = "20230630"
version = "20231010"
author = "Emery"
description = "Syndicated open command"
license = "Unlicense"

View File

@ -1,5 +1,3 @@
<require-service <daemon uri_runner>>
; configure the daemon when it is built
; (this is an artifact of the author's build system)
? <built uri_runner ?path ?hash> [