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

WIP - make simple-schema fully Async #746

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

vparpoil
Copy link

@vparpoil vparpoil commented Jan 16, 2025

Motivations

Following Meteor 3 compatibility PR, a vote has been casted and the community voted for a full async compatibility

From a quick investigation, here are the functions that could benefit of being async :

  • Functions that would enable denormalization and will make .clean() async
    • autoValue
    • label - my feeling is that using async function here is redundant with autoValue
  • Functions that would enable custom validation and allow enhancing data integrity. Thet will much likely make .validate() async
    • custom
    • required and optional
    • min, max, minCount, maxCount, exclusiveMin, exclusiveMax
    • allowedValues
    • regEx
    • skipRegExCheckForEmptyStrings

What's included

This PR introduces async support for autoValue. Here's an example use case:

authorId: {
   type: String,
    regEx: SimpleSchema.RegEx.Id
},
authorName: {
    type: String, 
    autoValue: async function(){
         const author = await Author.findOneAsync(this.field("authorId").value);
         return author.name;
    }
}

This feature is particularly useful for denormalization scenarios, such as adding fields like createdByName to your data schema.

Changes

  • Updated tests to include async autoValue. All existing tests continue to pass.
  • Full linting of the package using meteor npm run lint:fix (as outlined in CONTRIBUTING.md).
    • Note: One remaining issue with linting static properties and class fields in SimpleSchema.js still needs resolution.

⚠️ Breaking Changes

  • .clean() is now Async and must be awaited
    • this change will require an update of dependent packages, such as collection2 to add await on clean() calls and benefit of async autoValue
  • validator() is now Async and must be awaited
    • this change is breaking ValidatedMethods declarations

What's next

  • Please share your thoughts on this PR. Are you in favor of moving forward?
  • While making all those functions async could improve validation capabilities and enhance DX, my personal opinion is that making validate() async is too much of a breaking change for now. I suggest focusing on autoValue and maybe label

Thank you for you input!

@vparpoil vparpoil marked this pull request as draft January 16, 2025 14:46
@jankapunkt
Copy link
Member

This is great 👍 I think this is great step forward. Let me check the next Days how it will behave with existing apps.

vparpoil added a commit to vparpoil/validated-method that referenced this pull request Jan 16, 2025
@vparpoil
Copy link
Author

Hi @jankapunkt ,
I have tested inside a project and it seems to be working just fine!
For your tests, you will want to use the forked and updated versions of collection2 and mdg validated-methods :

vparpoil added a commit to vparpoil/meteor-collection2 that referenced this pull request Jan 16, 2025
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