informatics-isi-edu / ermrestjs

ERMrest client library in JavaScript
Apache License 2.0
4 stars 3 forks source link

Implement table-defaults annotation #997

Open RFSH opened 1 year ago

RFSH commented 1 year ago

Similar to how column-defaults allows us to define bulk column-level annotations, table-defaults would allow us to define annotations for multiple tables on the schema or catalog.

This came up before as part of #982, but I decided to create a separate issue since it would be useful for other use cases as well. For example, this would allow us to change the default sort order to be based on RCT.

This annotation must be more complicated than column-defaults and have a mix-and-match logic (if the rules make sense, we can update column-defaults later as well). Instead of just having simple by_name property, we will introduce a selectors property that matches the definitions.

{
  "tag:isrd.isi.edu,2023:table-defaults": [
    {
      "selectors": [
        {
          "schema_pattern": "",
          "schema_names": "" | [],
          "table_pattern": "",
          "table_names": "" | [],
        }, 
        // ... other selectors
      ],
      "default": {
         // annotations go here
      }
    }
    // ... other defaults
  ]
}

The following is how we will apply the annotations in each "default" object to the current table:

For the current case to work, we must merge the source-definitions of table-defaults with the local annotation on the table. In contrast, in column-defaults, local annotations of a column would simply replace the column-defaults ones. Requires more thought. I need to write down the rules, and then we need to discuss and finalize them. Because of this, we cannot allow all the annotation keys in this new annotation and have to explicitly explain which annotations and how they are supported.