Migrate TODO implementations to generated candidate bindings
This commit is contained in:
+18
-2
@@ -1,9 +1,22 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { referenceFromWire } from "../dist/references.js";
|
||||
import { bindQxHandler, decodeQxValue, encodeQxValue, jsToProtoValue, liveValue, protoValueToJs } from "../dist/index.js";
|
||||
import { bindQxHandler, decodeQxValue, encodeQxValue, jsToProtoValue, liveValue, protoValueToJs, opaqueReactPropsBinding } from "../dist/index.js";
|
||||
const scalar = (name) => ({ kind: "scalar", name });
|
||||
const unit = { kind: "builtin", name: "unit" };
|
||||
test("opaque React props retain managed references while ordinary messages remain closed", () => {
|
||||
const descriptorId = "org.quixos.web-studio.ReactProps";
|
||||
const reference = referenceFromWire("obj:task");
|
||||
const type = {kind: "message", descriptorId};
|
||||
const messages = {[descriptorId]: opaqueReactPropsBinding};
|
||||
const decoded = decodeQxValue(type, encodeQxValue(type, {subject: reference, title: "Task"}, messages), messages);
|
||||
assert.ok(decoded.subject.equals(reference));
|
||||
assert.equal(decoded.title, "Task");
|
||||
assert.throws(() => opaqueReactPropsBinding.encode(null), /object/);
|
||||
assert.throws(() => opaqueReactPropsBinding.encode([]), /object/);
|
||||
assert.throws(() => encodeQxValue({kind: "message", descriptorId: "Ordinary"}, {subject: reference},
|
||||
{Ordinary: opaqueReactPropsBinding}), /Managed references/);
|
||||
});
|
||||
test("declared record inputs preserve opaque references without opening message codecs", async () => {
|
||||
const target = referenceFromWire("obj:board");
|
||||
const type = {kind: "record", fields: {
|
||||
@@ -77,6 +90,9 @@ test("typed state and interface ports preserve declared values and exact operati
|
||||
const handler = bindQxHandler(spec, async ({ input, ports }) => {
|
||||
assert.equal(input, 2n ** 60n);
|
||||
assert.equal(await ports.data.get(), 9n);
|
||||
assert.deepEqual((await ports.data.live()).$quixosValue, jsToProtoValue(9n));
|
||||
assert.ok(ports.reader.objectId.equals(referenceFromWire("obj:reader")));
|
||||
assert.deepEqual((await ports.reader.live["payload.get"]()).$quixosValue, jsToProtoValue(new Uint8Array([7])));
|
||||
await ports.data.set(input);
|
||||
return ports.reader["payload.get"]();
|
||||
}, {});
|
||||
@@ -84,7 +100,7 @@ test("typed state and interface ports preserve declared values and exact operati
|
||||
state: (id) => { assert.equal(id, "state-id"); return {
|
||||
live: async () => liveValue(jsToProtoValue(9n)), set: async (value) => { written = value; },
|
||||
}; },
|
||||
interface: (id) => { assert.equal(id, "interface-id"); return { live: async (operation, input) => {
|
||||
interface: (id) => { assert.equal(id, "interface-id"); return { objectId: referenceFromWire("obj:reader"), live: async (operation, input) => {
|
||||
assert.equal(operation, "get-id"); assert.deepEqual(input, {}); return liveValue(jsToProtoValue(new Uint8Array([7])));
|
||||
} }; },
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user