import { jsonSchema } from "../../shared/src/json-schema.js";
import { readonly } from "../../shared/src/valita.js";
import { astSchema } from "./ast.js";
import { transformFailedBodySchema } from "./error.js";
import { array, object, string, literal, union, tuple } from "@badrap/valita";
const transformRequestBodySchema = array(
  object({
    id: string(),
    name: string(),
    args: readonly(array(jsonSchema))
  })
);
const transformedQuerySchema = object({
  id: string(),
  name: string(),
  ast: astSchema
});
const appErroredQuerySchema = object({
  error: literal("app"),
  id: string(),
  name: string(),
  // optional for backwards compatibility
  message: string().optional(),
  details: jsonSchema.optional()
});
const parseErroredQuerySchema = object({
  error: literal("parse"),
  id: string(),
  name: string(),
  message: string(),
  details: jsonSchema.optional()
});
const erroredQuerySchema = union(
  appErroredQuerySchema,
  parseErroredQuerySchema
);
const transformResponseBodySchema = array(
  union(transformedQuerySchema, erroredQuerySchema)
);
const transformRequestMessageSchema = tuple([
  literal("transform"),
  transformRequestBodySchema
]);
const transformErrorMessageSchema = tuple([
  literal("transformError"),
  array(erroredQuerySchema)
]);
const transformFailedMessageSchema = tuple([
  literal("transformFailed"),
  transformFailedBodySchema
]);
const transformOkMessageSchema = tuple([
  literal("transformed"),
  transformResponseBodySchema
]);
const transformResponseMessageSchema = union(
  transformOkMessageSchema,
  transformFailedMessageSchema
);
export {
  appErroredQuerySchema,
  erroredQuerySchema,
  parseErroredQuerySchema,
  transformErrorMessageSchema,
  transformRequestBodySchema,
  transformRequestMessageSchema,
  transformResponseBodySchema,
  transformResponseMessageSchema,
  transformedQuerySchema
};
//# sourceMappingURL=custom-queries.js.map
