-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add runtime type checking #50
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
Draft
fhur
wants to merge
7
commits into
master
Choose a base branch
from
runtime-type-safety
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
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
File renamed without changes.
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 |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| { | ||
| "typescript.tsdk": "node_modules/typescript/lib", | ||
| "typescript.tsserver.experimental.enableProjectDiagnostics": true, | ||
| "editor.formatOnSave": true, | ||
| "editor.codeActionsOnSave": { | ||
| "source.organizeImports": "always" | ||
| }, | ||
| "editor.defaultFormatter": "esbenp.prettier-vscode", | ||
| "[typescript]": { | ||
| "editor.defaultFormatter": "esbenp.prettier-vscode" | ||
| }, | ||
| "[typescriptreact]": { | ||
| "editor.defaultFormatter": "esbenp.prettier-vscode" | ||
| }, | ||
| "[json]": { | ||
| "editor.defaultFormatter": "esbenp.prettier-vscode" | ||
| } | ||
| } | ||
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
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
33 changes: 33 additions & 0 deletions
33
packages/backend/src/execution/execution/runSampledValidation.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 |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { TSchema } from '@sinclair/typebox'; | ||
| import { Value, ValueError } from '@sinclair/typebox/value'; | ||
|
|
||
| export function runSampledValidation({ | ||
| schema, | ||
| sampleRate, | ||
| rows, | ||
| }: { | ||
| schema?: TSchema; | ||
| sampleRate?: number; | ||
| rows: unknown; | ||
| }) { | ||
| if (sampleRate === undefined || schema === undefined) { | ||
| return; | ||
| } | ||
|
|
||
| const shouldSample = Math.random() < sampleRate; | ||
| if (!shouldSample) { | ||
| return; | ||
| } | ||
| const error = Value.Errors(schema, rows).First(); | ||
| if (error) { | ||
| throw new Error(formatError(error)); | ||
| } | ||
| } | ||
|
|
||
| function formatError(error: ValueError) { | ||
| return [ | ||
| `Validation error at ${error.path}: ${error.message}`, | ||
| `Actual: ${error.value}`, | ||
| `Expected schema: ${error.schema}`, | ||
| ].join('\n'); | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { ExecResultNode, ExecResultTree } from '../types'; | ||
|
|
||
| /** | ||
| * Looks at the execution tree and determines if we should yield results to the client. | ||
| * | ||
| * The current implementation should only yield once - when all planning nodes have been | ||
| * executed. | ||
| */ | ||
| export function shouldYield(tree: ExecResultTree): boolean { | ||
| return shouldYieldNode(tree.root); | ||
| } | ||
|
|
||
| /** | ||
| * Recursively checks if we should yield for a given node. | ||
| * | ||
| * As a reminder, an `ExecResultNode` is by definition, the execution of the planned node | ||
| * (i.e. the node that was initially planned). | ||
| * | ||
| * An ExecResultNode might have planned children, but no executed children. This indicates that | ||
| * execution has not finished for the children. | ||
| */ | ||
| function shouldYieldNode(node: ExecResultNode): boolean { | ||
| const plannedChildren = node.planNode.children; | ||
| const executedChildren = node.children; | ||
|
|
||
| // If the number of executed children is less than the number of planned children, | ||
| // we should not yield yet | ||
| if (executedChildren.length < plannedChildren.length) { | ||
| return false; | ||
| } | ||
|
|
||
| // Recursively check all executed children | ||
| for (const child of executedChildren) { | ||
| if (!shouldYieldNode(child)) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| // If we've reached this point, all children (and their descendants) are fully executed | ||
| return true; | ||
| } |
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
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.
💡 Codebase verification
Action Required: Add Prettier to Recommended Extensions
The
.vscode/extensions.jsonfile is missing. To ensure consistent formatting across all developers, please create.vscode/extensions.jsonand addesbenp.prettier-vscodeto therecommendationslist.🔗 Analysis chain
LGTM: Consistent use of Prettier for formatting.
Setting Prettier as the default formatter for TypeScript, TypeScript React, and JSON files ensures a consistent code style across these file types. This aligns well with the automatic formatting settings.
To ensure these settings work as intended, please verify that the Prettier extension (esbenp.prettier-vscode) is installed in VS Code for all developers. You may want to add this extension to your recommended extensions list in the
.vscode/extensions.jsonfile if it's not already there.Run the following script to check if Prettier is listed in the recommended extensions:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 259