Add lightweight correctness linting and resolve formatting conflicts
This commit is contained in:
Vendored
+72
-22
@@ -1,6 +1,6 @@
|
||||
import { create } from "@bufbuild/protobuf";
|
||||
import { ValueSchema, ObjectValueSchema } from "./camino/api_pb.js";
|
||||
import { derived, jsToProtoValue, liveValue, protoValueToJs } from "./index.js";
|
||||
import { derived, jsToProtoValue, liveValue, protoValueToJs, } from "./index.js";
|
||||
import { assertReferenceFree, referenceToWire } from "./references.js";
|
||||
const reactPropsDescriptor = "org.quixos.web-studio.ReactProps";
|
||||
// Explicit temporary props exception, matching orch's RPC contract. Field shapes
|
||||
@@ -111,8 +111,9 @@ export const encodeQxValue = (type, value, messages) => {
|
||||
};
|
||||
const inputValue = (context, type) => {
|
||||
if (type.kind === "message" || type.kind === "record")
|
||||
return create(ValueSchema, { kind: { case: "objectValue",
|
||||
value: create(ObjectValueSchema, { fields: context.inputProto }) } });
|
||||
return create(ValueSchema, {
|
||||
kind: { case: "objectValue", value: create(ObjectValueSchema, { fields: context.inputProto }) },
|
||||
});
|
||||
return context.inputProto.value;
|
||||
};
|
||||
const inputFields = (type, value, messages) => {
|
||||
@@ -133,37 +134,86 @@ export const bindQxHandler = (spec, handler, messages) => {
|
||||
switch (port.kind) {
|
||||
case "state": {
|
||||
const state = raw.state(port.id);
|
||||
return [name, {
|
||||
...(port.primitives.includes("read") ? { get: async () => decodeQxValue(port.valueType, (await state.live()).$quixosValue, messages), live: () => state.live() } : {}),
|
||||
...(port.primitives.includes("write") ? { set: async (value) => state.set(liveValue(encodeQxValue(port.valueType, value, messages))) } : {}),
|
||||
}];
|
||||
return [
|
||||
name,
|
||||
{
|
||||
...(port.primitives.includes("read")
|
||||
? {
|
||||
get: async () => decodeQxValue(port.valueType, (await state.live()).$quixosValue, messages),
|
||||
live: () => state.live(),
|
||||
}
|
||||
: {}),
|
||||
...(port.primitives.includes("write")
|
||||
? {
|
||||
set: async (value) => state.set(liveValue(encodeQxValue(port.valueType, value, messages))),
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
];
|
||||
}
|
||||
case "edge": {
|
||||
const edge = raw.edge(port.id);
|
||||
return [name, { ...Object.fromEntries(port.primitives.map((primitive) => [primitive, edge[primitive]])),
|
||||
return [
|
||||
name,
|
||||
{
|
||||
...Object.fromEntries(port.primitives.map((primitive) => [
|
||||
primitive,
|
||||
edge[primitive],
|
||||
])),
|
||||
...(port.primitives.includes("resolve") ? { collection: edge.collection } : {}),
|
||||
...(port.primitives.includes("resolve") && port.primitives.includes("connect") && port.primitives.includes("disconnect") ? { replace: edge.replace } : {}) }];
|
||||
...(port.primitives.includes("resolve") &&
|
||||
port.primitives.includes("connect") &&
|
||||
port.primitives.includes("disconnect")
|
||||
? { replace: edge.replace }
|
||||
: {}),
|
||||
},
|
||||
];
|
||||
}
|
||||
case "interface": {
|
||||
const target = raw.interface(port.id);
|
||||
return [name, { objectId: target.objectId,
|
||||
live: Object.fromEntries(Object.entries(port.operations).map(([name, operation]) => [name,
|
||||
return [
|
||||
name,
|
||||
{
|
||||
objectId: target.objectId,
|
||||
live: Object.fromEntries(Object.entries(port.operations).map(([name, operation]) => [
|
||||
name,
|
||||
(input) => target.live(operation.id, inputFields(operation.inputType, input, messages)),
|
||||
])),
|
||||
...Object.fromEntries(Object.entries(port.operations).map(([name, operation]) => [name,
|
||||
async (input) => decodeQxValue(operation.outputType, (await target.live(operation.id, inputFields(operation.inputType, input, messages))).$quixosValue, messages),
|
||||
])) }];
|
||||
...Object.fromEntries(Object.entries(port.operations).map(([name, operation]) => [
|
||||
name,
|
||||
async (input) => decodeQxValue(operation.outputType, (await target.live(operation.id, inputFields(operation.inputType, input, messages)))
|
||||
.$quixosValue, messages),
|
||||
])),
|
||||
},
|
||||
];
|
||||
}
|
||||
case "constructor": return [name, { construct: (input) => raw.constructor(port.id).construct(inputFields(port.inputType, input, messages)) }];
|
||||
case "constructor":
|
||||
return [
|
||||
name,
|
||||
{
|
||||
construct: (input) => raw.constructor(port.id).construct(inputFields(port.inputType, input, messages)),
|
||||
},
|
||||
];
|
||||
}
|
||||
}));
|
||||
return { objectId: raw.objectId, signal: raw.signal,
|
||||
...(raw.openSession ? { openSession: async () => {
|
||||
const session = await raw.openSession();
|
||||
return { id: session.id, close: () => session.close(),
|
||||
run: (work) => session.run((next) => work(bindContext(next))) };
|
||||
} } : {}),
|
||||
input: decodeQxValue(spec.inputType, inputValue(raw, spec.inputType), messages), ports };
|
||||
return {
|
||||
objectId: raw.objectId,
|
||||
signal: raw.signal,
|
||||
...(raw.openSession
|
||||
? {
|
||||
openSession: async () => {
|
||||
const session = await raw.openSession();
|
||||
return {
|
||||
id: session.id,
|
||||
close: () => session.close(),
|
||||
run: (work) => session.run((next) => work(bindContext(next))),
|
||||
};
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
input: decodeQxValue(spec.inputType, inputValue(raw, spec.inputType), messages),
|
||||
ports,
|
||||
};
|
||||
};
|
||||
const execute = async (raw) => {
|
||||
const context = bindContext(raw);
|
||||
|
||||
Reference in New Issue
Block a user