import { readonlyObject, literalUnion, readonly } from "../../shared/src/valita.js";
import { compoundKeySchema } from "../../zero-protocol/src/ast.js";
import { valueTypeSchema } from "../../zero-protocol/src/client-schema.js";
import { primaryKeySchema } from "../../zero-protocol/src/primary-key.js";
import "./compiled-permissions.js";
import { string, union, tuple, boolean, record } from "@badrap/valita";
const relationshipPart = readonlyObject({
  sourceField: compoundKeySchema,
  destField: compoundKeySchema,
  destSchema: string(),
  cardinality: literalUnion("one", "many")
});
const relationshipSchema = union(
  readonly(tuple([relationshipPart])),
  readonly(tuple([relationshipPart, relationshipPart]))
);
const schemaValueSchema = readonlyObject({
  type: valueTypeSchema,
  serverName: string().optional(),
  optional: boolean().optional()
});
const tableSchemaSchema = readonlyObject({
  name: string(),
  serverName: string().optional(),
  columns: record(schemaValueSchema),
  primaryKey: primaryKeySchema
});
readonlyObject({
  tables: record(tableSchemaSchema),
  relationships: record(record(relationshipSchema)),
  enableLegacyQueries: boolean().optional(),
  enableLegacyMutators: boolean().optional()
});
function isSchemaConfig(value) {
  return value != null && "schema" in value;
}
export {
  isSchemaConfig,
  relationshipSchema,
  schemaValueSchema,
  tableSchemaSchema
};
//# sourceMappingURL=schema-config.js.map
