Skip to content

SB3 Schema/Validation #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 10 commits into from
Mar 22, 2018
Merged

Conversation

kchadha
Copy link
Contributor

@kchadha kchadha commented Mar 16, 2018

This PR is an improved (less complexity, less major code changes) version of #20 which is closed in favor of this PR.

Proposed Changes

  • Adding an sb3 schema (this is a first draft of the schema, which is still a WIP, feedback is welcome)
  • Modifying the validator to validate against the sb2 and sb3 schemas to determine if the given
    input is valid against either of them. Note breaking change: since the validator is now checking against two different schemas, the 'error' returned by the validate function is now an object which includes both sb2 and sb3 errors if the input failed to validate against both specifications.
  • A callback wrapper around the JSZip promise interface
  • Change to the apis of unpack function and main exported function: These will provide the validated result as 2 element array of (1) the validated input with any appended metadata (which was what was previously being returned by these functions) and (2) either the unpacked zip if one was originally provided or null if a json string or file was provided.
  • Unpack now also tries to convert things that are neither strings nor buffers into buffers (e.g. scratch-vm gives scratch-parser an array buffer).

Test Coverage

The existing tests have been modified to accommodate these changes as necessary. Additional tests to be added for sb3 validation and for testing the new promise functionality. Both of these have been manually tested through scratch-vm and scratch-gui.

Additional Notes

This PR is related to the following PRs, and should be merged before either of them. The changes in these other PRs depend on the changes proposed by this PR.
scratchfoundation/scratch-vm#979
scratchfoundation/scratch-gui#1621

kchadha added 5 commits March 15, 2018 18:00
…ratch 3.0 projects.

Added sb3 schema, renamed sb2 schema, and updated validate to check given input against both sb2 and
sb3 schemas. Validate appends a projectVersion to the given project with 2 or 3 if the given project
is valid against the corresponding schema. Validate now returns an object containing an error
message and both the sb2 and sb3 validation errors upon failure to validate against both schemas.

BREAKING CHANGE: Changes to validate API and what it returns (namely, error returned by validate is
no longer a string, but is now an object which contains an error message string as well as the sb2
errors and the sb3 errors). Users of this library function should expect to parse the given error to
figure out why validation failed.
…ise-based interface. Refactor m

Refactor unpack and main exported function to return optional zip, if originally provided, in
addition to the validated project.

BREAKING CHANGE: Change to main api to return originally provided zip (or null if string was
provided) along with validated project, in a 2-element array.
Fixed up existing test coverage to accommodate the recent breaking changes.
@kchadha
Copy link
Contributor Author

kchadha commented Mar 16, 2018

@colbygk Addressed your comment on #20 in this PR.

Field and input values can be strings or numbers. TopLevel property is not required of blocks. VM
version property should be more permissive and follow semantic release convention.
Copy link
Contributor

@thisandagain thisandagain left a comment

Choose a reason for hiding this comment

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

This looks great. I think my only suggestion would be to add a unit test for the new zip.js module that wraps JSZip, but the rest of the test coverage looks good. Hopefully we can simplify this a bit further when we move the analysis stuff into it's own module.

Copy link
Contributor

@cwillisf cwillisf left a comment

Choose a reason for hiding this comment

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

This all looks good, though I agree with the suggestion for a unit test for lib/zip.js. The comments I made are more about potential future work than this PR in particular.

},
"md5": {
"type": "string",
"pattern": "^[a-fA-F0-9]{32}.[a-zA-Z]+$"

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

validationError: 'Could not parse as a valid SB2 or SB3 project.',
sb2Errors: validateSb2.errors,
sb3Errors: validateSb3.errors
};

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

Copy link
Contributor

@rschamp rschamp left a comment

Choose a reason for hiding this comment

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

I don't think any of my comments should block merging, and are just feedback for things that we might want to adjust in the future.

index.js Outdated
};

// First unpack the input (need this outside of the async waterfall so that
// unoackedProject can be refered to again)

This comment was marked as abuse.

This comment was marked as abuse.

"rotationCenterY": {
"type": "number"
},
"skinId": {

This comment was marked as abuse.

"sampleCount": {
"type": "integer"
},
"soundID": {

This comment was marked as abuse.

}
}
},
"block": {

This comment was marked as abuse.

]
},

"targets": {

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

kchadha added 3 commits March 20, 2018 12:59
…dd descriptive error message to

Added unit tests for unzip and added a user-friendly error message for unzip being unable to perform
its duties of extracting a project.json from the given input (zip).
@kchadha
Copy link
Contributor Author

kchadha commented Mar 21, 2018

@rschamp, @cwillisf, @thisandagain,

I believe I have now made changes (or comments) that address your PR comments. I think this PR (or just those changes) needs a second glance before this PR is ready to go.

Copy link
Contributor

@rschamp rschamp left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@cwillisf cwillisf left a comment

Choose a reason for hiding this comment

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

😎

@kchadha kchadha merged commit ee506e8 into scratchfoundation:master Mar 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants