defaultSchemas function

List<String> defaultSchemas({
  1. Map<String, String>? environment,
  2. Directory? startDirectory,
})

The schemas supabase gen types generates for when none are named: the api.schemas of the project's supabase/config.toml, always including public.

The configuration is looked up the way the Supabase CLI does: under SUPABASE_WORKDIR when that variable is set, otherwise in startDirectory, which defaults to the current directory, or the nearest parent of it holding a supabase/config.toml. Without a configuration file only public is returned, sorted like every other schema list.

Throws a FormatException when the file exists but is not valid TOML or api.schemas is not a list of strings.

Implementation

List<String> defaultSchemas({
  Map<String, String>? environment,
  Directory? startDirectory,
}) {
  final workingDirectory =
      (environment ?? Platform.environment)['SUPABASE_WORKDIR'];
  final configFile = workingDirectory == null
      ? _nearestConfigFile(startDirectory ?? Directory.current)
      : File('$workingDirectory/supabase/config.toml');
  final schemas = {'public'};
  if (configFile != null && configFile.existsSync()) {
    schemas.addAll(_exposedSchemas(configFile));
  }
  return schemas.toList()..sort();
}