File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -215,6 +215,17 @@ function levelgraphJSONLD(db, jsonldOpts) {
215215 graphdb . jsonld . del = function ( obj , options , callback ) {
216216 var blanks = { } ;
217217
218+ if ( typeof obj === 'string' ) {
219+ try {
220+ obj = JSON . parse ( obj ) ;
221+ } catch ( e ) {
222+ // Handle case where we're trying to delete by passing an IRI
223+ if ( ! N3Util . isIRI ( obj ) ) {
224+ throw e
225+ }
226+ }
227+ }
228+
218229 if ( typeof options === 'function' ) {
219230 callback = options ;
220231 options = { } ;
Original file line number Diff line number Diff line change @@ -125,4 +125,20 @@ describe('jsonld.del', function() {
125125 } ) ;
126126 } ) ;
127127 } ) ;
128+
129+ it ( 'should del obj passed as stringified JSON' , function ( done ) {
130+ var jld = { "@context" : { "@vocab" : "https://schema.org/" } , "name" : "BigBlueHat" } ;
131+
132+ db . jsonld . put ( JSON . stringify ( jld ) , { preserve :true } , function ( ) {
133+ db . jsonld . del ( JSON . stringify ( jld ) , { preserve :true } , function ( err ) {
134+ expect ( err ) . to . not . exist ;
135+ db . get ( { } , function ( err , triples ) {
136+ // getting the full db
137+ expect ( triples ) . to . have . length ( 1 ) ;
138+ done ( ) ;
139+ } ) ;
140+ } ) ;
141+ } ) ;
142+ } ) ;
143+
128144} ) ;
You can’t perform that action at this time.
0 commit comments