Skip to content

WIP: Framing #365

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 20 commits into from
Feb 28, 2020
Merged

WIP: Framing #365

merged 20 commits into from
Feb 28, 2020

Conversation

gkellogg
Copy link
Collaborator

@gkellogg gkellogg commented Feb 20, 2020

  • Remove new-embed tests, which are redundant and wrong.
  • Changed framing defaults
    • embed to "@once" and warn on "@first" or "@last".
    • pruneBlankNodeIdentifiers based on processingMode.
    • omitGraph based on processingMode.
  • Top level @graph omitted if omitGraph is true.
  • Check for invalid values of @embed.
  • Changes in object embedding.
  • Better support for graph framing.
  • replaced removePreserve with cleanupPreserve and cleanupNulls
  • Support default values for @type when framing.
  • Better frame validation.

@gkellogg gkellogg marked this pull request as ready for review February 22, 2020 01:25
@gkellogg
Copy link
Collaborator Author

This gets much of framing complete. More to do, but I may have a gap in working on it, so this can be reviewed and hopefully merged). This leaves nine failing tests.

Some tests are failing with Node6, which perhaps someone with more experience in the differences can see what might be going on.

@davidlehn davidlehn added this to the JSON-LD 1.1 milestone Feb 23, 2020
@gkellogg
Copy link
Collaborator Author

gkellogg commented Feb 23, 2020

It looks like the Node 6 failure is due to Object.entries not being defined. There is a suggestion for a PolyFill on the MDN entry for Object.entries.

if (!Object.entries) {
  Object.entries = function( obj ){
    var ownProps = Object.keys( obj ),
        i = ownProps.length,
        resArray = new Array(i); // preallocate the Array
    while (i--)
      resArray[i] = [ownProps[i], obj[ownProps[i]]];
    
    return resArray;
  };
}

Where would be the best place to apply this?

@davidlehn
Copy link
Member

Short answer is to hack it to work for now. core-js for Object.entries, and a shim for Object.fromEntries. I'll try adding it. Was trying to avoid this nonsense in jsonld.js 2.x. Once 1.1 support is mostly or all done I think we'll get radical with changes for a 3.x release. That'll include updating to core-js 3, which has Object.fromEntries, and just dropping node6 support and see if anyone notices.

Copy link
Member

@dlongley dlongley left a comment

Choose a reason for hiding this comment

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

Thanks @gkellogg! This is looking good. I left some comments that are almost all (all?) related to style or ES6/7 stuff. Hopefully they can be batched together. @davidlehn -- we should look into getting linting turned on/fixed for this repo so devs don't have to deal with these nits, do you know what needs to be done there?

Regarding node 6 support ... we should drop it, node 6 is EOL. It's fine to wait on that until another PR (I noticed a FIXME about it in here).

return false;
}
matchThis = true;
} else if(types.isObject(thisFrame)) { // XXX only framing keywords
Copy link
Member

Choose a reason for hiding this comment

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

Does this "XXX" comment need to be addressed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was in my code, and it could relate to some of the yet-to-be fixed issues.

@davidlehn
Copy link
Member

@dlongley Re linting, we do have eslint config here, and a "lint" command, but our rules didn't check for 'brace-style'. Added a PR to consider for that:
digitalbazaar/eslint-config-digitalbazaar#31

lib/frame.js Outdated
Object.keys(state.graphMap[id]).sort(), [subframe], output, '@graph');
state.graph = state.graphStack.pop;
state.graphStack.pop;
Copy link
Member

@davidlehn davidlehn Feb 24, 2020

Choose a reason for hiding this comment

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

Should this be calling pop? Should it have been calling it before? Should there be a test that detects this one way or the other?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We pushed on to the stack before recursing, so need to pop it back off when done. We don't need to save that, since state.graph was set just for the call.

Copy link
Member

Choose a reason for hiding this comment

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

Before it was setting state.graph to the pop function. Now it's just doing nothing. I assume this should be pop(), but it doesn't seem to matter either way in the test suite.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, you're right, should be pop() (Ruby-isms :) ). It doesn't matter for the tests, but it might in production.

I'll test before committing an update

Copy link
Member

Choose a reason for hiding this comment

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

Fixing and filing an issue about it.

gkellogg and others added 14 commits February 27, 2020 22:10
- Changed framing defaults
  - `embed` to "@once" and warn on "@FIRST" or "@last".
  - `pruneBlankNodeIdentifiers` based on processingMode.
  - `omitGraph` based on processingMode.
- Top level `@graph` omitted if `omitGraph` is `true`.
- Changes in object embedding.
- Better support for graph framing.
Replaced removePreserve with cleanupPreserve and cleanupNulls.
Co-Authored-By: Dave Longley <[email protected]>
Co-Authored-By: Dave Longley <[email protected]>
@davidlehn davidlehn merged commit 7cf2f71 into master Feb 28, 2020
@davidlehn davidlehn deleted the framing branch February 28, 2020 03:19
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.

3 participants