Standardize Camino query references and retire live field sidecars
This commit is contained in:
@@ -76,13 +76,10 @@ export function generatePortableClientBindings(
|
||||
const operations = query.operations.map(
|
||||
(key) => plan.definition.operations.find((operation) => operation.key === key)!,
|
||||
);
|
||||
const live = (selections: readonly QuerySelection[]): boolean =>
|
||||
selections.some((selection) => !!selection.liveSelectionId || live(selection.selection));
|
||||
if (
|
||||
operations.some(
|
||||
(operation) => operation.execution.kind !== "snapshot" || !operation.execution.targets.includes("server"),
|
||||
) ||
|
||||
live(query.query.checked.selection)
|
||||
)
|
||||
) {
|
||||
unavailable.push({ key: query.id, reason: "QUERY_NOT_SNAPSHOT_PROJECTION" });
|
||||
continue;
|
||||
|
||||
+1
-19
@@ -1,6 +1,5 @@
|
||||
import type { BindingSchema } from "./index.js";
|
||||
import type { ValueType } from "../capability-model/types.js";
|
||||
import { queryPresentation } from "../query/presentation.js";
|
||||
|
||||
/** Browser projection of the SAME checked RPC types, not a second props schema. */
|
||||
export function generateReactBindings(
|
||||
@@ -131,25 +130,9 @@ export function generateReactBindings(
|
||||
return type(value);
|
||||
};
|
||||
const queries = pkg.checkedQueries ?? [];
|
||||
const presentedType = (
|
||||
value: ValueType,
|
||||
fields: ReturnType<typeof queryPresentation>,
|
||||
path: string[] = [],
|
||||
): string => {
|
||||
const field = fields.find((field) => JSON.stringify(field.path) === JSON.stringify(path));
|
||||
if (field)
|
||||
return `${field.conditions.length ? "(" : ""}${field.setOperationId ? "WritableQueryField" : "QueryField"}<${type(field.valueType)}>${field.conditions.length ? " | null)" : ""}`;
|
||||
if (value.kind === "optional") return `(${presentedType(value.value, fields, path)} | null)`;
|
||||
if (value.kind === "list") return `Array<${presentedType(value.value, fields, [...path, "*"])}>`;
|
||||
if (value.kind === "record")
|
||||
return `{${Object.entries(value.fields)
|
||||
.map(([key, child]) => `${q(key)}: ${presentedType(child, fields, [...path, key])}`)
|
||||
.join(";")}}`;
|
||||
return queryType(value);
|
||||
};
|
||||
const queryCode =
|
||||
`export type QueryVariables = {${queries.map((query) => `${q(query.declaration.displayName)}: ${queryType(query.variables)}`).join(";")}};\n` +
|
||||
`export type QueryResults = {${queries.map((query) => `${q(query.declaration.displayName)}: ${presentedType(query.output, queryPresentation(query, schema.interfaces))}`).join(";")}};\n` +
|
||||
`export type QueryResults = {${queries.map((query) => `${q(query.declaration.displayName)}: ${queryType(query.output)}`).join(";")}};\n` +
|
||||
`export const queries: {${queries.map((query) => `${q(query.declaration.displayName)}: QueryDescriptor<QueryVariables[${q(query.declaration.displayName)}], QueryResults[${q(query.declaration.displayName)}], ${q(query.declaration.root.kind)}>`).join(";")}} = ${JSON.stringify(
|
||||
Object.fromEntries(
|
||||
queries.map((query) => [
|
||||
@@ -160,7 +143,6 @@ export function generateReactBindings(
|
||||
root: query.declaration.root,
|
||||
variables: query.variables,
|
||||
output: query.output,
|
||||
liveFields: queryPresentation(query, schema.interfaces),
|
||||
watch: query.declaration.watch,
|
||||
},
|
||||
]),
|
||||
|
||||
Reference in New Issue
Block a user