parse method

SchemaTypeOverrides parse(
  1. Object? node
)

Parses the types: node (a map, or null when absent).

Implementation

SchemaTypeOverrides parse(Object? node) {
  if (node == null) return const SchemaTypeOverrides.empty();
  if (node is! Map) {
    throw StateError('basalt.yaml: `types:` must be a mapping.');
  }
  for (final key in node.keys) {
    if (key != 'columns' && key != 'native' && key != 'canonical') {
      throw StateError(
        "basalt.yaml: unknown key 'types.$key' "
        '(expected: columns, native, canonical).',
      );
    }
  }

  return SchemaTypeOverrides(
    byColumn: _stringSection(node['columns'], 'types.columns', (k) => k),
    byNative:
        _stringSection(node['native'], 'types.native', normalizeNativeType),
    byCanonical: _canonicalSection(node['canonical']),
  );
}