Skip to content

api types: Mark most remaining types read-only#4957

Merged
chrisbobbe merged 4 commits intozulip:masterfrom
gnprice:pr-api-types-ro
Aug 13, 2021
Merged

api types: Mark most remaining types read-only#4957
chrisbobbe merged 4 commits intozulip:masterfrom
gnprice:pr-api-types-ro

Conversation

@gnprice
Copy link
Copy Markdown
Member

@gnprice gnprice commented Aug 13, 2021

This largely covers the remaining types here, inspired by #4948, with the help of some Perl find-and-replace.

There isn't anything special about the API that means its objects and arrays should be read-only -- after all, the actual server itself can't possibly care. But we reuse a lot of these for Redux actions and for pieces of our Redux store, where we do want things to be read-only, so it's helpful to just consistently mark here too.

Done with the following command:

$ perl -i -0pe '
    s<type\ \w+\ =\ \K( \{\| $ .*? ^ \|\} );> (\$ReadOnly<$1>;)gsmx;
    s<type\ \w+\ =\ \K( \{   $ .*? ^   \} );> (\$ReadOnly<$1>;)gsmx
  ' src/api/*Types.js
Done with this command:

  $ perl -i -0pe '
      s<( \w+ ) \[\]> (\$ReadOnlyArray<$1>)gsmx
    ' src/api/*Types.js

followed by dropping one irrelevant match inside a comment,
and propagating the read-only-ness to one spot to fix type errors.
Found by grepping (imprecisely) for object types that might not
be read-only:

  $ rg -A1 '[^<]\{' src/api/*Types.js

and inspecting the results.
We switched this bit of state a while ago from object-as-map
to Immutable.Map.

Happened across this when grepping for non-read-only object types.
@chrisbobbe chrisbobbe merged commit d5ad619 into zulip:master Aug 13, 2021
@chrisbobbe
Copy link
Copy Markdown
Contributor

Thanks, LGTM! Merged.

@gnprice gnprice deleted the pr-api-types-ro branch August 13, 2021 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants