-
Notifications
You must be signed in to change notification settings - Fork 5
Refactor schema inference #13
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
| }, | ||
| "dependencies": { | ||
| "fast-glob": "^3.3.2" | ||
| "fast-glob": "^3.3.2", |
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.
Moved these dependencies that are needed by inferSchemaFromExamplePayload
| if (unknownPaths.some(([pattern, paths]) => pattern.test(metadata.name) && paths.includes(fullPath))) { | ||
| // we know this path is always null, so don't error | ||
| } else { | ||
| errors.push({ |
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.
This file is largely unchanged, except for this part and what is being returned. Instead of logging the errors and warnings here, we collect them and return it along with the schema.
| await fs.writeFile(metadataFile, JSON.stringify(webhook, null, 2), "utf-8"); | ||
|
|
||
| const schema = inferSchemaFromExamplePayload(webhook.response, webhook, version); | ||
| const { schema, warnings: warningCount, errors: errorMessages } = inferSchemaFromExamplePayload(webhook.response, webhook); |
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.
This file is mostly the same except with the removed code moving to infer-schema. This is the main change, instead of the console output happening inside inferSchemaFromExamplePayload it is moved here.
jcao49
left a comment
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.
🙇♀️ thanks for this!!
This PR refactors the schema inference so it isn't coupled to
scraper.tsand can be imported and used in other codebases.src/infer-schema.tsinferSchemaFromExamplePayloadand put into the scraper.inferSchemaFromExamplePayloadand the function is now exported.package.jsonwas updated to add dependencies thatinferSchemaFromExamplePayloadneeds.