-
Notifications
You must be signed in to change notification settings - Fork 14
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
Detect schema version #104
Conversation
Schema version is now an optional argument rather than a required argument. If schema version is not provided, look for a version property in the data file. If found, try to use it as if it were the argument value. If not found, log an error and exit. If schema version is provided, still look for a version property in the data file. If it does not match the provided version, log a warning. The provided version is always used when available.
In cases where the version is the last property in the file, a backwards search can get the version quickly. Set a three-second time limit for the searches. If the time limit is reached, consider the version to be unknown.
}); | ||
if (lastStuff.bytesRead > 0) { | ||
const lastText = lastStuff.buffer.toString('utf-8'); | ||
const versionRegex = /"version"\s*:\s*("(?:\\"|\\\\|[^"])*")/; |
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.
verified this on an online regex tester.
src/SchemaManager.ts
Outdated
try { | ||
const stats = await fileHandle.stat(); | ||
const lastStuff = await fileHandle.read({ | ||
position: Math.max(0, stats.size - 100), |
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.
Is this looking at the last 100 characters? Though a bit arbitrary, I'd be fine 10x that as a "just in case". It shouldn't impact the speed.
Potential edge case, what if the file is smaller than the amount of characters being checked?
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.
If the file is shorter than the specified length, read
will go until the end of the file. It doesn't cause any errors to occur.
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.
Fantastic!
Addresses #92.
Schema version is now an optional argument rather than a required argument. If schema version is not provided, look for a version property in the data file. If found, try to use it as if it were the argument value. If not found, log an error and exit. If schema version is provided, still look for a version property in the data file. If it does not match the provided version, log a warning. The provided version is always used when available.
This is a significant change to the usage of the command-line interface. When this feature is released, be sure to make that fact very clear in the release notes.