Implement query execution, scoped RPC enrichment, live collections, and scaffold integration
This commit is contained in:
+26
-1
@@ -9,6 +9,7 @@ import {
|
||||
type QxObjectRef,
|
||||
} from "./references.js";
|
||||
export * from "./bindings.js";
|
||||
export * from "./queries.js";
|
||||
export { relationshipMap, relationshipList, relationshipSet } from "./relationships.js";
|
||||
import { AsyncLocalStorage } from "node:async_hooks";
|
||||
import { createHmac, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
||||
@@ -33,6 +34,7 @@ import {
|
||||
RefValueSchema,
|
||||
ValueSchema,
|
||||
type Value,
|
||||
type QueryResponse,
|
||||
} from "./camino/api_pb.js";
|
||||
import { OrchestratorRuntime } from "./quixos/orch_pb.js";
|
||||
import {
|
||||
@@ -197,7 +199,16 @@ export type ConstructorPort = {
|
||||
atomId: string;
|
||||
construct(input?: Record<string, unknown>): Promise<QxObjectRef>;
|
||||
};
|
||||
export type RuntimePort = StatePort | EdgePort | InterfacePort | ConstructorPort;
|
||||
export type QueryPort = {
|
||||
queryId: string;
|
||||
execute(variables: Record<string, Value>, expectedDefinitionDigest?: string): Promise<QueryResponse>;
|
||||
watch(
|
||||
variables: Record<string, Value>,
|
||||
signal: AbortSignal,
|
||||
expectedDefinitionDigest?: string,
|
||||
): AsyncIterable<import("./quixos/orch_pb.js").QueryEvent>;
|
||||
};
|
||||
export type RuntimePort = StatePort | EdgePort | InterfacePort | ConstructorPort | QueryPort;
|
||||
|
||||
export type RuntimeContext = {
|
||||
tryConform(object: QxObjectRef, interfaceRevisionId: string): Promise<InterfacePort | undefined>;
|
||||
@@ -212,6 +223,7 @@ export type RuntimeContext = {
|
||||
edge(portId: string): EdgePort;
|
||||
interface(portId: string): InterfacePort;
|
||||
constructor(portId: string): ConstructorPort;
|
||||
query(portId: string): QueryPort;
|
||||
};
|
||||
|
||||
export type RuntimeSession = {
|
||||
@@ -273,6 +285,18 @@ export const createRuntimeContext = (
|
||||
const ports = new Map<string, RuntimePort>();
|
||||
for (const dependency of request.dependencies) {
|
||||
switch (dependency.binding.case) {
|
||||
case "queryId": {
|
||||
const queryId = dependency.binding.value,
|
||||
objectId = dependency.objectId || request.objectId;
|
||||
ports.set(dependency.portId, {
|
||||
queryId,
|
||||
execute: (variables, expectedDefinitionDigest) =>
|
||||
orch.executeQuery({ queryId, objectId, variables, expectedDefinitionDigest }),
|
||||
watch: (variables, signal, expectedDefinitionDigest) =>
|
||||
orch.watchQuery({ queryId, objectId, variables, expectedDefinitionDigest }, { signal }),
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "stateSlotId": {
|
||||
const slotId = dependency.binding.value;
|
||||
const dependencyObjectId = dependency.objectId || request.objectId;
|
||||
@@ -421,6 +445,7 @@ export const createRuntimeContext = (
|
||||
edge: (portId: string) => requirePort<EdgePort>(portId, "edgeTypeId"),
|
||||
interface: (portId: string) => requirePort<InterfacePort>(portId, "interfaceRevisionId"),
|
||||
constructor: (portId: string) => requirePort<ConstructorPort>(portId, "atomId"),
|
||||
query: (portId: string) => requirePort<QueryPort>(portId, "queryId"),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user