Skip to content

feat: add new schemas package using zod, bring acc validation package… #801

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

Conversation

FedericoAmura
Copy link
Contributor

@FedericoAmura FedericoAmura commented Feb 19, 2025

Description

This PR replaces #660 which never got reviewed due to its size. It adds a new package, @lit-protocol/schemas which contains zod schemas we can use for input/output validation and as a connection between our constants and types

The packages dependency graph is as follows:
Screenshot from 2025-02-20 14-25-38

  • @lit-procotol/constants as the most base package and containing our constants values defined as const. Optionally, they can have types to help unify multiple values but those are not needed to be exposed
  • @lit-protocol/schemas as a child of constants. Its purpose is to define zod schemas, based on constants if needed, to provide complex runtime validations. This package is not intended for public use as it is internal to this SDK
  • @lit-protocol/types as a child of schemas. Will derive types from the schemas it needs to derive complex typescript compile time validations
  • Rest of packages will most likely depend from the three packages as they all contain useful resources

In this PR there is also a migration of https://github.com/LIT-Protocol/accs-schemas into @lit-protocol/access-control-conditions-schemas new package. Original package uses ajv to validate ACCs schemas, that was later imported in the SDK, now with zod in the SDK we can unify both and expose them into a public. This brings the benefit of having to update only one source of truth when adding support for a network in ACCs and a slight bundle reduction

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • CI still passing
  • Type system is still consistent with schema derived types
  • Unit tests over some schemas
  • ACCs validator and its tests migrated to new ACCs schemas pkg

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

… to also use zod and be integrated into the sdk instead of an external package using ajv
@FedericoAmura FedericoAmura marked this pull request as ready for review February 20, 2025 14:56
Copy link
Collaborator

@Ansonhkg Ansonhkg left a comment

Choose a reason for hiding this comment

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

LGTM! - a sentence or two guide on how do we add new chain support would be great!
packages/access-control-conditions-schemas/src/lib/common.ts

@@ -20,7 +20,6 @@
"@cypress/code-coverage": "^3.10.0",
"@cypress/react": "^6.2.0",
"@cypress/webpack-dev-server": "^2.3.0",
"@lit-protocol/accs-schemas": "0.0.7",
Copy link
Collaborator

Choose a reason for hiding this comment

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

NICE!

…o derive constants, types and params where applicable. This makes any lit supported chain update single source of truth
@Ansonhkg Ansonhkg merged commit 855a840 into feat/naga-fix-bls-wasm-cleanup Feb 25, 2025
3 of 4 checks passed
@Ansonhkg Ansonhkg deleted the feature/lit-3796-js-sdk-add-minimal-zod branch February 25, 2025 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants