Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ajv with zod; simplified plugin API #1441

Merged
merged 103 commits into from
May 23, 2023
Merged

Replace ajv with zod; simplified plugin API #1441

merged 103 commits into from
May 23, 2023

Conversation

keller-mark
Copy link
Member

@keller-mark keller-mark commented Mar 11, 2023

Fixes #1430
Fixes #1289
Towards #1401
Closes #1100
Towards #1515
Fixes #1514

Changes in this PR:

  • Multiple passes of config validation/parsing
      1. in <Vitessce/> to support upgrading from previous config schema versions - but plugin-agnostic
      1. in <VitS/> against the latest config schema - but plugin-agnostic
      1. in <VitS/> against a plugin-specific schema which accounts for coordination type value schemas and file type options schemas
  • Validation of plugin coordination type value schemas and file type options schemas via Zod
    • These validations now happen by building a plugin-specific config schema
    • Coordination type plugins accept a Zod schema for their value.
    • File type plugins accept a Zod schema for their options.
    • @vitessce/schemas and vitessce re-export z from Zod
    • superRefine calls for schema upgrades to catch deprecated coordination types.
    • Perform validation for cellSets/obsSets JSON/CSV imports using Zod rather than Ajv
  • Plugins no longer registered via window (if this is needed it should be done in user-land) - instead they are passed as props to <Vitessce/> / <VitS/>
  • Introduction of TypeScript in @vitessce/plugins and @vitessce/schemas
    • I had hesitated to do this for a while but I think Vitessce is stable enough now that it will help to start using TypeScript where possible
  • Linting for JSX, TS, and TSX

Updated docs

Future PRs:

  • plugin data types to replace DATA_TYPE_COORDINATION_VALUE_USAGE
  • plugin coordination types define autoIndependent
  • "decentralize" COMPONENT_COORDINATION_TYPES
  • auto-generate JSON schemas using zod-to-json-schema and publish to NPM to enable validation in external tools (e.g., vitessce-Python/R)

Checklist

  • Ensure PR works with all demos on the dev.vitessce.io homepage
  • Open (draft) PR's into vitessce-python and vitessce-r if this is a release PR
  • Documentation added or updated

@keller-mark keller-mark mentioned this pull request May 10, 2023
3 tasks
@vitessce vitessce deleted a comment from github-actions bot May 10, 2023
export class PluginCoordinationType<T1 extends z.ZodTypeAny> {
name: string;

defaultValue: z.infer<T1>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be inferred from the schema itself? zod probably has a notion of default values, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - it does https://zod.dev/?id=default although I think for now I will just make an issue to investigate/address in a follow-up PR

sites/docs/docs/dev-plugins.mdx Outdated Show resolved Hide resolved
* Use .js

* Comments

* Revert webpack plugin

* Update cypress e2e tests

* Add/move dev-docs

* Update design-guidelines.md

* Fix meta-updater

* Revert config

* Update design-guidelines.md

* Update README.md

* Update design-guidelines.md

* Update design-guidelines.md

* Update design-guidelines.md

* Update rollup.config.js

* Revert unrelated change

* WIP: clean up lodash, mui, uuid imports

* More import fixes

* De-duplicate imports

* Dev-docs about js imports

* Use publint

* isEqual

* Fix tests

* Dev-docs

* Dev-docs linked from main README

* Demo

* Feedback
@keller-mark keller-mark merged commit 33c30b5 into main May 23, 2023
5 checks passed
@keller-mark keller-mark deleted the keller-mark/zod branch May 23, 2023 17:52
@keller-mark keller-mark mentioned this pull request Jun 6, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants