-
Notifications
You must be signed in to change notification settings - Fork 45
Feature: Response sampling #21
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2833d0c
feat(core): implement pagination of executing function
oscar60310 45b5d97
refactor(build): change schema parser middlewares to classes instead …
oscar60310 4eec83f
feat(core): load compiled data right after compiling
oscar60310 caeb4eb
feat(build): add response sampler middleware
oscar60310 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| export * from './schema-reader'; | ||
| export * from './schemaParser'; | ||
| export { RawAPISchema, SchemaParserMiddleware } from './middleware'; | ||
| export * from './middleware'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
packages/build/src/lib/schema-parser/middleware/fallbackErrors.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| import { SchemaParserMiddleware } from './middleware'; | ||
| import { RawAPISchema, SchemaParserMiddleware } from './middleware'; | ||
|
|
||
| export const fallbackErrors = | ||
| (): SchemaParserMiddleware => async (schemas, next) => { | ||
| export class FallbackErrors extends SchemaParserMiddleware { | ||
| public async handle(schemas: RawAPISchema, next: () => Promise<void>) { | ||
| if (schemas.errors) return next(); | ||
| schemas.errors = []; | ||
| return next(); | ||
| }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
packages/build/src/lib/schema-parser/middleware/generateTemplateSource.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,11 @@ | ||
| import { SchemaParserMiddleware } from './middleware'; | ||
| import { RawAPISchema, SchemaParserMiddleware } from './middleware'; | ||
|
|
||
| // Use schema sourceName which was generated by schema reader as templateSource when it wan't defined. | ||
| // It usually be the path file of schema file. | ||
| export const generateTemplateSource = | ||
| (): SchemaParserMiddleware => async (schemas, next) => { | ||
| export class GenerateTemplateSource extends SchemaParserMiddleware { | ||
| public async handle(schemas: RawAPISchema, next: () => Promise<void>) { | ||
| if (schemas.templateSource) return next(); | ||
| schemas.templateSource = schemas.sourceName; | ||
| return next(); | ||
| }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,36 @@ | ||
| import { ClassType } from '@vulcan-sql/core'; | ||
| import { GenerateUrl } from './generateUrl'; | ||
| import { CheckValidator } from './checkValidator'; | ||
| import { TransformValidator } from './transformValidator'; | ||
| import { GenerateTemplateSource } from './generateTemplateSource'; | ||
| import { CheckParameter } from './checkParameter'; | ||
| import { AddMissingErrors } from './addMissingErrors'; | ||
| import { FallbackErrors } from './fallbackErrors'; | ||
| import { NormalizeFieldIn } from './normalizeFieldIn'; | ||
| import { GenerateDataType } from './generateDataType'; | ||
| import { NormalizeDataType } from './normalizeDataType'; | ||
| import { GeneratePathParameters } from './generatePathParameters'; | ||
| import { AddRequiredValidatorForPath } from './addRequiredValidatorForPath'; | ||
| import { SetConstraints } from './setConstraints'; | ||
| import { SchemaParserMiddleware } from './middleware'; | ||
| import { ResponseSampler } from './responseSampler'; | ||
|
|
||
| export * from './middleware'; | ||
| export * from './generateUrl'; | ||
| export * from './checkValidator'; | ||
| export * from './transformValidator'; | ||
| export * from './generateTemplateSource'; | ||
| export * from './checkParameter'; | ||
| export * from './addMissingErrors'; | ||
| export * from './fallbackErrors'; | ||
| export * from './normalizeFieldIn'; | ||
| export * from './generateDataType'; | ||
| export * from './normalizeDataType'; | ||
| export * from './generatePathParameters'; | ||
| export * from './addRequiredValidatorForPath'; | ||
| export * from './setConstraints'; | ||
|
|
||
| // The order of middleware here indicates the order of their execution, the first one will be executed first, and so on. | ||
| export const SchemaParserMiddlewares: ClassType<SchemaParserMiddleware>[] = [ | ||
| GenerateUrl, | ||
| CheckValidator, | ||
| TransformValidator, | ||
| GenerateTemplateSource, | ||
| CheckParameter, | ||
| AddMissingErrors, | ||
| FallbackErrors, | ||
| NormalizeFieldIn, | ||
| GenerateDataType, | ||
| NormalizeDataType, | ||
| GeneratePathParameters, | ||
| AddRequiredValidatorForPath, | ||
| SetConstraints, | ||
| ResponseSampler, | ||
| ]; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
packages/build/src/lib/schema-parser/middleware/normalizeFieldIn.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,14 @@ | ||
| import { FieldInType } from '@vulcan-sql/core'; | ||
| import { SchemaParserMiddleware } from './middleware'; | ||
| import { RawAPISchema, SchemaParserMiddleware } from './middleware'; | ||
|
|
||
| // FieldIn: query => FieldIn FieldInType.QUERY | ||
| export const normalizeFieldIn = | ||
| (): SchemaParserMiddleware => async (schemas, next) => { | ||
| export class NormalizeFieldIn extends SchemaParserMiddleware { | ||
| public async handle(schemas: RawAPISchema, next: () => Promise<void>) { | ||
| (schemas.request || []).forEach((request) => { | ||
| if (request.fieldIn) { | ||
| request.fieldIn = request.fieldIn.toUpperCase() as FieldInType; | ||
| } | ||
| }); | ||
| return next(); | ||
| }; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could add a comment to let other members know the array order will become the compose order for middleware executing, or if other members modified the order and some middleware have the relationship of reading/writing data, it will have some influence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I've added.