Fix supervised credentials and declare typed RPC records for canvas placement
This commit is contained in:
@@ -4,6 +4,27 @@ import { referenceFromWire } from "../dist/references.js";
|
||||
import { bindQxHandler, decodeQxValue, encodeQxValue, jsToProtoValue, liveValue, protoValueToJs } from "../dist/index.js";
|
||||
const scalar = (name) => ({ kind: "scalar", name });
|
||||
const unit = { kind: "builtin", name: "unit" };
|
||||
test("declared record inputs preserve opaque references without opening message codecs", async () => {
|
||||
const target = referenceFromWire("obj:board");
|
||||
const type = {kind: "record", fields: {
|
||||
target: {kind: "object-ref", expectation: {kind: "atom", atomId: "board"}},
|
||||
x: scalar("double"), note: {kind: "optional", value: scalar("string")},
|
||||
}};
|
||||
const encoded = encodeQxValue(type, {target, x: 12}, {});
|
||||
const decoded = decodeQxValue(type, encoded, {});
|
||||
assert.ok(decoded.target.equals(target));
|
||||
assert.equal(decoded.x, 12);
|
||||
assert.equal(decoded.note, null);
|
||||
assert.throws(() => JSON.stringify(decoded), /cannot be serialized/);
|
||||
assert.throws(() => encodeQxValue(type, {target, x: 12, hidden: target}, {}), /Unexpected/);
|
||||
assert.throws(() => encodeQxValue(type, {x: 12}, {}), /Missing/);
|
||||
assert.throws(() => encodeQxValue(type, {target: "obj:board", x: 12}, {}), /opaque object reference/);
|
||||
const handler = bindQxHandler({inputType: type, outputType: unit, ports: {}}, async (context) => {
|
||||
assert.ok(context.input.target.equals(target));
|
||||
assert.equal(context.input.x, 12);
|
||||
}, {});
|
||||
await handler({objectId: target, inputProto: encoded.kind.value.fields});
|
||||
});
|
||||
test("typed sessions rebind ports and cancellation to each acquired invocation", async () => {
|
||||
const first = new AbortController(), second = new AbortController();
|
||||
let closed = false;
|
||||
|
||||
Reference in New Issue
Block a user