import * as v from "../../../shared/src/valita.js";
import * as PostgresReplicaIdentity from "./postgres-replica-identity-enum.js";
import * as PostgresTypeClass from "./postgres-type-class-enum.js";
export const pgTypeClassSchema = v.literalUnion(PostgresTypeClass.Base, PostgresTypeClass.Composite, PostgresTypeClass.Domain, PostgresTypeClass.Enum, PostgresTypeClass.Pseudo, PostgresTypeClass.Range, PostgresTypeClass.Multirange);
export const pgReplicaIdentitySchema = v.literalUnion(PostgresReplicaIdentity.Default, PostgresReplicaIdentity.Nothing, PostgresReplicaIdentity.Full, PostgresReplicaIdentity.Index);
export const columnSpec = v.object({
    pos: v.number(),
    dataType: v.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: v.number().nullable().optional(),
    notNull: v.boolean().nullable().optional(),
    dflt: v.string().nullable().optional(),
});
const publishedColumnSpec = columnSpec.extend({
    typeOID: v.number(),
});
export const liteTableSpec = v.object({
    name: v.string(),
    columns: v.record(columnSpec),
    primaryKey: v.array(v.string()).optional(),
});
export const tableSpec = liteTableSpec.extend({
    schema: v.string(),
});
export const publishedTableSpec = tableSpec.extend({
    oid: v.number(),
    columns: v.record(publishedColumnSpec),
    replicaIdentity: pgReplicaIdentitySchema.optional(),
    publications: v.record(v.object({ rowFilter: v.string().nullable() })),
});
export const directionSchema = v.literalUnion('ASC', 'DESC');
export const liteIndexSpec = v.object({
    name: v.string(),
    tableName: v.string(),
    unique: v.boolean(),
    columns: v.record(directionSchema),
});
export const indexSpec = liteIndexSpec.extend({
    schema: v.string(),
});
export const publishedIndexSpec = indexSpec.extend({
    isReplicaIdentity: v.boolean().optional(),
    isImmediate: v.boolean().optional(),
});
//# sourceMappingURL=specs.js.map