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

Detect schema version #104

Merged
merged 7 commits into from
Oct 6, 2023
Merged

Detect schema version #104

merged 7 commits into from
Oct 6, 2023

Conversation

mint-thompson
Copy link
Collaborator

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.

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*("(?:\\"|\\\\|[^"])*")/;
Copy link
Collaborator

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.

try {
const stats = await fileHandle.stat();
const lastStuff = await fileHandle.read({
position: Math.max(0, stats.size - 100),
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

@shaselton-usds shaselton-usds left a comment

Choose a reason for hiding this comment

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

Fantastic!

@shaselton-usds shaselton-usds merged commit ac7a636 into main Oct 6, 2023
12 checks passed
@shaselton-usds shaselton-usds deleted the detect-schema-version branch October 6, 2023 19:30
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.

2 participants