Adjust to Syndicate API
This commit is contained in:
parent
c77c1cb8ac
commit
bb773e10b9
30
src/open.nim
30
src/open.nim
|
@ -2,10 +2,20 @@
|
||||||
# SPDX-License-Identifier: Unlicense
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
import std/[asyncdispatch, os, uri]
|
import std/[asyncdispatch, os, uri]
|
||||||
import preserves, syndicate, syndicate/capabilities
|
import preserves, syndicate, syndicate/relays, syndicate/capabilities
|
||||||
import ./protocol, ./common
|
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():
|
for arg in commandLineParams():
|
||||||
if fileExists(arg):
|
if fileExists(arg):
|
||||||
message(turn, ds, Open(uri: protocol.Uri(
|
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))
|
message(turn, ds, initRecord("open", arg.parseUri.toPreserve))
|
||||||
stop(turn)
|
stop(turn)
|
||||||
|
|
||||||
proc unixSocketPath: Unix =
|
proc main =
|
||||||
result.path = getEnv("SYNDICATE_SOCK")
|
let step = envStep()
|
||||||
if result.path == "":
|
discard bootDataspace("open") do (root: Cap; turn: var Turn):
|
||||||
result.path = getEnv("XDG_RUNTIME_DIR", "/run/user/1000") / "dataspace"
|
connect(turn, unixSocketPath(), step, publishUri)
|
||||||
|
|
||||||
discard bootDataspace("open") do (root: Ref; turn: var Turn):
|
for i in 0..4: poll(20)
|
||||||
let cap = mint().toPreserve(Ref)
|
# A hack to exit
|
||||||
connect(turn, unixSocketPath(), cap, publishUri)
|
|
||||||
|
|
||||||
for i in 0..4: poll(20)
|
main()
|
||||||
# A hack to exit
|
|
||||||
|
|
|
@ -2,29 +2,29 @@
|
||||||
# SPDX-License-Identifier: Unlicense
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
import std/[re, tables, uri]
|
import std/[re, tables, uri]
|
||||||
import preserves, syndicate, syndicate/patterns
|
import preserves, syndicate, syndicate/relays, syndicate/patterns
|
||||||
import ./protocol, ./common
|
import ./protocol, ./common
|
||||||
|
|
||||||
# importing std/re doesn't actually link against PCRE
|
# importing std/re doesn't actually link against PCRE
|
||||||
{.passC: staticExec("pkg-config --cflags libpcre").}
|
{.passC: staticExec("pkg-config --cflags libpcre").}
|
||||||
{.passL: staticExec("pkg-config --libs 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 rewrite(result: var Assertion; uri: string; regex: Regex) {.gcsafe.} =
|
||||||
proc op(pr: var Assertion) =
|
proc op(pr: var Assertion) {.gcsafe.} =
|
||||||
if pr.isString:
|
if pr.isString:
|
||||||
pr.string = replacef(uri, regex, pr.string)
|
pr.string = replacef(uri, regex, pr.string)
|
||||||
apply(result, op)
|
apply(result, op)
|
||||||
|
|
||||||
runActor("main") do (root: Ref; turn: var Turn):
|
runActor("main") do (root: Cap; turn: var Turn):
|
||||||
connectStdio(root, turn)
|
connectStdio(root, turn)
|
||||||
var handlers: Table[Handle, RegexAction]
|
let handlers = newTable[Handle, RegexAction]()
|
||||||
during(turn, root, ?UriRunnerConfig) do (handlerspace: Ref, urispace: Ref):
|
during(turn, root, ?UriRunnerConfig) do (handlerspace: Cap, urispace: Cap):
|
||||||
|
|
||||||
during(turn, handlerspace, dropType(ActionHandler)) do:
|
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
|
# `duringHandle` is a symbol exposed by the `during` macro
|
||||||
handlers[duringHandle] = (re(pat, {reIgnoreCase, reStudy}), entity, act,)
|
handlers[duringHandle] = (re(pat, {reIgnoreCase, reStudy}), entity, act,)
|
||||||
do:
|
do:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "20230630"
|
version = "20231010"
|
||||||
author = "Emery"
|
author = "Emery"
|
||||||
description = "Syndicated open command"
|
description = "Syndicated open command"
|
||||||
license = "Unlicense"
|
license = "Unlicense"
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
<require-service <daemon uri_runner>>
|
|
||||||
|
|
||||||
; configure the daemon when it is built
|
; configure the daemon when it is built
|
||||||
; (this is an artifact of the author's build system)
|
; (this is an artifact of the author's build system)
|
||||||
? <built uri_runner ?path ?hash> [
|
? <built uri_runner ?path ?hash> [
|
||||||
|
|
Loading…
Reference in New Issue