import { literalUnion } from "../../../shared/src/valita.js";
import { Index, Full, Nothing, Default } from "./postgres-replica-identity-enum.js";
import { Multirange, Range, Pseudo, Enum, Domain, Composite, Base } from "./postgres-type-class-enum.js";
import { object, string, boolean, number, array, record } from "@badrap/valita";
const pgTypeClassSchema = literalUnion(
  Base,
  Composite,
  Domain,
  Enum,
  Pseudo,
  Range,
  Multirange
);
const pgReplicaIdentitySchema = literalUnion(
  Default,
  Nothing,
  Full,
  Index
);
const columnSpec = object({
  pos: number(),
  dataType: string(),
  pgTypeClass: pgTypeClassSchema.optional(),
  // If the column is an array, this will be the type of the
  // elements in the array. If the column is not an array,
  // this will be null.
  elemPgTypeClass: pgTypeClassSchema.nullable().optional(),
  characterMaximumLength: number().nullable().optional(),
  notNull: boolean().nullable().optional(),
  dflt: string().nullable().optional()
});
const publishedColumnSpec = columnSpec.extend({
  typeOID: number()
});
const liteTableSpec = object({
  name: string(),
  columns: record(columnSpec),
  primaryKey: array(string()).optional()
});
const tableSpec = liteTableSpec.extend({
  schema: string()
});
const publishedTableSpec = tableSpec.extend({
  oid: number(),
  // Always present for new instances (e.g. from DDL triggers), but
  // may from `initialSchema` object stored in the `replicas` table.
  schemaOID: number().optional(),
  columns: record(publishedColumnSpec),
  replicaIdentity: pgReplicaIdentitySchema.optional(),
  publications: record(object({ rowFilter: string().nullable() }))
});
const directionSchema = literalUnion("ASC", "DESC");
const liteIndexSpec = object({
  name: string(),
  tableName: string(),
  unique: boolean(),
  columns: record(directionSchema)
});
const indexSpec = liteIndexSpec.extend({
  schema: string()
});
const publishedIndexSpec = indexSpec.extend({
  isReplicaIdentity: boolean().optional(),
  isPrimaryKey: boolean().optional(),
  isImmediate: boolean().optional()
});
export {
  columnSpec,
  directionSchema,
  indexSpec,
  liteIndexSpec,
  liteTableSpec,
  pgTypeClassSchema,
  publishedIndexSpec,
  publishedTableSpec,
  tableSpec
};
//# sourceMappingURL=specs.js.map
