Generate typed QX bindings and add source editing tools
This commit is contained in:
Vendored
+76
@@ -0,0 +1,76 @@
|
||||
import { type Value } from "./camino/api_pb.js";
|
||||
import { type RuntimeHandler, type DerivedHandler } from "./index.js";
|
||||
declare const referenceBrand: unique symbol;
|
||||
export type QxObjectRef<Identity extends string> = string & {
|
||||
readonly [referenceBrand]: {
|
||||
readonly [K in Identity]: true;
|
||||
};
|
||||
};
|
||||
declare const watchBrand: unique symbol;
|
||||
export type QxWatchHandle = string & {
|
||||
readonly [watchBrand]: true;
|
||||
};
|
||||
export type MessageBinding<T> = {
|
||||
encode(value: T): Value;
|
||||
decode(value: Value): T;
|
||||
};
|
||||
export type BindingValue<B> = B extends MessageBinding<infer T> ? T : never;
|
||||
export type QxHandler<C, O> = (context: C) => O | Promise<O>;
|
||||
export type QxDerived<C, O> = {
|
||||
kind: "derived";
|
||||
get: QxHandler<C, O>;
|
||||
};
|
||||
export declare const qxDerived: <C, O>(get: QxHandler<C, O>) => QxDerived<C, O>;
|
||||
/** Versioned binding ABI. This mirrors the language-neutral value IR. */
|
||||
export type QxValueType = {
|
||||
kind: "builtin";
|
||||
name: "unit" | "watch-handle";
|
||||
} | {
|
||||
kind: "scalar";
|
||||
name: string;
|
||||
} | {
|
||||
kind: "message";
|
||||
descriptorId: string;
|
||||
} | {
|
||||
kind: "object-ref";
|
||||
expectation: unknown;
|
||||
} | {
|
||||
kind: "optional" | "list";
|
||||
value: QxValueType;
|
||||
};
|
||||
export type QxOperationSpec = {
|
||||
id: string;
|
||||
inputType: QxValueType;
|
||||
outputType: QxValueType;
|
||||
};
|
||||
export type QxPortSpec = {
|
||||
kind: "state";
|
||||
id: string;
|
||||
valueType: QxValueType;
|
||||
primitives: string[];
|
||||
} | {
|
||||
kind: "edge";
|
||||
id: string;
|
||||
primitives: string[];
|
||||
} | {
|
||||
kind: "interface";
|
||||
id: string;
|
||||
operations: Record<string, QxOperationSpec>;
|
||||
} | {
|
||||
kind: "constructor";
|
||||
id: string;
|
||||
inputType: QxValueType;
|
||||
};
|
||||
export type QxHandlerSpec = {
|
||||
inputType: QxValueType;
|
||||
outputType: QxValueType;
|
||||
eventType?: QxValueType;
|
||||
ports: Record<string, QxPortSpec>;
|
||||
};
|
||||
export type QxMessages = Record<string, MessageBinding<any>>;
|
||||
export declare const decodeQxValue: (type: QxValueType, value: Value | undefined, messages: QxMessages) => any;
|
||||
export declare const encodeQxValue: (type: QxValueType, value: any, messages: QxMessages) => Value;
|
||||
/** The sole unchecked cast connects generated contracts to the dynamic RPC runtime. */
|
||||
export declare const bindQxHandler: <C, O>(spec: QxHandlerSpec, handler: QxHandler<C, O> | QxDerived<C, O>, messages: QxMessages) => RuntimeHandler | DerivedHandler;
|
||||
export {};
|
||||
//# sourceMappingURL=bindings.d.ts.map
|
||||
Reference in New Issue
Block a user