Other languages
The same two evaluations from Python, Node.js, Ruby, PHP, Java, shell, Rust, C# and PowerShell through the command, and from Node.js and Python through the WebAssembly module.
Code: examples/engine-clients
(README). Every client starts the engine once, sends
version, loads the payments bundle, evaluates two requests and prints exactly
expected-output.txt:
engine: Rule Cascade 1.0.0, bundle format 1.0.0
loaded: acme.payments.transfer 1.0.0
domestic transfer: allow
warning ORG-TRF-003 Adding a memo makes this transfer easier to reconcile.
blocked country: deny
error ORG-TRF-001 Transfers to KP are not permitted.The core of each client is one function: write a request line, read a response line, check it.
From process/client.py:
def call(self, command, **members):
self.sent += 1
line = json.dumps({"id": self.sent, "command": command, **members}, ensure_ascii=False)
try:
self.process.stdin.write(line.encode("utf-8") + b"\n")
self.process.stdin.flush()
except OSError:
fail("the engine closed its input")
answer = self.process.stdout.readline() # a whole line, however long
if not answer:
fail("the engine closed its output")
response = json.loads(answer)
if response.get("id") != self.sent:
fail("expected the response to request %d, got %r" % (self.sent, response.get("id")))
if response.get("ok") is not True:
error = response.get("error") or {}
fail("%s: %s" % (error.get("code"), error.get("message")))
return response["result"]PHP, Java, shell, Rust, C# and PowerShell follow the same shape in process/; wasm/client.mjs
and wasm/client.py run the WebAssembly module inside the client's own process.
Run them
cd packages/go && go build -o dist/rule-cascade ./cmd/rule-cascade && cd ../..
sh examples/engine-clients/run-all.sh # every client whose language is installedOr one client:
RULE_CASCADE_ENGINE=$PWD/packages/go/dist/rule-cascade \
python3 examples/engine-clients/process/client.py conformance/bundles/acme.payments.transfer.bundle.jsonCI runs the Python, Node.js, Ruby, PHP, Java, shell and Rust clients and both WebAssembly clients
on Linux. Client.cs and client.ps1 were written against the documented behaviour of .NET and
PowerShell and have not been executed.
Step by step: Run rules from any other language.