import "../../shared/src/valita.js";
import { mutationsPatchSchema } from "./mutations-patch.js";
import { queriesPatchSchema } from "./queries-patch.js";
import { rowsPatchSchema } from "./row-patch.js";
import { nullableVersionSchema, versionSchema } from "./version.js";
import { object, number, string, record, boolean, tuple, literal } from "@badrap/valita";
const pokeStartBodySchema = object({
  pokeID: string(),
  // We always specify a Version as our cookie, but Replicache starts clients
  // with initial cookie `null`, before the first request. So we have to be
  // able to send a base cookie with value `null` to match that state.
  baseCookie: nullableVersionSchema,
  /**
   * This field is always set if the poke contains a `rowsPatch`.
   * It may be absent for patches that only update clients and queries.
   */
  schemaVersions: object({
    minSupportedVersion: number(),
    maxSupportedVersion: number()
  }).optional(),
  timestamp: number().optional()
});
const pokePartBodySchema = object({
  pokeID: string(),
  // Changes to last mutation id by client id.
  lastMutationIDChanges: record(number()).optional(),
  // Patches to the desired query sets by client id.
  desiredQueriesPatches: record(queriesPatchSchema).optional(),
  // Patches to the set of queries for which entities are sync'd in
  // rowsPatch.
  gotQueriesPatch: queriesPatchSchema.optional(),
  // Patches to the rows set.
  rowsPatch: rowsPatchSchema.optional(),
  // Mutation results patch
  mutationsPatch: mutationsPatchSchema.optional()
});
const pokeEndBodySchema = object({
  pokeID: string(),
  // Note: This should be ignored (and may be empty) if cancel === `true`.
  cookie: versionSchema,
  // If `true`, the poke with id `pokeID` should be discarded without
  // applying it.
  cancel: boolean().optional()
});
const pokeStartMessageSchema = tuple([
  literal("pokeStart"),
  pokeStartBodySchema
]);
const pokePartMessageSchema = tuple([
  literal("pokePart"),
  pokePartBodySchema
]);
const pokeEndMessageSchema = tuple([
  literal("pokeEnd"),
  pokeEndBodySchema
]);
export {
  pokeEndBodySchema,
  pokeEndMessageSchema,
  pokePartBodySchema,
  pokePartMessageSchema,
  pokeStartBodySchema,
  pokeStartMessageSchema
};
//# sourceMappingURL=poke.js.map
