@@ -62,8 +62,10 @@ const {
62
62
} = require ( './graphTypes' ) ;
63
63
64
64
const {
65
+ expandIri : _expandIri ,
65
66
getInitialContext : _getInitialContext ,
66
- process : _processContext
67
+ process : _processContext ,
68
+ processingMode : _processingMode
67
69
} = require ( './context' ) ;
68
70
69
71
const {
@@ -223,6 +225,12 @@ jsonld.compact = async function(input, ctx, options) {
223
225
ctx = ctx [ 0 ] ;
224
226
}
225
227
228
+ if ( options . framing ) {
229
+ // remove @preserve from results
230
+ options . link = { } ;
231
+ compacted = _removePreserve ( activeCtx , compacted , options ) ;
232
+ }
233
+
226
234
// add context and/or @graph
227
235
if ( _isArray ( compacted ) ) {
228
236
// use '@graph' keyword
@@ -244,16 +252,6 @@ jsonld.compact = async function(input, ctx, options) {
244
252
}
245
253
}
246
254
247
- if ( options . framing ) {
248
- // get graph alias
249
- const graph = _compactIri ( {
250
- activeCtx, iri : '@graph' , relativeTo : { vocab : true }
251
- } ) ;
252
- // remove @preserve from results
253
- options . link = { } ;
254
- compacted [ graph ] = _removePreserve ( activeCtx , compacted [ graph ] , options ) ;
255
- }
256
-
257
255
return compacted ;
258
256
} ;
259
257
@@ -435,11 +433,10 @@ jsonld.frame = async function(input, frame, options) {
435
433
// set default options
436
434
options = _setDefaults ( options , {
437
435
base : _isString ( input ) ? input : '' ,
438
- embed : '@last ' ,
436
+ embed : '@once ' ,
439
437
explicit : false ,
440
- requireAll : true ,
438
+ requireAll : false ,
441
439
omitDefault : false ,
442
- pruneBlankNodeIdentifiers : true ,
443
440
bnodesToClear : [ ] ,
444
441
contextResolver : new ContextResolver (
445
442
{ sharedCache : _resolvedContextCache } )
@@ -467,6 +464,24 @@ jsonld.frame = async function(input, frame, options) {
467
464
468
465
const frameContext = frame ? frame [ '@context' ] || { } : { } ;
469
466
467
+ // process context
468
+ const activeCtx = await jsonld . processContext (
469
+ _getInitialContext ( options ) , frameContext , options ) ;
470
+
471
+ // mode specific defaults
472
+ if ( ! options . hasOwnProperty ( 'omitGraph' ) ) {
473
+ options . omitGraph = _processingMode ( activeCtx , 1.1 ) ;
474
+ }
475
+ if ( ! options . hasOwnProperty ( 'pruneBlankNodeIdentifiers' ) ) {
476
+ options . pruneBlankNodeIdentifiers = _processingMode ( activeCtx , 1.1 ) ;
477
+ }
478
+ if ( ( options . embed === '@first' || options . embed === '@last' ) &&
479
+ _processingMode ( activeCtx , 1.1 ) )
480
+ {
481
+ console . warn ( `WARNING: ${ options . embed } is not a valid value ` +
482
+ `of @embed in 1.1 mode.` ) ;
483
+ }
484
+
470
485
// expand input
471
486
const expanded = await jsonld . expand ( input , options ) ;
472
487
@@ -478,14 +493,13 @@ jsonld.frame = async function(input, frame, options) {
478
493
479
494
// if the unexpanded frame includes a key expanding to @graph , frame the
480
495
// default graph, otherwise, the merged graph
481
- // FIXME should look for aliases of @graph
482
- opts . merged = ! ( '@graph' in frame ) ;
496
+ const frameKeys = Object . keys ( frame )
497
+ . map ( key => _expandIri ( activeCtx , key , { vocab : true } ) ) ;
498
+ opts . merged = ! frameKeys . includes ( '@graph' ) ;
483
499
// do framing
484
500
const framed = _frameMergedOrDefault ( expanded , expandedFrame , opts ) ;
485
501
486
- // compact result (force @graph option to true, skip expansion,
487
- // check for linked embeds)
488
- opts . graph = true ;
502
+ opts . graph = ! options . omitGraph ;
489
503
opts . skipExpansion = true ;
490
504
opts . link = { } ;
491
505
opts . framing = true ;
0 commit comments