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

Feature: Syntax sugars for parameter validators #108

Merged
merged 12 commits into from
Oct 12, 2022

Conversation

oscar60310
Copy link
Contributor

@oscar60310 oscar60310 commented Oct 4, 2022

Description

I made validation filters for every validator, named with prefix is_, e.g. integer validator has the is_integer filter. Those validators can be used with any variables:

  • With dynamic parameters

    SELECT * FROM "artists"
    WHERE ConstituentID = {{ context.params.id | is_required | is_integer }}
  • With predefined queries' result

    {% req artist %}
    SELECT * FROM "artists"
    WHERE DisplayName = {{ context.params.name }} LIMIT 1
    {% endreq %}
    
    SELECT * FROM "artworks"
    WHERE ConstituentID = {{ artist.value()[0].ConstituentID | is_required | is_integer }}

To add arguments:

SELECT * FROM users
WHERE age = {{ context.params.age | integer(min=0, max=100) }}

Please check the document here.

I've also added a new validator enum and implemented getConstraints function for all validators.

Issue ticket number

closes #99

Additional Context

  • I used the simplest way to name validation filters: is_xxxx, we can improve it in the future.

We injected nunjucks environments and their extensions together into compiler,
but they can be injected after they have been initialized properly.

- Compose compiler environments
- Fix circular dependencies issues
@vercel
Copy link

vercel bot commented Oct 4, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
vulcan-sql-document ✅ Ready (Inspect) Visit Preview Oct 7, 2022 at 7:15AM (UTC)

@codecov-commenter
Copy link

codecov-commenter commented Oct 6, 2022

Codecov Report

Base: 92.57% // Head: 92.68% // Increases project coverage by +0.10% 🎉

Coverage data is based on head (c3fb05c) compared to base (0a04d0f).
Patch coverage: 95.68% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #108      +/-   ##
===========================================
+ Coverage    92.57%   92.68%   +0.10%     
===========================================
  Files          259      265       +6     
  Lines         3799     3964     +165     
  Branches       482      517      +35     
===========================================
+ Hits          3517     3674     +157     
- Misses         185      193       +8     
  Partials        97       97              
Flag Coverage Δ
build 94.98% <100.00%> (+0.07%) ⬆️
core 93.15% <95.49%> (+0.15%) ⬆️
extension-dbt 97.43% <ø> (ø)
extension-debug-tools 98.11% <ø> (ø)
extension-driver-duckdb 100.00% <ø> (ø)
extension-driver-pg 94.87% <ø> (ø)
integration-testing 96.15% <ø> (ø)
serve 90.29% <ø> (ø)
test-utility ∅ <ø> (∅)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
.../lib/template-engine/extension-utils/interfaces.ts 100.00% <ø> (ø)
packages/core/src/lib/utils/errors.ts 76.92% <ø> (+7.69%) ⬆️
...kages/core/src/models/extensions/templateEngine.ts 100.00% <ø> (ø)
...ib/validators/built-in-validators/enumValidator.ts 80.00% <80.00%> (ø)
.../template-engine/compiler-environment/buildTime.ts 91.17% <91.17%> (ø)
packages/core/src/lib/validators/constraints.ts 96.66% <95.83%> (-0.96%) ⬇️
...ib/template-engine/compiler-environment/runtime.ts 96.66% <96.66%> (ø)
...built-in-extensions/validator/parametersChecker.ts 97.64% <97.46%> (-2.36%) ⬇️
...generator/spec-generator/oas3/oas3SpecGenerator.ts 97.46% <100.00%> (+0.13%) ⬆️
...d/src/lib/schema-parser/middleware/addParameter.ts 100.00% <100.00%> (ø)
... and 18 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@oscar60310 oscar60310 changed the title [WIP] Feature: Syntax sugars for parameter validators Feature: Syntax sugars for parameter validators Oct 7, 2022
@oscar60310 oscar60310 marked this pull request as ready for review October 7, 2022 07:32
Copy link
Contributor

@kokokuo kokokuo left a comment

Choose a reason for hiding this comment

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

Beside one question, other is LGTM 👍 👍


if (existedParam) {
if (!existedParam.validators) existedParam.validators = [];
existedParam.validators.push(...(parameter.validators || []));
Copy link
Contributor

Choose a reason for hiding this comment

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

If there are the same name validators in metadata and schema requests, will we exclude one of them?

Because we may face some cases which the args are different in schema request and SQL syntax validation filter:

  • schema request has integer validator with args min=10, and max=20
  • metadata exists in the validator with args min=5, and max=90 which parsed from SQL

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pushed all validators to the list because I didn't know how to compose all of the validators, e.g.
string(format="\d+")
string(format="[1-5]+")

So I prefer to execute all of these validators.

P.S. Our constraints have composed logic so that we won't duplicate them.

Copy link
Contributor

@kokokuo kokokuo Oct 12, 2022

Choose a reason for hiding this comment

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

Thanks so much

@kokokuo kokokuo merged commit 99b3aa3 into develop Oct 12, 2022
@kokokuo kokokuo deleted the feature/validator-syntax-sugar branch October 12, 2022 04:25
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.

Syntax sugars for parameter validators
3 participants